From dd6d5de33c322f0619fc54b50e5f3b96644c3345 Mon Sep 17 00:00:00 2001 From: Michael Uhl Date: Tue, 25 Dec 2018 15:25:51 +0100 Subject: [PATCH] Line number and identifier for autocomlpete are evaluated correctly now. --- .../editor/JafCompletionProcess.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java index a702d05..98fa6e9 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java @@ -43,10 +43,15 @@ public class JafCompletionProcess implements IContentAssistProcessor { String indent = lastIndent(doc, offset); ArrayList result = new ArrayList<>(); + /* for (String ti : editor.resolveTypeInserts()) { String proposal = ti; result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length())); } + */ + + String proposal = "Line '" + evaluateLineNumber(doc, offset) + "' identifer '" + lastWord(doc, offset) + "'."; + result.add(new CompletionProposal(proposal, offset - prefix.length(), prefix.length(), proposal.length())); return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]); } @@ -62,6 +67,7 @@ public class JafCompletionProcess implements IContentAssistProcessor { } private String lastWord(IDocument doc, int offset) { + offset--; try { for (int n = offset - 1; n >= 0; n--) { char c = doc.getChar(n); @@ -74,6 +80,20 @@ public class JafCompletionProcess implements IContentAssistProcessor { return ""; } + private int evaluateLineNumber(IDocument doc, int offset) { + int lineNbr = 1; + for (int i = offset; i > 0; i--) { + try { + if (doc.getChar(i) == '\n') { + lineNbr++; + } + } catch (BadLocationException e) { + LOG.log(new Status(ERROR, PLUGIN_ID, e.getMessage(), e)); + } + } + return lineNbr; + } + private char lastChar(IDocument doc, int offset) { try { return doc.getChar(offset -1);