diff --git a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java index 12741c44a7..3079f0bbb8 100644 --- a/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java +++ b/headless-services/commons/language-server-test-harness/src/main/java/org/springframework/ide/vscode/languageserver/testharness/Editor.java @@ -71,8 +71,8 @@ public class Editor { public static final Predicate RELAXED_COMPLETION = c -> c.getLabel().startsWith("- ") - || c.getLabel().startsWith(Unicodes.LEFT_ARROW+" ") - || c.getLabel().startsWith(Unicodes.RIGHT_ARROW+" ") + || c.getLabel().startsWith(Unicodes.LEFT_ARROW + " ") + || c.getLabel().startsWith(Unicodes.RIGHT_ARROW + " ") ; public static final Predicate SNIPPET_COMPLETION = c -> c.getLabel().endsWith("Snippet"); public static final Predicate PLAIN_COMPLETION = RELAXED_COMPLETION.negate(); @@ -86,11 +86,11 @@ static class EditorState { public EditorState(String text) { selectionStart = text.indexOf(CURSOR); - if (selectionStart>=0) { - text = text.substring(0,selectionStart) + text.substring(selectionStart+CURSOR.length()); + if (selectionStart >= 0) { + text = text.substring(0,selectionStart) + text.substring(selectionStart + CURSOR.length()); selectionEnd = text.indexOf(CURSOR, selectionStart); - if (selectionEnd>=0) { - text = text.substring(0, selectionEnd) + text.substring(selectionEnd+CURSOR.length()); + if (selectionEnd >= 0) { + text = text.substring(0, selectionEnd) + text.substring(selectionEnd + CURSOR.length()); } else { selectionEnd = selectionStart; } @@ -110,15 +110,15 @@ public EditorState(String text) { @Override public int compare(Diagnostic o1, Diagnostic o2) { int diff = compare(o1.getRange().getStart(), o2.getRange().getStart()); - if (diff!=0) return diff; + if (diff != 0) return diff; diff = compare(o1.getRange().getEnd(), o2.getRange().getEnd()); - if (diff!=0) return diff; + if (diff != 0) return diff; return o1.getMessage().compareTo(o2.getMessage()); } private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); - if (d!=0) return d; + if (d != 0) return d; return p1.getCharacter() - p2.getCharacter(); } }; @@ -126,12 +126,12 @@ private int compare(Position p1, Position p2) { @Override public int compare(Range o1, Range o2) { int diff = compare(o1.getStart(), o2.getStart()); - if (diff!=0) return diff; + if (diff != 0) return diff; return compare(o1.getEnd(), o2.getEnd()); } private int compare(Position p1, Position p2) { int d = p1.getLine() - p2.getLine(); - if (d!=0) return d; + if (d != 0) return d; return p1.getCharacter() - p2.getCharacter(); } }; @@ -202,18 +202,18 @@ public List assertProblems(String... expectedProblems) throws Except }).collect(Collectors.toList())); Collections.sort(actualProblems, PROBLEM_COMPARATOR); String bad = null; - if (actualProblems.size()!=expectedProblems.length) { + if (actualProblems.size() != expectedProblems.length) { bad = "Wrong number of problems (expecting "+expectedProblems.length+" but found "+actualProblems.size()+")"; } else { for (int i = 0; i < expectedProblems.length; i++) { if (!matchProblem(actualProblems.get(i), expectedProblems[i])) { - bad = "First mismatch at index "+i+": "+expectedProblems[i]+"\n"; + bad = "First mismatch at index "+i+": " + expectedProblems[i] + "\n"; break; } } } if (bad!=null) { - fail(bad+problemSumary(editor, actualProblems)); + fail(bad + problemSumary(editor, actualProblems)); } return ImmutableList.copyOf(actualProblems); } @@ -224,8 +224,8 @@ private String problemSumary(Editor editor, List actualProblems) thr buf.append("\n----------------------\n"); String snippet = editor.getText(p.getRange()); - buf.append("("+p.getRange().getStart().getLine()+", "+p.getRange().getStart().getCharacter()+")["+snippet+"]:\n"); - buf.append(" "+p.getMessage()); + buf.append("(" + p.getRange().getStart().getLine() + ", " + p.getRange().getStart().getCharacter() + ")[" + snippet + "]:\n"); + buf.append(" " + p.getMessage()); } return buf.toString(); } @@ -244,7 +244,7 @@ public List assertHighlights(String... expectedHighlights) throws Excepti public void assertDocumentHighlights(String afterString, DocumentHighlight... expected) throws Exception { int pos = getRawText().indexOf(afterString); - if (pos>=0) { + if (pos >= 0) { pos += afterString.length(); } List actual = harness.getDocumentHighlights(doc.getId(), doc.toPosition(pos)); @@ -264,7 +264,7 @@ public void assertDocumentHighlights(String afterString, DocumentHighlight... ex public String getText() { String text = doc.getText(); text = text.substring(0, selectionEnd) + CURSOR + text.substring(selectionEnd); - if (selectionStart reconcile() throws Exception { PublishDiagnosticsParams diagnostics = harness.getDiagnostics(doc); - if (diagnostics!=null) { + if (diagnostics != null) { return diagnostics.getDiagnostics(); } return Collections.emptyList(); @@ -428,7 +428,7 @@ public void assertNoCompletionsWithLabel(Predicate labelPredicate) throw .filter(labelPredicate) .collect(Collectors.toList()); if (!found.isEmpty()) { - fail("Found but not expected: "+found); + fail("Found but not expected: " + found); } } @@ -520,7 +520,7 @@ public void apply(CompletionItem completion) throws Exception { insertPosition = selectionStart; insertLength = insertText.length(); - selectionStart+= insertText.length(); + selectionStart += insertText.length(); selectionEnd += insertText.length(); setRawText(newText); } @@ -554,7 +554,7 @@ public void apply(CompletionItem completion) throws Exception { private String getInsertText(CompletionItem completion) { String s = completion.getInsertText(); - if (s==null) { + if (s == null) { //If no insertText is provided the label is used s = completion.getLabel(); } @@ -650,7 +650,7 @@ public String hoverString(Hover hover) { buf.append(s); } else if (block.isRight()) { MarkedString ms = block.getRight(); - buf.append("```"+ms.getLanguage()+"\n"); + buf.append("```" + ms.getLanguage() + "\n"); buf.append(ms.getValue()); buf.append("\n```"); } @@ -663,10 +663,10 @@ public String hoverString(Hover hover) { } private int getHoverPosition(String hoverOver, int occurrence) throws Exception { - assertTrue(occurrence>0); + assertTrue(occurrence > 0); return occurrences(getRawText(), hoverOver) .elementAt(occurrence-1) - .map(offset -> offset + hoverOver.length()/2) + .map(offset -> offset + hoverOver.length() / 2) .block(); } @@ -681,7 +681,7 @@ public boolean hasNext() { @Override public Integer next() { int found = text.indexOf(substring, searchFrom); - assertTrue(found>=0); + assertTrue(found >= 0); searchFrom = found+1; return found; } @@ -732,7 +732,7 @@ public void assertNoHover(String hoverOver) throws Exception { */ public void assertHoverText(String afterString, String expectSnippet) throws Exception { int pos = getRawText().indexOf(afterString); - if (pos>=0) { + if (pos >= 0) { pos += afterString.length(); } Hover hover = harness.getHover(doc, doc.toPosition(pos)); @@ -746,7 +746,7 @@ public void assertHoverText(String afterString, String expectSnippet) throws Exc */ public void assertHoverExactText(String afterString, String expectedHover) throws Exception { int pos = getRawText().indexOf(afterString); - if (pos>=0) { + if (pos >= 0) { pos += afterString.length(); } Hover hover = harness.getHover(doc, doc.toPosition(pos)); @@ -755,7 +755,7 @@ public void assertHoverExactText(String afterString, String expectedHover) throw public Hover getHover(String afterString) throws Exception { int pos = getRawText().indexOf(afterString); - if (pos>=0) { + if (pos >= 0) { pos += afterString.length(); } return harness.getHover(doc, doc.toPosition(pos)); @@ -763,10 +763,10 @@ public Hover getHover(String afterString) throws Exception { public CompletionItem assertCompletionDetails(String expectLabel, String expectDetail, String expectDocSnippet) throws Exception { CompletionItem it = harness.resolveCompletionItem(assertCompletionWithLabel(expectLabel)); - if (expectDetail!=null) { + if (expectDetail != null) { assertEquals(expectDetail, it.getDetail()); } - if (expectDocSnippet!=null) { + if (expectDocSnippet != null) { assertContains(expectDocSnippet, getDocString(it)); } return it; @@ -774,10 +774,10 @@ public CompletionItem assertCompletionDetails(String expectLabel, String expectD public CompletionItem assertCompletionDetailsWithDeprecation(String expectLabel, String expectDetail, String expectDocSnippet, boolean deprecated) throws Exception { CompletionItem it = harness.resolveCompletionItem(assertCompletionWithLabel(expectLabel)); - if (expectDetail!=null) { + if (expectDetail != null) { assertEquals(expectDetail, it.getDetail()); } - if (expectDocSnippet!=null) { + if (expectDocSnippet != null) { assertContains(expectDocSnippet, getDocString(it)); } @SuppressWarnings("deprecation") @@ -794,7 +794,7 @@ protected CompletionItem assertCompletionWithLabel(Predicate expectLabel if (completion.isPresent()) { return completion.get(); } - fail("Not found in "+ completions.stream().map(c -> c.getLabel()).collect(Collectors.toList())); + fail("Not found in " + completions.stream().map(c -> c.getLabel()).collect(Collectors.toList())); return null; //unreachable but compiler doesn't know. } @@ -806,7 +806,7 @@ protected CompletionItem assertCompletionWithLabel(String expectLabel) throws Ex if (completion.isPresent()) { return completion.get(); } - fail("Not found '"+expectLabel+"' in "+ completions.stream().map(c -> c.getLabel()).collect(Collectors.toList())); + fail("Not found '" + expectLabel + "' in " + completions.stream().map(c -> c.getLabel()).collect(Collectors.toList())); return null; //unreachable but compiler doesn't know. } @@ -828,21 +828,21 @@ public CompletionItem assertCompletionWithLabel(Predicate expectLabel, S } public void setSelection(int start, int end) { - assertTrue(start>=0); - assertTrue(end>=start); - assertTrue(end<=doc.getText().length()); + assertTrue(start >= 0); + assertTrue(end >= start); + assertTrue(end <= doc.getText().length()); this.selectionStart = start; this.selectionEnd = end; } @Override public String toString() { - return "Editor(\n"+getText()+"\n)"; + return "Editor(\n" + getText() + "\n)"; } public void assertLinkTargets(String hoverOver, Collection expectedLocations) throws Exception { int pos = getRawText().indexOf(hoverOver); - if (pos>=0) { + if (pos >= 0) { pos += hoverOver.length() / 2; } assertTrue(pos>=0, "Not found in editor: '"+hoverOver+"'"); @@ -859,10 +859,10 @@ public void assertLinkTargets(Position pos, Collection expectedLoc public void assertNoLinkTargets(String hoverOver) throws Exception { int pos = getRawText().indexOf(hoverOver); - if (pos>=0) { + if (pos >= 0) { pos += hoverOver.length() / 2; } - assertTrue(pos>=0, "Not found in editor: '"+hoverOver+"'"); + assertTrue(pos >= 0, "Not found in editor: '" + hoverOver + "'"); DefinitionParams params = new DefinitionParams(new TextDocumentIdentifier(getUri()), doc.toPosition(pos)); List definitions = harness.getDefinitions(params); @@ -901,7 +901,7 @@ public Diagnostic assertProblem(String coveredText) throws Exception { return p; } } - fail("No problem found covering the text '"+coveredText+"' in: \n" + fail("No problem found covering the text '" + coveredText + "' in: \n" + problemSumary(editor, problems) ); return null; //unreachable but compiler doesn't know @@ -917,11 +917,11 @@ public List assertQuickfixes(Diagnostic problem, String... expectedL List actions = getCodeActions(problem); StringBuilder expecteds = new StringBuilder(); for (String l : expectedLabels) { - expecteds.append(l+"\n"); + expecteds.append(l + "\n"); } StringBuilder actuals = new StringBuilder(); for (CodeAction a : actions) { - actuals.append(a.getLabel()+"\n"); + actuals.append(a.getLabel() + "\n"); } assertEquals(expecteds.toString(), actuals.toString()); return actions; @@ -954,7 +954,7 @@ public void assertGotoDefinition(Position pos, Range expectedTarget, Range highl */ public Position positionOf(String longSnippet, String focusSnippet) throws Exception { Range r = rangeOf(longSnippet, focusSnippet); - return r==null?null:r.getStart(); + return r == null ? null : r.getStart(); } public Position positionOf(String snippet) throws Exception { @@ -977,8 +977,8 @@ public Range rangeOf(String focusSnippet) throws Exception { public Range rangeOf(String longSnippet, String focusSnippet) throws Exception { int relativeOffset = longSnippet.indexOf(focusSnippet); int contextStart = getRawText().indexOf(longSnippet); - assertTrue(contextStart>=0, "'"+longSnippet+"' not found in editor"); - int start = contextStart+relativeOffset; + assertTrue(contextStart >= 0, "'" + longSnippet + "' not found in editor"); + int start = contextStart + relativeOffset; return new Range(doc.toPosition(start), doc.toPosition(start+focusSnippet.length())); } @@ -991,10 +991,10 @@ public List getCodeActions(Diagnostic problem) throws Exception { } public List getCodeActions(String overStr, int occurrence) throws Exception { - assertTrue(occurrence>0); + assertTrue(occurrence > 0); int offset = occurrences(getRawText(), overStr) - .elementAt(occurrence-1) - .map(o -> o + overStr.length()/2) + .elementAt(occurrence - 1) + .map(o -> o + overStr.length() / 2) .block(); Position position = doc.toPosition(offset); return harness.getCodeActions(doc, new Range(position, position)); @@ -1008,10 +1008,10 @@ public CodeAction assertCodeAction(Diagnostic problem) throws Exception { public void assertNoCodeAction(Diagnostic problem) throws Exception { List actions = getCodeActions(problem); - if (actions!=null && !actions.isEmpty()) { + if (actions != null && !actions.isEmpty()) { StringBuilder found = new StringBuilder(); for (CodeAction codeAction : actions) { - found.append("\n"+codeAction.getLabel()); + found.append("\n" + codeAction.getLabel()); } fail("Expected no code actions but found:"+found); } @@ -1030,7 +1030,7 @@ public void assertDocumentSymbols(String... symbolsAndContainers) throws Excepti Arrays.sort(symbolsAndContainers); StringBuilder expected = new StringBuilder(); for (String string : symbolsAndContainers) { - expected.append(string+"\n"); + expected.append(string + "\n"); } List actualSymbols = getDocumentSymbols(); @@ -1044,7 +1044,7 @@ public void assertDocumentSymbols(String... symbolsAndContainers) throws Excepti Collections.sort(actuals); StringBuilder actual = new StringBuilder(); for (String string : actuals) { - actual.append(string+"\n"); + actual.append(string + "\n"); } assertEquals(expected.toString(), actual.toString()); } @@ -1072,9 +1072,9 @@ private void dumpSymbol(DocumentSymbol s, int indent, StringBuilder symbolDump) symbolDump.append("\n"); assertEquals(s.getName(), getText(s.getSelectionRange())); - assertNestedRange("Invalid selection range for "+s.getName(), s.getRange(), s.getSelectionRange()); + assertNestedRange("Invalid selection range for " + s.getName(), s.getRange(), s.getSelectionRange()); List children = s.getChildren(); - if (children!=null) { + if (children != null) { dumpSymbols(children, indent+1, symbolDump); } } @@ -1086,15 +1086,15 @@ private void assertNestedRange(String msg, Range outerRange, Range innerRange) { //it's fine! } else { fail(msg + "\n" + - "outer: '"+this.getText(outerRange)+"'\n" + + "outer: '" + this.getText(outerRange)+"'\n" + "does not contain\n" + - "inner: '"+this.getText(innerRange)+"'" + "inner: '" + this.getText(innerRange) + "'" ); } } private static int compare(Position p1, Position p2) { - if (p1.getLine()==p2.getLine()) { + if (p1.getLine() == p2.getLine()) { return p1.getCharacter() - p2.getCharacter(); } else { return p1.getLine() - p2.getLine();