summaryrefslogtreecommitdiff
path: root/src/main/java/org/javacs/JavaLanguageServer.java
diff options
context:
space:
mode:
authorGeorge Fraser <george@fivetran.com>2018-12-31 16:05:09 -0800
committerGeorge Fraser <george@fivetran.com>2018-12-31 16:05:09 -0800
commit25c67bb8f300f8af13b7312933dec157e67e678c (patch)
tree4eb2076b4da8571fe59338c7185b6aa63963e467 /src/main/java/org/javacs/JavaLanguageServer.java
parent8f63f14f980f44af2c5747747320703819ebc402 (diff)
downloadjava-language-server-25c67bb8f300f8af13b7312933dec157e67e678c.zip
Add @Override
Diffstat (limited to 'src/main/java/org/javacs/JavaLanguageServer.java')
-rw-r--r--src/main/java/org/javacs/JavaLanguageServer.java28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/main/java/org/javacs/JavaLanguageServer.java b/src/main/java/org/javacs/JavaLanguageServer.java
index 30b869a..7bfa3a5 100644
--- a/src/main/java/org/javacs/JavaLanguageServer.java
+++ b/src/main/java/org/javacs/JavaLanguageServer.java
@@ -1016,6 +1016,14 @@ class JavaLanguageServer extends LanguageServer {
@Override
public List<TextEdit> formatting(DocumentFormattingParams params) {
updateHoverCache(params.textDocument.uri, contents(params.textDocument.uri).content);
+
+ var edits = new ArrayList<TextEdit>();
+ edits.addAll(fixImports());
+ edits.addAll(addOverrides());
+ return edits;
+ }
+
+ private List<TextEdit> fixImports() {
// TODO if imports already match fixed-imports, return empty list
// TODO preserve comments and other details of existing imports
var imports = hoverCache.fixImports();
@@ -1063,6 +1071,26 @@ class JavaLanguageServer extends LanguageServer {
return edits;
}
+ private List<TextEdit> addOverrides() {
+ var edits = new ArrayList<TextEdit>();
+ var methods = hoverCache.needsOverrideAnnotation();
+ var pos = hoverCache.sourcePositions();
+ var lines = hoverCache.root.getLineMap();
+ for (var t : methods) {
+ var methodStart = pos.getStartPosition(t.getCompilationUnit(), t.getLeaf());
+ var insertLine = lines.getLineNumber(methodStart);
+ var indent = methodStart - lines.getPosition(insertLine, 0);
+ var insertText = new StringBuilder();
+ for (var i = 0; i < indent; i++) insertText.append(' ');
+ insertText.append("@Override");
+ insertText.append('\n');
+ var insertPosition = new Position((int) insertLine, 0);
+ var insert = new TextEdit(new Range(insertPosition, insertPosition), insertText.toString());
+ edits.add(insert);
+ }
+ return edits;
+ }
+
@Override
public List<FoldingRange> foldingRange(FoldingRangeParams params) {
updateCachedParse(params.textDocument.uri);