summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-06-30 23:08:09 -0700
committerGeorge Fraser <george@fivetran.com>2018-06-30 23:08:09 -0700
commitf7fa473a1b75b25ca812543be80fc998fc05c448 (patch)
tree4928c59f16808a0e0857928897e4d66104159258 /src/test
parent9d3a72cfcff5df7e2f58852d13d820ee27a0df7d (diff)
downloadjava-language-server-f7fa473a1b75b25ca812543be80fc998fc05c448.zip
Use var
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/javacs/CompletionsBase.java25
-rw-r--r--src/test/java/org/javacs/CompletionsScopesTest.java37
-rw-r--r--src/test/java/org/javacs/CompletionsTest.java266
-rw-r--r--src/test/java/org/javacs/FindReferencesTest.java5
-rw-r--r--src/test/java/org/javacs/FindResource.java6
-rw-r--r--src/test/java/org/javacs/InferConfigTest.java5
-rw-r--r--src/test/java/org/javacs/JavaCompilerServiceTest.java93
-rw-r--r--src/test/java/org/javacs/LanguageServerFixture.java4
-rw-r--r--src/test/java/org/javacs/ParserFixImportsTest.java6
-rw-r--r--src/test/java/org/javacs/SearchTest.java20
-rw-r--r--src/test/java/org/javacs/SignatureHelpTest.java14
-rw-r--r--src/test/java/org/javacs/SymbolUnderCursorTest.java4
12 files changed, 228 insertions, 257 deletions
diff --git a/src/test/java/org/javacs/CompletionsBase.java b/src/test/java/org/javacs/CompletionsBase.java
index a8da4c2..aefd10e 100644
--- a/src/test/java/org/javacs/CompletionsBase.java
+++ b/src/test/java/org/javacs/CompletionsBase.java
@@ -1,7 +1,6 @@
package org.javacs;
import java.io.IOException;
-import java.net.URI;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -19,13 +18,13 @@ public class CompletionsBase {
protected static final Logger LOG = Logger.getLogger("main");
protected Set<String> insertTemplate(String file, int row, int column) throws IOException {
- List<? extends CompletionItem> items = items(file, row, column);
+ var items = items(file, row, column);
return items.stream().map(CompletionsBase::itemInsertTemplate).collect(Collectors.toSet());
}
static String itemInsertTemplate(CompletionItem i) {
- String text = i.getInsertText();
+ var text = i.getInsertText();
if (text == null) text = i.getLabel();
@@ -35,18 +34,18 @@ public class CompletionsBase {
}
protected Set<String> insertText(String file, int row, int column) throws IOException {
- List<? extends CompletionItem> items = items(file, row, column);
+ var items = items(file, row, column);
return items.stream().map(CompletionsBase::itemInsertText).collect(Collectors.toSet());
}
protected Map<String, Integer> insertCount(String file, int row, int column) throws IOException {
- List<? extends CompletionItem> items = items(file, row, column);
- Map<String, Integer> result = new HashMap<>();
+ var items = items(file, row, column);
+ var result = new HashMap<String, Integer>();
- for (CompletionItem each : items) {
- String key = itemInsertText(each);
- int count = result.getOrDefault(key, 0) + 1;
+ for (var each : items) {
+ var key = itemInsertText(each);
+ var count = result.getOrDefault(key, 0) + 1;
result.put(key, count);
}
@@ -55,7 +54,7 @@ public class CompletionsBase {
}
static String itemInsertText(CompletionItem i) {
- String text = i.getInsertText();
+ var text = i.getInsertText();
if (text == null) text = i.getLabel();
@@ -67,7 +66,7 @@ public class CompletionsBase {
}
protected Set<String> documentation(String file, int row, int column) throws IOException {
- List<? extends CompletionItem> items = items(file, row, column);
+ var items = items(file, row, column);
return items.stream()
.flatMap(
@@ -82,8 +81,8 @@ public class CompletionsBase {
protected static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
protected List<? extends CompletionItem> items(String file, int row, int column) {
- URI uri = FindResource.uri(file);
- CompletionParams position =
+ var uri = FindResource.uri(file);
+ var position =
new CompletionParams(new TextDocumentIdentifier(uri.toString()), new Position(row - 1, column - 1));
try {
diff --git a/src/test/java/org/javacs/CompletionsScopesTest.java b/src/test/java/org/javacs/CompletionsScopesTest.java
index 4f43498..af7ba00 100644
--- a/src/test/java/org/javacs/CompletionsScopesTest.java
+++ b/src/test/java/org/javacs/CompletionsScopesTest.java
@@ -5,16 +5,15 @@ import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.io.IOException;
-import java.util.Set;
import org.junit.Test;
public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSub() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 15, 14);
+ var suggestions = insertText(file, 15, 14);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -35,7 +34,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// StaticSub.this, StaticSub.super
assertThat(insertText(file, 37, 23), hasItems("this", "super"));
@@ -47,10 +46,10 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubInner() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 45, 22);
+ var suggestions = insertText(file, 45, 22);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -71,7 +70,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubInnerThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// StaticSub.this, StaticSub.super
assertThat(insertText(file, 67, 31), hasItems("this", "super"));
@@ -83,10 +82,10 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubStaticMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 78, 14);
+ var suggestions = insertText(file, 78, 14);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -107,7 +106,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubStaticMethodThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// StaticSub.this, StaticSub.super
assertThat(insertText(file, 100, 23), not(hasItems("this", "super")));
@@ -119,10 +118,10 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubStaticMethodInner() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 108, 22);
+ var suggestions = insertText(file, 108, 22);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -143,7 +142,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void staticSubStaticMethodInnerThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// StaticSub.this, StaticSub.super
assertThat(insertText(file, 130, 31), not(hasItems("this", "super")));
@@ -155,10 +154,10 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void sub() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 143, 14);
+ var suggestions = insertText(file, 143, 14);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -179,7 +178,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void subThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// sub.this, sub.super
assertThat(insertText(file, 158, 17), hasItems("this", "super"));
@@ -191,10 +190,10 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void subInner() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// Static method
- Set<String> suggestions = insertText(file, 166, 22);
+ var suggestions = insertText(file, 166, 22);
// Locals
assertThat(suggestions, hasItems("localVariables", "arguments"));
@@ -215,7 +214,7 @@ public class CompletionsScopesTest extends CompletionsBase {
@Test
public void subInnerThisSuper() throws IOException {
- String file = "/org/javacs/example/AutocompleteScopes.java";
+ var file = "/org/javacs/example/AutocompleteScopes.java";
// sub.this, sub.super
assertThat(insertText(file, 181, 25), hasItems("this", "super"));
diff --git a/src/test/java/org/javacs/CompletionsTest.java b/src/test/java/org/javacs/CompletionsTest.java
index 50b14f6..19578fe 100644
--- a/src/test/java/org/javacs/CompletionsTest.java
+++ b/src/test/java/org/javacs/CompletionsTest.java
@@ -5,9 +5,6 @@ import static org.junit.Assert.*;
import com.google.common.collect.Lists;
import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.lsp4j.CompletionItem;
import org.junit.Ignore;
@@ -17,10 +14,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void staticMember() throws IOException {
- String file = "/org/javacs/example/AutocompleteStaticMember.java";
+ var file = "/org/javacs/example/AutocompleteStaticMember.java";
// Static methods
- Set<String> suggestions = insertText(file, 5, 34);
+ var suggestions = insertText(file, 5, 34);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic", "class"));
assertThat(suggestions, not(hasItems("fields", "methods", "getClass")));
@@ -28,10 +25,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void staticReference() throws IOException {
- String file = "/org/javacs/example/AutocompleteStaticReference.java";
+ var file = "/org/javacs/example/AutocompleteStaticReference.java";
// Static methods
- Set<String> suggestions = insertText(file, 7, 44);
+ var suggestions = insertText(file, 7, 44);
assertThat(suggestions, hasItems("methods", "methodStatic"));
assertThat(suggestions, not(hasItems("new")));
@@ -39,10 +36,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void member() throws IOException {
- String file = "/org/javacs/example/AutocompleteMember.java";
+ var file = "/org/javacs/example/AutocompleteMember.java";
// Virtual methods
- Set<String> suggestions = insertText(file, 5, 14);
+ var suggestions = insertText(file, 5, 14);
assertThat(
"excludes static members",
@@ -65,12 +62,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
@Ignore // This has been subsumed by Javadocs
public void throwsSignature() throws IOException {
- String file = "/org/javacs/example/AutocompleteMember.java";
+ var file = "/org/javacs/example/AutocompleteMember.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 5, 14);
- Set<String> suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
- Set<String> details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
+ var items = items(file, 5, 14);
+ var suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
+ var details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
assertThat(suggestions, hasItems("methods"));
assertThat(details, hasItems("String () throws Exception"));
@@ -78,20 +75,20 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fieldFromInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// f
- Set<String> suggestions = insertText(file, 8, 10);
+ var suggestions = insertText(file, 8, 10);
assertThat(suggestions, hasItems("fields", "fieldStatic", "methods", "methodStatic"));
}
@Test
public void thisDotFieldFromInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// this.f
- Set<String> suggestions = insertText(file, 9, 15);
+ var suggestions = insertText(file, 9, 15);
assertThat(suggestions, hasItems("fields", "methods"));
assertThat(suggestions, not(hasItems("fieldStatic", "methodStatic")));
@@ -99,10 +96,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classDotFieldFromInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers.f
- Set<String> suggestions = insertText(file, 10, 30);
+ var suggestions = insertText(file, 10, 30);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic"));
assertThat(suggestions, not(hasItems("fields", "methods")));
@@ -110,20 +107,20 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fieldFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// f
- Set<String> suggestions = insertText(file, 22, 10);
+ var suggestions = insertText(file, 22, 10);
assertThat(suggestions, hasItems("fields", "fieldStatic", "methods", "methodStatic", "arguments"));
}
@Test
public void thisDotFieldFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// this.f
- Set<String> suggestions = insertText(file, 23, 15);
+ var suggestions = insertText(file, 23, 15);
assertThat(suggestions, hasItems("fields", "methods"));
assertThat(suggestions, not(hasItems("fieldStatic", "methodStatic", "arguments")));
@@ -131,10 +128,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classDotFieldFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers.f
- Set<String> suggestions = insertText(file, 24, 30);
+ var suggestions = insertText(file, 24, 30);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic"));
assertThat(suggestions, not(hasItems("fields", "methods", "arguments")));
@@ -142,10 +139,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void thisRefMethodFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// this::m
- Set<String> suggestions = insertText(file, 25, 59);
+ var suggestions = insertText(file, 25, 59);
assertThat(suggestions, hasItems("methods"));
assertThat(suggestions, not(hasItems("fields", "fieldStatic", "methodStatic")));
@@ -153,10 +150,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classRefMethodFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers::m
- Set<String> suggestions = insertText(file, 26, 74);
+ var suggestions = insertText(file, 26, 74);
assertThat(suggestions, hasItems("methodStatic", "methods"));
assertThat(suggestions, not(hasItems("fields", "fieldStatic")));
@@ -165,10 +162,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
@Ignore // javac doesn't give us helpful info about the fact that static initializers are static
public void fieldFromStaticInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// f
- Set<String> suggestions = insertText(file, 16, 10);
+ var suggestions = insertText(file, 16, 10);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic"));
assertThat(suggestions, not(hasItems("fields", "methods")));
@@ -176,10 +173,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classDotFieldFromStaticInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers.f
- Set<String> suggestions = insertText(file, 17, 30);
+ var suggestions = insertText(file, 17, 30);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic"));
assertThat(suggestions, not(hasItems("fields", "methods")));
@@ -187,10 +184,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classRefFieldFromStaticInitBlock() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers::m
- Set<String> suggestions = insertText(file, 17, 30);
+ var suggestions = insertText(file, 17, 30);
assertThat(suggestions, hasItems("methodStatic"));
assertThat(suggestions, not(hasItems("fields", "fieldStatic", "methods")));
@@ -198,10 +195,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fieldFromStaticMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// f
- Set<String> suggestions = insertText(file, 30, 10);
+ var suggestions = insertText(file, 30, 10);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic", "arguments"));
assertThat(suggestions, not(hasItems("fields", "methods")));
@@ -209,10 +206,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classDotFieldFromStaticMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// AutocompleteMembers.f
- Set<String> suggestions = insertText(file, 31, 30);
+ var suggestions = insertText(file, 31, 30);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic"));
assertThat(suggestions, not(hasItems("fields", "methods", "arguments")));
@@ -220,11 +217,11 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classRefFieldFromStaticMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteMembers.java";
+ var file = "/org/javacs/example/AutocompleteMembers.java";
// TODO
// AutocompleteMembers::m
- Set<String> suggestions = insertText(file, 17, 30);
+ var suggestions = insertText(file, 17, 30);
assertThat(suggestions, hasItems("methodStatic"));
assertThat(suggestions, not(hasItems("fields", "fieldStatic", "methods")));
@@ -237,10 +234,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void otherMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// new AutocompleteMember().
- Set<String> suggestions = insertText(file, 5, 34);
+ var suggestions = insertText(file, 5, 34);
assertThat(suggestions, not(hasItems("fieldStatic", "methodStatic", "class")));
assertThat(suggestions, not(hasItems("fieldStaticPrivate", "methodStaticPrivate")));
@@ -250,10 +247,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void otherStatic() throws IOException {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// AutocompleteMember.
- Set<String> suggestions = insertText(file, 7, 28);
+ var suggestions = insertText(file, 7, 28);
assertThat(suggestions, hasItems("fieldStatic", "methodStatic", "class"));
assertThat(suggestions, not(hasItems("fieldStaticPrivate", "methodStaticPrivate")));
@@ -263,10 +260,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void otherDotClassDot() throws IOException {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// AutocompleteMember.class.
- Set<String> suggestions = insertText(file, 8, 33);
+ var suggestions = insertText(file, 8, 33);
assertThat(suggestions, hasItems("getName", "getClass"));
assertThat(suggestions, not(hasItems("fieldStatic", "methodStatic", "class")));
@@ -277,10 +274,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void otherClass() throws IOException {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- Set<String> suggestions = insertText(file, 6, 10);
+ var suggestions = insertText(file, 6, 10);
// String is in root scope, List is in import java.util.*
assertThat(suggestions, hasItems("AutocompleteOther", "AutocompleteMember"));
@@ -288,12 +285,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void addImport() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 9, 17);
+ var items = items(file, 9, 17);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("ArrayList".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), not(nullValue()));
assertThat(item.getAdditionalTextEdits(), not(empty()));
@@ -307,12 +304,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void dontImportSamePackage() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 6, 10);
+ var items = items(file, 6, 10);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("AutocompleteMember".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue()));
@@ -325,12 +322,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void dontImportJavaLang() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 11, 38);
+ var items = items(file, 11, 38);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("ArrayIndexOutOfBoundsException".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue()));
@@ -343,12 +340,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void dontImportSelf() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 6, 10);
+ var items = items(file, 6, 10);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("AutocompleteOther".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue()));
@@ -361,12 +358,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void dontImportAlreadyImported() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 12, 14);
+ var items = items(file, 12, 14);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("Arrays".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue()));
@@ -379,12 +376,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void dontImportAlreadyImportedStar() {
- String file = "/org/javacs/example/AutocompleteOther.java";
+ var file = "/org/javacs/example/AutocompleteOther.java";
// Name of class
- List<? extends CompletionItem> items = items(file, 10, 26);
+ var items = items(file, 10, 26);
- for (CompletionItem item : items) {
+ for (var item : items) {
if ("ArrayBlockingQueue".equals(item.getLabel())) {
assertThat(item.getAdditionalTextEdits(), either(empty()).or(nullValue()));
@@ -397,32 +394,32 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fromClasspath() throws IOException {
- String file = "/org/javacs/example/AutocompleteFromClasspath.java";
+ var file = "/org/javacs/example/AutocompleteFromClasspath.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 8, 17);
- Set<String> suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
- Set<String> details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
+ var items = items(file, 8, 17);
+ var suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
+ var details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
assertThat(suggestions, hasItems("add", "addAll"));
}
@Test
public void betweenLines() throws IOException {
- String file = "/org/javacs/example/AutocompleteBetweenLines.java";
+ var file = "/org/javacs/example/AutocompleteBetweenLines.java";
// Static methods
- Set<String> suggestions = insertText(file, 9, 18);
+ var suggestions = insertText(file, 9, 18);
assertThat(suggestions, hasItems("add"));
}
@Test
public void reference() throws IOException {
- String file = "/org/javacs/example/AutocompleteReference.java";
+ var file = "/org/javacs/example/AutocompleteReference.java";
// Static methods
- Set<String> suggestions = insertTemplate(file, 7, 21);
+ var suggestions = insertTemplate(file, 7, 21);
assertThat(suggestions, not(hasItems("methodStatic")));
assertThat(suggestions, hasItems("methods", "getClass"));
@@ -431,9 +428,8 @@ public class CompletionsTest extends CompletionsBase {
@Test
@Ignore // This has been subsumed by Javadocs
public void docstring() throws IOException {
- String file = "/org/javacs/example/AutocompleteDocstring.java";
-
- Set<String> docstrings = documentation(file, 8, 14);
+ var file = "/org/javacs/example/AutocompleteDocstring.java";
+ var docstrings = documentation(file, 8, 14);
assertThat(docstrings, hasItems("A methods", "A fields"));
@@ -444,20 +440,20 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classes() throws IOException {
- String file = "/org/javacs/example/AutocompleteClasses.java";
+ var file = "/org/javacs/example/AutocompleteClasses.java";
// Static methods
- Set<String> suggestions = insertText(file, 5, 10);
+ var suggestions = insertText(file, 5, 10);
assertThat(suggestions, hasItems("FixParseErrorAfter", "SomeInnerClass"));
}
@Test
public void editMethodName() throws IOException {
- String file = "/org/javacs/example/AutocompleteEditMethodName.java";
+ var file = "/org/javacs/example/AutocompleteEditMethodName.java";
// Static methods
- Set<String> suggestions = insertText(file, 5, 21);
+ var suggestions = insertText(file, 5, 21);
assertThat(suggestions, hasItems("getClass"));
}
@@ -465,12 +461,12 @@ public class CompletionsTest extends CompletionsBase {
@Test
@Ignore // This has been subsumed by Javadocs
public void restParams() throws IOException {
- String file = "/org/javacs/example/AutocompleteRest.java";
+ var file = "/org/javacs/example/AutocompleteRest.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 5, 18);
- Set<String> suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
- Set<String> details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
+ var items = items(file, 5, 18);
+ var suggestions = items.stream().map(i -> i.getLabel()).collect(Collectors.toSet());
+ var details = items.stream().map(i -> i.getDetail()).collect(Collectors.toSet());
assertThat(suggestions, hasItems("restMethod"));
assertThat(details, hasItems("void (String... params)"));
@@ -478,10 +474,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void constructor() throws IOException {
- String file = "/org/javacs/example/AutocompleteConstructor.java";
+ var file = "/org/javacs/example/AutocompleteConstructor.java";
// Static methods
- Set<String> suggestions = insertText(file, 5, 25);
+ var suggestions = insertText(file, 5, 25);
assertThat(suggestions, hasItem(startsWith("AutocompleteConstructor")));
assertThat(suggestions, hasItem(startsWith("AutocompleteMember")));
@@ -489,15 +485,15 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void autoImportConstructor() throws IOException {
- String file = "/org/javacs/example/AutocompleteConstructor.java";
+ var file = "/org/javacs/example/AutocompleteConstructor.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 6, 19);
- List<String> suggestions = Lists.transform(items, i -> i.getInsertText());
+ var items = items(file, 6, 19);
+ var suggestions = Lists.transform(items, i -> i.getInsertText());
assertThat(suggestions, hasItems("ArrayList<>($0)"));
- for (CompletionItem each : items) {
+ for (var each : items) {
if (each.getInsertText().equals("ArrayList<>"))
assertThat(
"new ? auto-imports", each.getAdditionalTextEdits(), both(not(empty())).and(not(nullValue())));
@@ -506,56 +502,56 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void importFromSource() throws IOException {
- String file = "/org/javacs/example/AutocompletePackage.java";
+ var file = "/org/javacs/example/AutocompletePackage.java";
// Static methods
- Set<String> suggestions = insertText(file, 3, 12);
+ var suggestions = insertText(file, 3, 12);
assertThat("Does not have own package class", suggestions, hasItems("javacs"));
}
@Test
public void importFromClasspath() throws IOException {
- String file = "/org/javacs/example/AutocompletePackage.java";
+ var file = "/org/javacs/example/AutocompletePackage.java";
// Static methods
- Set<String> suggestions = insertText(file, 5, 13);
+ var suggestions = insertText(file, 5, 13);
assertThat("Has class from classpath", suggestions, hasItems("util"));
}
@Test
public void importFirstId() throws IOException {
- String file = "/org/javacs/example/AutocompletePackage.java";
+ var file = "/org/javacs/example/AutocompletePackage.java";
// Static methods
- Set<String> suggestions = insertText(file, 7, 9);
+ var suggestions = insertText(file, 7, 9);
assertThat("Has class from classpath", suggestions, hasItems("com", "org"));
}
@Test
public void emptyClasspath() throws IOException {
- String file = "/org/javacs/example/AutocompletePackage.java";
+ var file = "/org/javacs/example/AutocompletePackage.java";
// Static methods
- Set<String> suggestions = insertText(file, 6, 12);
+ var suggestions = insertText(file, 6, 12);
assertThat("Has deeply nested class", suggestions, not(hasItems("google.common.collect.Lists")));
}
@Test
public void importClass() throws IOException {
- String file = "/org/javacs/example/AutocompletePackage.java";
+ var file = "/org/javacs/example/AutocompletePackage.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 4, 25);
- List<String> suggestions = Lists.transform(items, i -> i.getLabel());
+ var items = items(file, 4, 25);
+ var suggestions = Lists.transform(items, i -> i.getLabel());
assertThat(suggestions, hasItems("OtherPackagePublic"));
assertThat(suggestions, not(hasItems("OtherPackagePrivate")));
- for (CompletionItem item : items) {
+ for (var item : items) {
if (item.getLabel().equals("OtherPackagePublic"))
assertThat(
"Don't import when completing imports",
@@ -566,16 +562,16 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void otherPackageId() throws IOException {
- String file = "/org/javacs/example/AutocompleteOtherPackage.java";
+ var file = "/org/javacs/example/AutocompleteOtherPackage.java";
// Static methods
- List<? extends CompletionItem> items = items(file, 5, 14);
- List<String> suggestions = Lists.transform(items, i -> i.getLabel());
+ var items = items(file, 5, 14);
+ var suggestions = Lists.transform(items, i -> i.getLabel());
assertThat(suggestions, hasItems("OtherPackagePublic"));
assertThat(suggestions, not(hasItems("OtherPackagePrivate")));
- for (CompletionItem item : items) {
+ for (var item : items) {
if (item.getLabel().equals("OtherPackagePublic"))
assertThat("Auto-import OtherPackagePublic", item.getAdditionalTextEdits(), not(empty()));
}
@@ -583,10 +579,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fieldFromStaticInner() throws IOException {
- String file = "/org/javacs/example/AutocompleteOuter.java";
+ var file = "/org/javacs/example/AutocompleteOuter.java";
// Initializer of static inner class
- Set<String> suggestions = insertText(file, 12, 14);
+ var suggestions = insertText(file, 12, 14);
assertThat(suggestions, hasItems("methodStatic", "fieldStatic"));
assertThat(suggestions, not(hasItems("methods", "fields")));
@@ -594,10 +590,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void fieldFromInner() throws IOException {
- String file = "/org/javacs/example/AutocompleteOuter.java";
+ var file = "/org/javacs/example/AutocompleteOuter.java";
// Initializer of inner class
- Set<String> suggestions = insertText(file, 18, 14);
+ var suggestions = insertText(file, 18, 14);
assertThat(suggestions, hasItems("methodStatic", "fieldStatic"));
assertThat(suggestions, hasItems("methods", "fields"));
@@ -605,10 +601,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void classDotClassFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteInners.java";
+ var file = "/org/javacs/example/AutocompleteInners.java";
// AutocompleteInners.I
- Set<String> suggestions = insertText(file, 5, 29);
+ var suggestions = insertText(file, 5, 29);
assertThat("suggests qualified inner class declaration", suggestions, hasItem("InnerClass"));
assertThat("suggests qualified inner enum declaration", suggestions, hasItem("InnerEnum"));
@@ -616,10 +612,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void innerClassFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteInners.java";
+ var file = "/org/javacs/example/AutocompleteInners.java";
// I
- Set<String> suggestions = insertText(file, 6, 10);
+ var suggestions = insertText(file, 6, 10);
assertThat("suggests unqualified inner class declaration", suggestions, hasItem("InnerClass"));
assertThat("suggests unqualified inner enum declaration", suggestions, hasItem("InnerEnum"));
@@ -627,10 +623,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void newClassDotInnerClassFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteInners.java";
+ var file = "/org/javacs/example/AutocompleteInners.java";
// new AutocompleteInners.I
- Set<String> suggestions = insertText(file, 10, 33);
+ var suggestions = insertText(file, 10, 33);
assertThat("suggests qualified inner class declaration", suggestions, hasItem("InnerClass"));
assertThat("suggests qualified inner enum declaration", suggestions, not(hasItem("InnerEnum")));
@@ -638,10 +634,10 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void newInnerClassFromMethod() throws IOException {
- String file = "/org/javacs/example/AutocompleteInners.java";
+ var file = "/org/javacs/example/AutocompleteInners.java";
// new I
- Set<String> suggestions = insertText(file, 11, 14);
+ var suggestions = insertText(file, 11, 14);
assertThat("suggests unqualified inner class declaration", suggestions, hasItem("InnerClass"));
assertThat("suggests unqualified inner enum declaration", suggestions, not(hasItem("InnerEnum")));
@@ -649,36 +645,32 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void innerEnum() throws IOException {
- String file = "/org/javacs/example/AutocompleteInners.java";
-
- Set<String> suggestions = insertText(file, 15, 40);
+ var file = "/org/javacs/example/AutocompleteInners.java";
+ var suggestions = insertText(file, 15, 40);
assertThat("suggests enum constants", suggestions, hasItems("Foo"));
}
@Test
public void staticStarImport() throws IOException {
- String file = "/org/javacs/example/AutocompleteStaticImport.java";
-
- Set<String> suggestions = insertText(file, 9, 15);
+ var file = "/org/javacs/example/AutocompleteStaticImport.java";
+ var suggestions = insertText(file, 9, 15);
assertThat("suggests star-imported static method", suggestions, hasItems("emptyList"));
}
@Test
public void staticImport() throws IOException {
- String file = "/org/javacs/example/AutocompleteStaticImport.java";
-
- Set<String> suggestions = insertText(file, 10, 10);
+ var file = "/org/javacs/example/AutocompleteStaticImport.java";
+ var suggestions = insertText(file, 10, 10);
assertThat("suggests star-imported static field", suggestions, hasItems("BC"));
}
@Test
public void staticImportSourcePath() throws IOException {
- String file = "/org/javacs/example/AutocompleteStaticImport.java";
-
- Set<String> suggestions = insertText(file, 11, 20);
+ var file = "/org/javacs/example/AutocompleteStaticImport.java";
+ var suggestions = insertText(file, 11, 20);
assertThat(
"suggests star-imported public static field from source path",
@@ -692,18 +684,16 @@ public class CompletionsTest extends CompletionsBase {
@Test
public void withinConstructor() throws IOException {
- String file = "/org/javacs/example/AutocompleteContext.java";
-
- Set<String> suggestions = insertText(file, 8, 38);
+ var file = "/org/javacs/example/AutocompleteContext.java";
+ var suggestions = insertText(file, 8, 38);
assertThat("suggests local variable", suggestions, hasItems("length"));
}
@Test
public void onlySuggestOnce() throws IOException {
- String file = "/org/javacs/example/AutocompleteOnce.java";
-
- Map<String, Integer> suggestions = insertCount(file, 5, 18);
+ var file = "/org/javacs/example/AutocompleteOnce.java";
+ var suggestions = insertCount(file, 5, 18);
assertThat("suggests Signatures", suggestions, hasKey("Signatures"));
assertThat("suggests Signatures only once", suggestions, hasEntry("Signatures", 1));
diff --git a/src/test/java/org/javacs/FindReferencesTest.java b/src/test/java/org/javacs/FindReferencesTest.java
index e5d380a..50b8ea5 100644
--- a/src/test/java/org/javacs/FindReferencesTest.java
+++ b/src/test/java/org/javacs/FindReferencesTest.java
@@ -3,7 +3,6 @@ package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
-import java.net.URI;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Logger;
@@ -19,8 +18,8 @@ public class FindReferencesTest {
private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
protected List<? extends Location> items(String file, int row, int column) {
- URI uri = FindResource.uri(file);
- ReferenceParams params = new ReferenceParams();
+ var uri = FindResource.uri(file);
+ var params = new ReferenceParams();
params.setTextDocument(new TextDocumentIdentifier(uri.toString()));
params.setUri(uri.toString());
diff --git a/src/test/java/org/javacs/FindResource.java b/src/test/java/org/javacs/FindResource.java
index 55b519f..cb8a95d 100644
--- a/src/test/java/org/javacs/FindResource.java
+++ b/src/test/java/org/javacs/FindResource.java
@@ -1,8 +1,6 @@
package org.javacs;
-import java.io.File;
import java.net.URI;
-import java.nio.file.Path;
import java.nio.file.Paths;
/** Find java sources in test-project/workspace/src */
@@ -10,8 +8,8 @@ public class FindResource {
public static URI uri(String resourcePath) {
if (resourcePath.startsWith("/")) resourcePath = resourcePath.substring(1);
- Path path = Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).normalize();
- File file = path.toFile();
+ var path = Paths.get("./src/test/test-project/workspace/src").resolve(resourcePath).normalize();
+ var file = path.toFile();
if (!file.exists()) throw new RuntimeException(file + " does not exist");
diff --git a/src/test/java/org/javacs/InferConfigTest.java b/src/test/java/org/javacs/InferConfigTest.java
index 33c1b39..a39b0c6 100644
--- a/src/test/java/org/javacs/InferConfigTest.java
+++ b/src/test/java/org/javacs/InferConfigTest.java
@@ -5,7 +5,6 @@ import static org.junit.Assert.*;
import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Optional;
import org.junit.Test;
public class InferConfigTest {
@@ -16,7 +15,7 @@ public class InferConfigTest {
@Test
public void mavenClassPath() {
- Optional<Path> found = infer.findMavenJar(externalArtifact, false);
+ var found = infer.findMavenJar(externalArtifact, false);
assertTrue(found.isPresent());
assertThat(
found.get(),
@@ -26,7 +25,7 @@ public class InferConfigTest {
@Test
public void mavenDocPath() {
- Optional<Path> found = infer.findMavenJar(externalArtifact, true);
+ var found = infer.findMavenJar(externalArtifact, true);
assertTrue(found.isPresent());
assertThat(
found.get(),
diff --git a/src/test/java/org/javacs/JavaCompilerServiceTest.java b/src/test/java/org/javacs/JavaCompilerServiceTest.java
index 563fbb8..d776078 100644
--- a/src/test/java/org/javacs/JavaCompilerServiceTest.java
+++ b/src/test/java/org/javacs/JavaCompilerServiceTest.java
@@ -3,14 +3,8 @@ package org.javacs;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
-import com.sun.source.tree.CompilationUnitTree;
-import com.sun.source.tree.LineMap;
-import com.sun.source.util.SourcePositions;
-import com.sun.source.util.TreePath;
-import com.sun.source.util.Trees;
import java.io.BufferedReader;
import java.io.IOException;
-import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
@@ -19,11 +13,9 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Set;
import java.util.logging.Logger;
import java.util.stream.Collectors;
import javax.lang.model.element.Element;
-import javax.lang.model.element.ExecutableElement;
import javax.tools.Diagnostic;
import javax.tools.JavaFileObject;
import org.junit.Test;
@@ -44,7 +36,7 @@ public class JavaCompilerServiceTest {
}
private String contents(String resourceFile) {
- try (InputStream in = JavaCompilerServiceTest.class.getResourceAsStream(resourceFile)) {
+ try (var in = JavaCompilerServiceTest.class.getResourceAsStream(resourceFile)) {
return new BufferedReader(new InputStreamReader(in)).lines().collect(Collectors.joining("\n"));
} catch (IOException e) {
throw new RuntimeException(e);
@@ -61,37 +53,37 @@ public class JavaCompilerServiceTest {
@Test
public void element() {
- Element found = compiler.element(URI.create("/HelloWorld.java"), contents("/HelloWorld.java"), 3, 24);
+ var found = compiler.element(URI.create("/HelloWorld.java"), contents("/HelloWorld.java"), 3, 24);
assertThat(found.getSimpleName(), hasToString(containsString("println")));
}
@Test
public void elementWithError() {
- Element found = compiler.element(URI.create("/CompleteMembers.java"), contents("/CompleteMembers.java"), 3, 12);
+ var found = compiler.element(URI.create("/CompleteMembers.java"), contents("/CompleteMembers.java"), 3, 12);
assertThat(found, notNullValue());
}
@Test
public void pruneMethods() {
- Pruner pruner = new Pruner(URI.create("/PruneMethods.java"), contents("/PruneMethods.java"));
+ var pruner = new Pruner(URI.create("/PruneMethods.java"), contents("/PruneMethods.java"));
pruner.prune(6, 19);
- String expected = contents("/PruneMethods_erased.java");
+ var expected = contents("/PruneMethods_erased.java");
assertThat(pruner.contents(), equalToIgnoringWhiteSpace(expected));
}
@Test
public void pruneToEndOfBlock() {
- Pruner pruner = new Pruner(URI.create("/PruneToEndOfBlock.java"), contents("/PruneToEndOfBlock.java"));
+ var pruner = new Pruner(URI.create("/PruneToEndOfBlock.java"), contents("/PruneToEndOfBlock.java"));
pruner.prune(4, 18);
- String expected = contents("/PruneToEndOfBlock_erased.java");
+ var expected = contents("/PruneToEndOfBlock_erased.java");
assertThat(pruner.contents(), equalToIgnoringWhiteSpace(expected));
}
private List<String> completionNames(List<Completion> found) {
- List<String> result = new ArrayList<>();
- for (Completion c : found) {
+ var result = new ArrayList<String>();
+ for (var c : found) {
if (c.element != null) result.add(c.element.getSimpleName().toString());
else if (c.packagePart != null) result.add(c.packagePart.name);
else if (c.keyword != null) result.add(c.keyword);
@@ -106,10 +98,10 @@ public class JavaCompilerServiceTest {
@Test
public void identifiers() {
- List<Element> found =
+ var found =
compiler.scopeMembers(
URI.create("/CompleteIdentifiers.java"), contents("/CompleteIdentifiers.java"), 13, 21);
- List<String> names = elementNames(found);
+ var names = elementNames(found);
assertThat(names, hasItem("completeLocal"));
assertThat(names, hasItem("completeParam"));
assertThat(names, hasItem("super"));
@@ -123,9 +115,9 @@ public class JavaCompilerServiceTest {
@Test
public void identifiersInMiddle() {
- List<Element> found =
+ var found =
compiler.scopeMembers(URI.create("/CompleteInMiddle.java"), contents("/CompleteInMiddle.java"), 13, 21);
- List<String> names = elementNames(found);
+ var names = elementNames(found);
assertThat(names, hasItem("completeLocal"));
assertThat(names, hasItem("completeParam"));
assertThat(names, hasItem("super"));
@@ -139,7 +131,7 @@ public class JavaCompilerServiceTest {
@Test
public void completeIdentifiers() {
- List<Completion> found =
+ var found =
compiler.completions(
URI.create("/CompleteIdentifiers.java"),
contents("/CompleteIdentifiers.java"),
@@ -147,7 +139,7 @@ public class JavaCompilerServiceTest {
21,
Integer.MAX_VALUE)
.items;
- List<String> names = completionNames(found);
+ var names = completionNames(found);
assertThat(names, hasItem("completeLocal"));
assertThat(names, hasItem("completeParam"));
assertThat(names, hasItem("super"));
@@ -161,9 +153,8 @@ public class JavaCompilerServiceTest {
@Test
public void members() {
- List<Completion> found =
- compiler.members(URI.create("/CompleteMembers.java"), contents("/CompleteMembers.java"), 3, 14);
- List<String> names = completionNames(found);
+ var found = compiler.members(URI.create("/CompleteMembers.java"), contents("/CompleteMembers.java"), 3, 14);
+ var names = completionNames(found);
assertThat(names, hasItem("subMethod"));
assertThat(names, hasItem("superMethod"));
assertThat(names, hasItem("equals"));
@@ -171,7 +162,7 @@ public class JavaCompilerServiceTest {
@Test
public void completeMembers() {
- List<Completion> found =
+ var found =
compiler.completions(
URI.create("/CompleteMembers.java"),
contents("/CompleteMembers.java"),
@@ -179,7 +170,7 @@ public class JavaCompilerServiceTest {
15,
Integer.MAX_VALUE)
.items;
- List<String> names = completionNames(found);
+ var names = completionNames(found);
assertThat(names, hasItem("subMethod"));
assertThat(names, hasItem("superMethod"));
assertThat(names, hasItem("equals"));
@@ -187,7 +178,7 @@ public class JavaCompilerServiceTest {
@Test
public void completeExpression() {
- List<Completion> found =
+ var found =
compiler.completions(
URI.create("/CompleteExpression.java"),
contents("/CompleteExpression.java"),
@@ -195,7 +186,7 @@ public class JavaCompilerServiceTest {
37,
Integer.MAX_VALUE)
.items;
- List<String> names = completionNames(found);
+ var names = completionNames(found);
assertThat(names, hasItem("instanceMethod"));
assertThat(names, not(hasItem("create")));
assertThat(names, hasItem("equals"));
@@ -203,7 +194,7 @@ public class JavaCompilerServiceTest {
@Test
public void completeClass() {
- List<Completion> found =
+ var found =
compiler.completions(
URI.create("/CompleteClass.java"),
contents("/CompleteClass.java"),
@@ -211,7 +202,7 @@ public class JavaCompilerServiceTest {
23,
Integer.MAX_VALUE)
.items;
- List<String> names = completionNames(found);
+ var names = completionNames(found);
assertThat(names, hasItems("staticMethod", "staticField"));
assertThat(names, hasItems("class"));
assertThat(names, not(hasItem("instanceMethod")));
@@ -220,7 +211,7 @@ public class JavaCompilerServiceTest {
@Test
public void completeImports() {
- List<Completion> found =
+ var found =
compiler.completions(
URI.create("/CompleteImports.java"),
contents("/CompleteImports.java"),
@@ -228,7 +219,7 @@ public class JavaCompilerServiceTest {
18,
Integer.MAX_VALUE)
.items;
- List<String> names = completionNames(found);
+ var names = completionNames(found);
assertThat(names, hasItem("List"));
assertThat(names, hasItem("concurrent"));
}
@@ -236,17 +227,17 @@ public class JavaCompilerServiceTest {
/*
@Test
public void gotoDefinition() {
- Optional<TreePath> def =
+ var def =
compiler.definition(URI.create("/GotoDefinition.java"), 3, 12, uri -> Files.readAllText(uri));
assertTrue(def.isPresent());
- TreePath t = def.get();
- CompilationUnitTree unit = t.getCompilationUnit();
+ var t = def.get();
+ var unit = t.getCompilationUnit();
assertThat(unit.getSourceFile().getName(), endsWith("GotoDefinition.java"));
- Trees trees = compiler.trees();
- SourcePositions pos = trees.getSourcePositions();
- LineMap lines = unit.getLineMap();
+ var trees = compiler.trees();
+ var pos = trees.getSourcePositions();
+ var lines = unit.getLineMap();
long start = pos.getStartPosition(unit, t.getLeaf());
long line = lines.getLineNumber(start);
assertThat(line, equalTo(6L));
@@ -255,15 +246,14 @@ public class JavaCompilerServiceTest {
@Test
public void references() {
- List<TreePath> refs =
- compiler.references(URI.create("/GotoDefinition.java"), contents("/GotoDefinition.java"), 6, 13);
+ var refs = compiler.references(URI.create("/GotoDefinition.java"), contents("/GotoDefinition.java"), 6, 13);
boolean found = false;
- for (TreePath t : refs) {
- CompilationUnitTree unit = t.getCompilationUnit();
- String name = unit.getSourceFile().getName();
- Trees trees = compiler.trees();
- SourcePositions pos = trees.getSourcePositions();
- LineMap lines = unit.getLineMap();
+ for (var t : refs) {
+ var unit = t.getCompilationUnit();
+ var name = unit.getSourceFile().getName();
+ var trees = compiler.trees();
+ var pos = trees.getSourcePositions();
+ var lines = unit.getLineMap();
long start = pos.getStartPosition(unit, t.getLeaf());
long line = lines.getLineNumber(start);
if (name.endsWith("GotoDefinition.java") && line == 3) found = true;
@@ -274,8 +264,7 @@ public class JavaCompilerServiceTest {
@Test
public void overloads() {
- MethodInvocation found =
- compiler.methodInvocation(URI.create("/Overloads.java"), contents("/Overloads.java"), 3, 15).get();
+ var found = compiler.methodInvocation(URI.create("/Overloads.java"), contents("/Overloads.java"), 3, 15).get();
assertThat(found.overloads, hasItem(hasToString("print(int)")));
assertThat(found.overloads, hasToString("print(java.lang.String)"));
@@ -290,7 +279,7 @@ public class JavaCompilerServiceTest {
@Test
public void localDoc() {
- ExecutableElement method =
+ var method =
compiler.methodInvocation(URI.create("/LocalMethodDoc.java"), contents("/LocalMethodDoc.java"), 3, 21)
.get()
.activeMethod
@@ -302,7 +291,7 @@ public class JavaCompilerServiceTest {
@Test
public void fixImports() {
- Set<String> qualifiedNames =
+ var qualifiedNames =
compiler.fixImports(resourceUri("/MissingImport.java"), contents("/MissingImport.java")).fixedImports;
assertThat(qualifiedNames, hasItem("java.util.List"));
}
diff --git a/src/test/java/org/javacs/LanguageServerFixture.java b/src/test/java/org/javacs/LanguageServerFixture.java
index 6af0aee..94ba764 100644
--- a/src/test/java/org/javacs/LanguageServerFixture.java
+++ b/src/test/java/org/javacs/LanguageServerFixture.java
@@ -52,8 +52,8 @@ class LanguageServerFixture {
}
private static JavaLanguageServer getJavaLanguageServer(Path workspaceRoot, LanguageClient client) {
- JavaLanguageServer server = new JavaLanguageServer();
- InitializeParams init = new InitializeParams();
+ var server = new JavaLanguageServer();
+ var init = new InitializeParams();
init.setRootUri(workspaceRoot.toUri().toString());
diff --git a/src/test/java/org/javacs/ParserFixImportsTest.java b/src/test/java/org/javacs/ParserFixImportsTest.java
index b754fe1..65fa15d 100644
--- a/src/test/java/org/javacs/ParserFixImportsTest.java
+++ b/src/test/java/org/javacs/ParserFixImportsTest.java
@@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.util.Collections;
-import java.util.Map;
import org.junit.Test;
public class ParserFixImportsTest {
@@ -12,14 +11,13 @@ public class ParserFixImportsTest {
@Test
public void findJavaUtilList() {
- Map<String, String> resolved =
- Parser.resolveSymbols(Collections.singleton("List"), emptyImports, Collections.emptySet());
+ var resolved = Parser.resolveSymbols(Collections.singleton("List"), emptyImports, Collections.emptySet());
assertThat(resolved, hasEntry("List", "java.util.List"));
}
@Test
public void findExistingImports() {
- ExistingImports find = Parser.existingImports(Collections.singleton(JavaCompilerServiceTest.resourcesDir()));
+ var find = Parser.existingImports(Collections.singleton(JavaCompilerServiceTest.resourcesDir()));
assertThat(find.classes, hasItem("java.util.List"));
assertThat(find.packages, hasItem("java.util"));
}
diff --git a/src/test/java/org/javacs/SearchTest.java b/src/test/java/org/javacs/SearchTest.java
index 64d70a2..f99bba4 100644
--- a/src/test/java/org/javacs/SearchTest.java
+++ b/src/test/java/org/javacs/SearchTest.java
@@ -23,9 +23,9 @@ public class SearchTest {
@BeforeClass
public static void openSource() throws IOException {
- URI uri = FindResource.uri("/org/javacs/example/AutocompleteBetweenLines.java");
- String textContent = Joiner.on("\n").join(Files.readAllLines(Paths.get(uri)));
- TextDocumentItem document = new TextDocumentItem();
+ var uri = FindResource.uri("/org/javacs/example/AutocompleteBetweenLines.java");
+ var textContent = Joiner.on("\n").join(Files.readAllLines(Paths.get(uri)));
+ var document = new TextDocumentItem();
document.setUri(uri.toString());
document.setText(textContent);
@@ -62,29 +62,29 @@ public class SearchTest {
@Test
public void all() {
- Set<String> all = searchWorkspace("", 100);
+ var all = searchWorkspace("", 100);
assertThat(all, not(empty()));
}
@Test
public void searchClasses() {
- Set<String> all = searchWorkspace("ABetweenLines", Integer.MAX_VALUE);
+ var all = searchWorkspace("ABetweenLines", Integer.MAX_VALUE);
assertThat(all, hasItem("AutocompleteBetweenLines"));
}
@Test
public void searchMethods() {
- Set<String> all = searchWorkspace("mStatic", Integer.MAX_VALUE);
+ var all = searchWorkspace("mStatic", Integer.MAX_VALUE);
assertThat(all, hasItem("methodStatic"));
}
@Test
public void symbolsInFile() {
- String path = "/org/javacs/example/AutocompleteMemberFixed.java";
- Set<String> all = searchFile(FindResource.uri(path));
+ var path = "/org/javacs/example/AutocompleteMemberFixed.java";
+ var all = searchFile(FindResource.uri(path));
assertThat(
all,
@@ -101,8 +101,8 @@ public class SearchTest {
@Test
public void explicitConstructor() {
- String path = "/org/javacs/example/ReferenceConstructor.java";
- Set<String> all = searchFile(FindResource.uri(path));
+ var path = "/org/javacs/example/ReferenceConstructor.java";
+ var all = searchFile(FindResource.uri(path));
assertThat("includes explicit constructor", all, hasItem("ReferenceConstructor"));
}
diff --git a/src/test/java/org/javacs/SignatureHelpTest.java b/src/test/java/org/javacs/SignatureHelpTest.java
index 94c2eba..125e6fb 100644
--- a/src/test/java/org/javacs/SignatureHelpTest.java
+++ b/src/test/java/org/javacs/SignatureHelpTest.java
@@ -14,14 +14,14 @@ import org.junit.Test;
public class SignatureHelpTest {
@Test
public void signatureHelp() throws IOException {
- SignatureHelp help = doHelp("/org/javacs/example/SignatureHelp.java", 7, 36);
+ var help = doHelp("/org/javacs/example/SignatureHelp.java", 7, 36);
assertThat(help.getSignatures(), hasSize(2));
}
@Test
public void partlyFilledIn() throws IOException {
- SignatureHelp help = doHelp("/org/javacs/example/SignatureHelp.java", 8, 39);
+ var help = doHelp("/org/javacs/example/SignatureHelp.java", 8, 39);
assertThat(help.getSignatures(), hasSize(2));
assertThat(help.getActiveSignature(), equalTo(1));
@@ -30,7 +30,7 @@ public class SignatureHelpTest {
@Test
public void constructor() throws IOException {
- SignatureHelp help = doHelp("/org/javacs/example/SignatureHelp.java", 9, 27);
+ var help = doHelp("/org/javacs/example/SignatureHelp.java", 9, 27);
assertThat(help.getSignatures(), hasSize(1));
assertThat(help.getSignatures().get(0).getLabel(), startsWith("SignatureHelp"));
@@ -38,7 +38,7 @@ public class SignatureHelpTest {
@Test
public void platformConstructor() throws IOException {
- SignatureHelp help = doHelp("/org/javacs/example/SignatureHelp.java", 10, 26);
+ var help = doHelp("/org/javacs/example/SignatureHelp.java", 10, 26);
assertThat(help.getSignatures(), not(empty()));
assertThat(help.getSignatures().get(0).getLabel(), startsWith("ArrayList"));
@@ -49,16 +49,16 @@ public class SignatureHelpTest {
private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
private SignatureHelp doHelp(String file, int row, int column) throws IOException {
- TextDocumentIdentifier document = new TextDocumentIdentifier();
+ var document = new TextDocumentIdentifier();
document.setUri(FindResource.uri(file).toString());
- Position position = new Position();
+ var position = new Position();
position.setLine(row - 1);
position.setCharacter(column - 1);
- TextDocumentPositionParams p = new TextDocumentPositionParams();
+ var p = new TextDocumentPositionParams();
p.setTextDocument(document);
p.setPosition(position);
diff --git a/src/test/java/org/javacs/SymbolUnderCursorTest.java b/src/test/java/org/javacs/SymbolUnderCursorTest.java
index f01a5c1..97756d0 100644
--- a/src/test/java/org/javacs/SymbolUnderCursorTest.java
+++ b/src/test/java/org/javacs/SymbolUnderCursorTest.java
@@ -85,11 +85,11 @@ public class SymbolUnderCursorTest {
private static final JavaLanguageServer server = LanguageServerFixture.getJavaLanguageServer();
private String symbolAt(String file, int line, int character) {
- TextDocumentPositionParams pos =
+ var pos =
new TextDocumentPositionParams(
new TextDocumentIdentifier(FindResource.uri(file).toString()),
new Position(line - 1, character - 1));
- StringJoiner result = new StringJoiner("\n");
+ var result = new StringJoiner("\n");
try {
server.getTextDocumentService()
.hover(pos)