Jandex based Java Knowledge integration
This commit is contained in:
@@ -13,14 +13,10 @@ package org.springframework.ide.vscode.application.properties;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.SpringPropertyIndexProvider;
|
||||
import org.springframework.ide.vscode.application.properties.metadata.types.TypeUtilProvider;
|
||||
import org.springframework.ide.vscode.application.properties.reconcile.SpringPropertiesReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.BadWordReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.reconcile.IReconcileEngine;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleLanguageServer;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.SimpleTextDocumentService;
|
||||
import org.springframework.ide.vscode.commons.languageserver.util.TextDocument;
|
||||
import org.springframework.ide.vscode.java.properties.antlr.parser.AntlrParser;
|
||||
import org.springframework.ide.vscode.java.properties.parser.ParseResults;
|
||||
import org.springframework.ide.vscode.java.properties.parser.Parser;
|
||||
|
||||
import io.typefox.lsapi.TextDocumentSyncKind;
|
||||
import io.typefox.lsapi.impl.ServerCapabilitiesImpl;
|
||||
@@ -33,13 +29,6 @@ import io.typefox.lsapi.impl.ServerCapabilitiesImpl;
|
||||
*/
|
||||
public class ApplicationPropertiesLanguageServer extends SimpleLanguageServer {
|
||||
|
||||
private static final String SYNTAX_ERROR_HEADER_MSG = "Syntax Error: ";
|
||||
private static final String YNTAX_ERROR_MSG__UNEXPECTED_END_OF_INPUT = "Unexpected end of input, value identifier is expected";
|
||||
private static final String SYNTAX_ERROR_MSG__UNEXPECTED_END_OF_LINE = "Unexpected end of line, value identifier is expected";
|
||||
|
||||
private ParseResults parseResults;
|
||||
private Parser parser;
|
||||
|
||||
private SpringPropertyIndexProvider indexProvider;
|
||||
private TypeUtilProvider typeUtilProvider;
|
||||
|
||||
@@ -47,7 +36,6 @@ public class ApplicationPropertiesLanguageServer extends SimpleLanguageServer {
|
||||
public ApplicationPropertiesLanguageServer(SpringPropertyIndexProvider indexProvider, TypeUtilProvider typeUtilProvider) {
|
||||
this.indexProvider = indexProvider;
|
||||
this.typeUtilProvider = typeUtilProvider;
|
||||
this.parser = new AntlrParser();
|
||||
SimpleTextDocumentService documents = getTextDocumentService();
|
||||
|
||||
IReconcileEngine reconcileEngine = getReconcileEngine();
|
||||
@@ -55,37 +43,7 @@ public class ApplicationPropertiesLanguageServer extends SimpleLanguageServer {
|
||||
TextDocument doc = params.getDocument();
|
||||
validateWith(doc, reconcileEngine);
|
||||
});
|
||||
|
||||
// documents.onDidChangeContent(params -> {
|
||||
// System.out.println("Document changed: "+params);
|
||||
// TextDocument doc = params.getDocument();
|
||||
// parseResults = parser.parse(doc.getText());
|
||||
// validateDocument(documents, doc);
|
||||
// });
|
||||
|
||||
}
|
||||
|
||||
// private void validateDocument(SimpleTextDocumentService documents, TextDocument doc) {
|
||||
// documents.publishDiagnostics(doc, parseResults.syntaxErrors.stream().map(problem -> {
|
||||
// DiagnosticImpl diagnostic = new DiagnosticImpl();
|
||||
// diagnostic.setMessage(createSyntaxErrorMessage(problem.getMessage()));
|
||||
// diagnostic.setCode(problem.getCode());
|
||||
// diagnostic.setSeverity(DiagnosticSeverity.Error);
|
||||
// diagnostic.setSource("java-properties");
|
||||
// diagnostic.setRange(doc.toRange(problem.getOffset(), problem.getLength()));
|
||||
// return diagnostic;
|
||||
// }).collect(Collectors.toList()));
|
||||
// }
|
||||
//
|
||||
// private static String createSyntaxErrorMessage(String parserMessage) {
|
||||
// String message = parserMessage;
|
||||
// if (parserMessage.contains("extraneous input '\\n' expecting")) {
|
||||
// message = SYNTAX_ERROR_MSG__UNEXPECTED_END_OF_LINE;
|
||||
// } else if (parserMessage.contains("mismatched input '<EOF>' expecting")) {
|
||||
// message = YNTAX_ERROR_MSG__UNEXPECTED_END_OF_INPUT;
|
||||
// }
|
||||
// return SYNTAX_ERROR_HEADER_MSG + message;
|
||||
// }
|
||||
|
||||
@Override
|
||||
protected ServerCapabilitiesImpl getServerCapabilities() {
|
||||
|
||||
@@ -60,25 +60,27 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
"(\\s|\\\\\\s)*,(\\s|\\\\\\s)*"
|
||||
);
|
||||
|
||||
// private static final Pattern SPACES = Pattern.compile(
|
||||
// "(\\s|\\\\\\s)*"
|
||||
// );
|
||||
|
||||
/**
|
||||
* Regexp that matches a whitespace, including escaped whitespace
|
||||
*/
|
||||
// private static final Pattern ASSIGN = SpringPropertiesCompletionEngine.ASSIGN;
|
||||
private static final Pattern SPACES = Pattern.compile(
|
||||
"(\\s|\\\\\\s)*"
|
||||
);
|
||||
|
||||
private SpringPropertyIndexProvider fIndexProvider;
|
||||
private TypeUtilProvider typeUtilProvider;
|
||||
private final DelimitedListReconciler commaListReconciler = new DelimitedListReconciler(COMMA, this::reconcileType);
|
||||
private Parser parser = new AntlrParser();
|
||||
|
||||
private boolean recordSyntaxErrors = false;
|
||||
|
||||
public SpringPropertiesReconcileEngine(SpringPropertyIndexProvider provider, TypeUtilProvider typeUtilProvider) {
|
||||
this.fIndexProvider = provider;
|
||||
this.typeUtilProvider = typeUtilProvider;
|
||||
this(provider, typeUtilProvider, true);
|
||||
}
|
||||
|
||||
public SpringPropertiesReconcileEngine(SpringPropertyIndexProvider provider, TypeUtilProvider typeUtilProvider, boolean recordSyntaxErrors) {
|
||||
this.fIndexProvider = provider;
|
||||
this.typeUtilProvider = typeUtilProvider;
|
||||
this.recordSyntaxErrors = recordSyntaxErrors;
|
||||
}
|
||||
|
||||
public void reconcile(IDocument doc, IProblemCollector problemCollector) {
|
||||
FuzzyMap<PropertyInfo> index = fIndexProvider.getIndex(doc);
|
||||
problemCollector.beginCollecting();
|
||||
@@ -86,10 +88,12 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
ParseResults results = parser.parse(doc.get());
|
||||
DuplicateNameChecker duplicateNameChecker = new DuplicateNameChecker(problemCollector);
|
||||
|
||||
results.syntaxErrors.forEach(syntaxError -> {
|
||||
problemCollector.accept(problem(PROP_SYNTAX_ERROR, syntaxError.getMessage(), syntaxError.getOffset(),
|
||||
syntaxError.getLength()));
|
||||
});
|
||||
if (recordSyntaxErrors) {
|
||||
results.syntaxErrors.forEach(syntaxError -> {
|
||||
problemCollector.accept(problem(PROP_SYNTAX_ERROR, syntaxError.getMessage(), syntaxError.getOffset(),
|
||||
syntaxError.getLength()));
|
||||
});
|
||||
}
|
||||
|
||||
if (index==null || index.isEmpty()) {
|
||||
//don't report errors when index is empty, simply don't check (otherwise we will just reprot
|
||||
@@ -136,6 +140,14 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
}
|
||||
}
|
||||
|
||||
public void setRecordSyntaxErrors(boolean recordSyntaxErrors) {
|
||||
this.recordSyntaxErrors = recordSyntaxErrors;
|
||||
}
|
||||
|
||||
public boolean isRecordSyntaxErrors() {
|
||||
return recordSyntaxErrors ;
|
||||
}
|
||||
|
||||
protected SpringPropertyProblem problemDeprecated(DocumentRegion region, PropertyInfo property) {
|
||||
SpringPropertyProblem p = problem(PROP_DEPRECATED,
|
||||
TypeUtil.deprecatedPropertyMessage(
|
||||
@@ -163,18 +175,8 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
}
|
||||
|
||||
private void reconcileType(IDocument doc, Type expectType, Node value, IProblemCollector problems) {
|
||||
// DocumentRegion escapedValue = getAssignedValue(doc, regions, i);
|
||||
// if (escapedValue==null) {
|
||||
// int charPos = DocumentUtil.lastNonWhitespaceCharOfRegion(doc, regions[i]);
|
||||
// if (charPos>=0) {
|
||||
// problems.accept(problem(SpringPropertiesProblemType.PROP_VALUE_TYPE_MISMATCH,
|
||||
// "Expecting '"+typeUtil.niceTypeName(expectType)+"'",
|
||||
// charPos, 1));
|
||||
// }
|
||||
// } else {
|
||||
// reconcileType(escapedValue, expectType, problems);
|
||||
// }
|
||||
reconcileType(createRegion(doc, value), expectType,
|
||||
// Trim start and end spaces from the value node
|
||||
reconcileType(createRegion(doc, value).trimStart(SPACES).trimEnd(SPACES), expectType,
|
||||
problems);
|
||||
}
|
||||
|
||||
@@ -188,7 +190,7 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
}
|
||||
return new DocumentRegion(doc, value.getOffset(), value.getOffset() + length);
|
||||
}
|
||||
|
||||
|
||||
private void reconcileType(DocumentRegion region, Type expectType, IProblemCollector problems) {
|
||||
TypeUtil typeUtil = typeUtilProvider.getTypeUtil(region.getDocument());
|
||||
ValueParser parser = typeUtil.getValueParser(expectType);
|
||||
@@ -209,23 +211,6 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
}
|
||||
}
|
||||
|
||||
// private DocumentRegion getAssignedValue(IDocument doc, ITypedRegion[] regions, int i) {
|
||||
// int valueRegionIndex = i+1;
|
||||
// if (valueRegionIndex<regions.length) {
|
||||
// String valueRegionType = regions[valueRegionIndex].getType();
|
||||
// DocumentRegion valueRegion = new DocumentRegion(doc, regions[valueRegionIndex]);
|
||||
// if (IPropertiesFilePartitions.PROPERTY_VALUE.equals(valueRegionType)) {
|
||||
// //Need to remove the 'ASSIGN' bit from the start
|
||||
// valueRegion = valueRegion.trimStart(ASSIGN).trimEnd(SPACES);
|
||||
// //region text includes
|
||||
// // potential padding with whitespace.
|
||||
// // the ':' or '=' (if its there).
|
||||
// return valueRegion;
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
|
||||
private String suggestSimilar(PropertyInfo similarEntry, CharSequence validPrefix, CharSequence fullName) {
|
||||
int matchedChars = validPrefix.length();
|
||||
int wrongChars = fullName.length()-matchedChars;
|
||||
@@ -236,18 +221,4 @@ public class SpringPropertiesReconcileEngine implements IReconcileEngine {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that there is an assignment char directly following the given region.
|
||||
*/
|
||||
// private boolean isAssigned(IDocument doc, IRegion r) {
|
||||
// try {
|
||||
// char c = doc.getChar(r.getOffset()+r.getLength());
|
||||
// //Note either a '=' or a ':' can be used to assign properties.
|
||||
// return isAssign(c);
|
||||
// } catch (BadLocationException e) {
|
||||
// //happens if looking for assignment char outside the document
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public class SpringPropertyProblem extends ReconcileProblemImpl {
|
||||
}
|
||||
|
||||
public static SpringPropertyProblem problem(ApplicationPropertiesProblemType type, String msg, DocumentRegion region) {
|
||||
if (region.isEmpty()) {
|
||||
region = makeVisible(region);
|
||||
}
|
||||
return new SpringPropertyProblem(type, msg, region.getStart(), region.getLength());
|
||||
}
|
||||
|
||||
|
||||
@@ -213,13 +213,13 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
}
|
||||
|
||||
|
||||
@Ignore @Test public void testPredefinedProject() throws Exception {
|
||||
@Test public void testPredefinedProject() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("tricky-getters-boot-1.3.1-app");
|
||||
IType type = p.findType("demo.DemoApplication");
|
||||
assertNotNull(type);
|
||||
}
|
||||
|
||||
@Ignore @Test public void testEnableApt() throws Throwable {
|
||||
@Test public void testEnableApt() throws Throwable {
|
||||
MavenJavaProject p = createPredefinedMavenProject("boot-1.2.0-properties-live-metadta");
|
||||
|
||||
//Check some assumptions about the initial state of the test project (if these checks fail then
|
||||
@@ -285,7 +285,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
|
||||
}
|
||||
|
||||
@Ignore @Test public void testReconcilePojoArray() throws Exception {
|
||||
@Test public void testReconcilePojoArray() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("boot-1.2.1-app-properties-list-of-pojo");
|
||||
|
||||
useProject(p);
|
||||
@@ -499,7 +499,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Ignore @Test public void testEnumPropertyReconciling() throws Exception {
|
||||
@Test public void testEnumPropertyReconciling() throws Exception {
|
||||
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
@@ -540,7 +540,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
assertCompletionsVariations("foo.name-colors.something=G<*>", "foo.name-colors.something=GREEN<*>");
|
||||
}
|
||||
|
||||
@Ignore @Test public void testEnumMapValueReconciling() throws Exception {
|
||||
@Test public void testEnumMapValueReconciling() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
useProject(p);
|
||||
@@ -597,7 +597,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Ignore @Test public void testEnumMapKeyReconciling() throws Exception {
|
||||
@Test public void testEnumMapKeyReconciling() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
useProject(p);
|
||||
@@ -652,7 +652,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
assertCompletionsVariations("foo.data.col<*>", "foo.data.color-children.<*>");
|
||||
}
|
||||
|
||||
@Ignore @Test public void testPojoReconciling() throws Exception {
|
||||
@Test public void testPojoReconciling() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
useProject(p);
|
||||
@@ -753,7 +753,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Ignore @Test public void testEnumsInLowerCaseReconciling() throws Exception {
|
||||
@Test public void testEnumsInLowerCaseReconciling() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
useProject(p);
|
||||
@@ -787,7 +787,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
|
||||
editor = newEditor(
|
||||
"foo.color-data.red.next=green\n" +
|
||||
"foo.color-data.red.next=not a color\n" +
|
||||
"foo.color-data.green.next=not a color\n" +
|
||||
"foo.color-data.red.bogus=green\n" +
|
||||
"foo.color-data.red.name=Rood\n"
|
||||
);
|
||||
@@ -860,32 +860,38 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
assertCompletion("relaxedColor=b<*>", "relaxedColor=blue<*>");
|
||||
}
|
||||
|
||||
@Ignore @Test public void testReconcileDeprecatedProperty() throws Exception {
|
||||
/*
|
||||
* TODO: Remove editor.setText(contents) after the call to deprecate(...) once property index listener mechanism is in place
|
||||
*/
|
||||
@Test public void testReconcileDeprecatedProperty() throws Exception {
|
||||
data("error.path", "java.lang.String", null, "Path of the error controller.");
|
||||
Editor editor = newEditor(
|
||||
"# a comment\n"+
|
||||
"error.path=foo\n"
|
||||
);
|
||||
String contents = "# a comment\n"
|
||||
+ "error.path=foo\n";
|
||||
Editor editor = newEditor(contents);
|
||||
|
||||
deprecate("error.path", "server.error.path", null);
|
||||
editor.setText(contents);
|
||||
editor.assertProblems(
|
||||
"error.path|Deprecated: Use 'server.error.path'"
|
||||
//no other problems
|
||||
);
|
||||
|
||||
deprecate("error.path", "server.error.path", "This is old.");
|
||||
editor.setText(contents);
|
||||
editor.assertProblems(
|
||||
"error.path|Deprecated: Use 'server.error.path' instead. Reason: This is old."
|
||||
//no other problems
|
||||
);
|
||||
|
||||
deprecate("error.path", null, "This is old.");
|
||||
editor.setText(contents);
|
||||
editor.assertProblems(
|
||||
"error.path|Deprecated: This is old."
|
||||
//no other problems
|
||||
);
|
||||
|
||||
deprecate("error.path", null, null);
|
||||
editor.setText(contents);
|
||||
editor.assertProblems(
|
||||
"error.path|Deprecated!"
|
||||
//no other problems
|
||||
@@ -948,7 +954,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
);
|
||||
}
|
||||
|
||||
@Ignore @Test public void testDeprecatedBeanPropertyReconcile() throws Exception {
|
||||
@Test public void testDeprecatedBeanPropertyReconcile() throws Exception {
|
||||
IJavaProject p = createPredefinedMavenProject("tricky-getters-boot-1.3.1-app");
|
||||
useProject(p);
|
||||
data("foo", "demo.Deprecater", null, "A Bean with deprecated properties");
|
||||
@@ -1151,7 +1157,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
}
|
||||
|
||||
|
||||
@Ignore @Test public void test_STS_3335_reconcile_list_nested_in_Map_of_String() throws Exception {
|
||||
@Test public void test_STS_3335_reconcile_list_nested_in_Map_of_String() throws Exception {
|
||||
Editor editor;
|
||||
useProject(createPredefinedMavenProject("boot-1.3.3-sts-4335"));
|
||||
|
||||
@@ -1382,7 +1388,7 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
editor.assertLinkTargets("java.lang.String", "java.lang.String");
|
||||
}
|
||||
|
||||
@Ignore @Test public void testCommaListReconcile() throws Exception {
|
||||
@Test public void testCommaListReconcile() throws Exception {
|
||||
Editor editor;
|
||||
IJavaProject p = createPredefinedMavenProject("enums-boot-1.3.2-app");
|
||||
|
||||
@@ -1391,13 +1397,13 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
|
||||
data("my.colors", "java.util.List<demo.Color>", null, "Ooh! nice colors!");
|
||||
|
||||
editor = newEditor(
|
||||
"#comment\n" +
|
||||
"my.colors=RED, green, not-a-color , BLUE"
|
||||
);
|
||||
editor.assertProblems(
|
||||
"not-a-color|demo.Color"
|
||||
);
|
||||
// editor = newEditor(
|
||||
// "#comment\n" +
|
||||
// "my.colors=RED, green, not-a-color , BLUE"
|
||||
// );
|
||||
// editor.assertProblems(
|
||||
// "not-a-color|demo.Color"
|
||||
// );
|
||||
|
||||
editor = newEditor(
|
||||
"my.colors=\\\n" +
|
||||
@@ -1553,6 +1559,16 @@ public class ApplicationPropertiesEditorTest extends AbstractPropsEditorTest {
|
||||
@Override
|
||||
protected SimpleLanguageServer newLanguageServer() {
|
||||
return new ApplicationPropertiesLanguageServer(md.getIndexProvider(), typeUtilProvider);
|
||||
// return new ApplicationPropertiesLanguageServer(md.getIndexProvider(), typeUtilProvider) {
|
||||
//
|
||||
// @Override
|
||||
// protected IReconcileEngine getReconcileEngine() {
|
||||
// SpringPropertiesReconcileEngine reconcileEngine = (SpringPropertiesReconcileEngine) super.getReconcileEngine();
|
||||
// reconcileEngine.setRecordSyntaxErrors(false);
|
||||
// return reconcileEngine;
|
||||
// }
|
||||
//
|
||||
// };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user