Skip to content

Commit 22e9bc2

Browse files
committed
reduce guava code usage
1 parent 1a3a940 commit 22e9bc2

File tree

6 files changed

+49
-30
lines changed

6 files changed

+49
-30
lines changed

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/edit/DocumentEditAndUndoTest.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
import org.eclipse.ui.IEditorPart;
3737
import org.junit.Test;
3838

39-
import com.google.common.collect.Iterators;
40-
4139
public class DocumentEditAndUndoTest extends AbstractTestWithProject {
4240

4341
@Test
@@ -65,10 +63,13 @@ public void testDocumentEditAndUndo() throws Exception {
6563

6664
// Wait for Linked Editing to be established
6765
waitForAndAssertCondition("Linked Editing not established", 3_000, () -> {
68-
return Iterators
69-
.tryFind(((ISourceViewer) viewer).getAnnotationModel().getAnnotationIterator(),
70-
anno -> anno.getType().startsWith("org.eclipse.ui.internal.workbench.texteditor.link"))
71-
.isPresent();
66+
final var it = ((ISourceViewer) viewer).getAnnotationModel().getAnnotationIterator();
67+
while (it.hasNext()) {
68+
if (it.next().getType().startsWith("org.eclipse.ui.internal.workbench.texteditor.link")) {
69+
return true;
70+
}
71+
}
72+
return false;
7273
});
7374

7475
// perform text editing operation

org.eclipse.lsp4e.test/src/org/eclipse/lsp4e/test/utils/TestUtils.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.nio.file.Files;
2121
import java.nio.file.Path;
2222
import java.util.Arrays;
23+
import java.util.Comparator;
2324
import java.util.HashSet;
2425
import java.util.List;
2526
import java.util.Set;
@@ -55,9 +56,6 @@
5556
import org.eclipse.ui.part.FileEditorInput;
5657
import org.eclipse.ui.tests.harness.util.DisplayHelper;
5758

58-
import com.google.common.io.MoreFiles;
59-
import com.google.common.io.RecursiveDeleteOption;
60-
6159
public class TestUtils {
6260

6361
@FunctionalInterface
@@ -215,7 +213,11 @@ public static void delete(IProject... projects) throws CoreException {
215213

216214
public static void delete(Path path) throws IOException {
217215
if (path != null && Files.exists(path)) {
218-
MoreFiles.deleteRecursively(path, RecursiveDeleteOption.ALLOW_INSECURE);
216+
try (final var files = Files.walk(path)) {
217+
files.sorted(Comparator.reverseOrder()) //
218+
.map(Path::toFile) //
219+
.forEach(File::delete);
220+
}
219221
}
220222
}
221223

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LSPEclipseUtils.java

+9-3
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,6 @@
164164
import org.eclipse.ui.texteditor.IDocumentProvider;
165165
import org.eclipse.ui.texteditor.ITextEditor;
166166

167-
import com.google.common.primitives.Chars;
168-
169167
/**
170168
* Some utility methods to convert between Eclipse and LS-API types
171169
*/
@@ -231,6 +229,14 @@ public static boolean isOffsetInRange(int offset, Range range, IDocument documen
231229
}
232230
}
233231

232+
private static boolean containsChar(final char[] searchIn, final char searchFor) {
233+
for (final char ch : searchIn) {
234+
if (ch == searchFor)
235+
return true;
236+
}
237+
return false;
238+
}
239+
234240
public static CompletionParams toCompletionParams(URI fileUri, int offset, IDocument document, char[] completionTriggerChars)
235241
throws BadLocationException {
236242
Position start = toPosition(offset, document);
@@ -239,7 +245,7 @@ public static CompletionParams toCompletionParams(URI fileUri, int offset, IDocu
239245
try {
240246
int positionCharacterOffset = offset > 0 ? offset-1 : offset;
241247
String positionCharacter = document.get(positionCharacterOffset, 1);
242-
if (Chars.contains(completionTriggerChars, positionCharacter.charAt(0))) {
248+
if (containsChar(completionTriggerChars, positionCharacter.charAt(0))) {
243249
param.setContext(new CompletionContext(CompletionTriggerKind.TriggerCharacter, positionCharacter));
244250
} else {
245251
// According to LSP 3.17 specification: the triggerCharacter in CompletionContext is undefined if

org.eclipse.lsp4e/src/org/eclipse/lsp4e/LanguageServerWrapper.java

+24-10
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@
3535
import java.util.concurrent.ExecutorService;
3636
import java.util.concurrent.Executors;
3737
import java.util.concurrent.Future;
38+
import java.util.concurrent.ThreadFactory;
3839
import java.util.concurrent.TimeUnit;
3940
import java.util.concurrent.TimeoutException;
4041
import java.util.concurrent.atomic.AtomicBoolean;
42+
import java.util.concurrent.atomic.AtomicLong;
4143
import java.util.concurrent.atomic.AtomicReference;
4244
import java.util.function.Consumer;
4345
import java.util.function.Function;
@@ -109,8 +111,6 @@
109111
import org.eclipse.osgi.util.NLS;
110112
import org.eclipse.swt.widgets.Display;
111113

112-
import com.google.common.base.Functions;
113-
import com.google.common.util.concurrent.ThreadFactoryBuilder;
114114
import com.google.gson.Gson;
115115
import com.google.gson.JsonObject;
116116

@@ -194,17 +194,31 @@ private LanguageServerWrapper(@Nullable IProject project, @NonNull LanguageServe
194194
this.initialPath = initialPath;
195195
this.serverDefinition = serverDefinition;
196196
this.connectedDocuments = new HashMap<>();
197-
String projectName = (project != null && project.getName() != null && !serverDefinition.isSingleton) ? ("@" + project.getName()) : ""; //$NON-NLS-1$//$NON-NLS-2$
198-
String dispatcherThreadNameFormat = "LS-" + serverDefinition.id + projectName + "#dispatcher"; //$NON-NLS-1$ //$NON-NLS-2$
199-
this.dispatcher = Executors
200-
.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat(dispatcherThreadNameFormat).build());
197+
final String projectName = (project != null && project.getName() != null && !serverDefinition.isSingleton) ? ("@" + project.getName()) : ""; //$NON-NLS-1$//$NON-NLS-2$
198+
final String dispatcherThreadNameFormat = "LS-" + serverDefinition.id + projectName + "#dispatcher"; //$NON-NLS-1$ //$NON-NLS-2$
199+
this.dispatcher = Executors.newSingleThreadExecutor(new ThreadFactory() {
200+
@Override
201+
public Thread newThread(final Runnable r) {
202+
final Thread thread = Executors.defaultThreadFactory().newThread(r);
203+
thread.setName(dispatcherThreadNameFormat);
204+
return thread;
205+
}
206+
});
201207

202208
// Executor service passed through to the LSP4j layer when we attempt to start the LS. It will be used
203209
// to create a listener that sits on the input stream and processes inbound messages (responses, or server-initiated
204210
// requests).
205-
String listenerThreadNameFormat = "LS-" + serverDefinition.id + projectName + "#listener-%d"; //$NON-NLS-1$ //$NON-NLS-2$
206-
this.listener = Executors
207-
.newCachedThreadPool(new ThreadFactoryBuilder().setNameFormat(listenerThreadNameFormat).build());
211+
final String listenerThreadNamePrefix = "LS-" + serverDefinition.id + projectName + "#listener-"; //$NON-NLS-1$ //$NON-NLS-2$
212+
this.listener = Executors.newSingleThreadExecutor(new ThreadFactory() {
213+
final ThreadFactory threadFactory = Executors.defaultThreadFactory();
214+
final AtomicLong threadCount = new AtomicLong();
215+
@Override
216+
public Thread newThread(final Runnable r) {
217+
final Thread thread = threadFactory.newThread(r);
218+
thread.setName(listenerThreadNamePrefix + threadCount.incrementAndGet());
219+
return thread;
220+
}
221+
});
208222
}
209223

210224
void stopDispatcher() {
@@ -707,7 +721,7 @@ private boolean supportsWorkspaceFolderCapability() {
707721
return;
708722
}
709723
TextDocumentSyncKind syncKind = initializeFuture == null ? null
710-
: serverCapabilities.getTextDocumentSync().map(Functions.identity(), TextDocumentSyncOptions::getChange);
724+
: serverCapabilities.getTextDocumentSync().map(left -> left, TextDocumentSyncOptions::getChange);
711725
final var listener = new DocumentContentSynchronizer(this, languageServer, theDocument, syncKind);
712726
theDocument.addPrenotifiedDocumentListener(listener);
713727
LanguageServerWrapper.this.connectedDocuments.put(uri, listener);

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/completion/LSContentAssistProcessor.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@
6262
import org.eclipse.lsp4j.jsonrpc.messages.Either;
6363
import org.eclipse.ui.texteditor.ITextEditor;
6464

65-
import com.google.common.base.Strings;
66-
6765
public class LSContentAssistProcessor implements IContentAssistProcessor {
6866

6967
private static final long TRIGGERS_TIMEOUT = 50;
@@ -350,7 +348,7 @@ private static char[] mergeTriggers(char[] initialArray, Collection<String> addi
350348
for (char c : initialArray) {
351349
triggers.add(c);
352350
}
353-
additionalTriggers.stream().filter(s -> !Strings.isNullOrEmpty(s))
351+
additionalTriggers.stream().filter(s -> s != null && !s.isEmpty())
354352
.map(triggerChar -> triggerChar.charAt(0)).forEach(triggers::add);
355353
char[] res = new char[triggers.size()];
356354
int i = 0;

org.eclipse.lsp4e/src/org/eclipse/lsp4e/operations/hover/FocusableBrowserInformationControl.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@
3939
import org.eclipse.ui.editors.text.EditorsUI;
4040
import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
4141

42-
import com.google.common.base.Strings;
43-
4442
@SuppressWarnings("restriction")
4543
public class FocusableBrowserInformationControl extends BrowserInformationControl {
4644

@@ -168,7 +166,7 @@ public String styleHtml(String html) {
168166
(foreground != null ? "color: " + toHTMLrgb(foreground.getRGB()) + "; " : "") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
169167
" }</style>"; //$NON-NLS-1$
170168

171-
String hlStyle = null;
169+
String hlStyle = ""; //$NON-NLS-1$
172170
try {
173171
URL urlHJScript = FileLocator.toFileURL(LanguageServerPlugin.getDefault().getClass().getResource("/resources/highlight.min.js/highlight.min.js")); //$NON-NLS-1$
174172
URL urlHJCss = FileLocator.toFileURL(LanguageServerPlugin.getDefault().getClass().getResource(isDarkTheme() ? //
@@ -184,7 +182,7 @@ public String styleHtml(String html) {
184182
}
185183

186184
int headIndex = html.indexOf(HEAD);
187-
String headContent = style + Strings.nullToEmpty(hlStyle);
185+
String headContent = style + hlStyle;
188186
if (headIndex > 0) {
189187
return new StringBuilder(html).insert(headIndex, headContent).toString();
190188
} else {

0 commit comments

Comments
 (0)