diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/.gitignore b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/.gitignore index 73d3b56..6ad7fde 100644 --- a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/.gitignore +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/.gitignore @@ -2,3 +2,4 @@ /.settings/ /bin/ *.iml +/lib/ diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/JavaCompilerPlugin.Plugin/.gitignore b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/JavaCompilerPlugin.Plugin/.gitignore new file mode 100644 index 0000000..12c18d4 --- /dev/null +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/JavaCompilerPlugin.Plugin/.gitignore @@ -0,0 +1 @@ +/lib/ diff --git a/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java new file mode 100644 index 0000000..5420ba4 --- /dev/null +++ b/JavaCompilerPlugin/bundles/JavaCompilerPlugin.Plugin/src/typinferenzplugin/editor/JafCompletionProcess.java @@ -0,0 +1,89 @@ +package typinferenzplugin.editor; + +import java.util.ArrayList; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.contentassist.CompletionProposal; +import org.eclipse.jface.text.contentassist.ICompletionProposal; +import org.eclipse.jface.text.contentassist.IContentAssistProcessor; +import org.eclipse.jface.text.contentassist.IContextInformation; +import org.eclipse.jface.text.contentassist.IContextInformationValidator; + +public class JafCompletionProcess implements IContentAssistProcessor { + private final IContextInformation[] NO_CONTEXTS = {}; + private final char[] PROPOSAL_ACTIVATION_CHARS = { 's', 'f', 'p', 'n', 'm', }; + private ICompletionProposal[] NO_COMPLETIONS = {}; + + @Override + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { + try { + IDocument document = viewer.getDocument(); + ArrayList result = new ArrayList<>(); + String prefix = lastWord(document, offset); + String indent = lastIndent(document, offset); + + result.add(new CompletionProposal("replace", offset - prefix.length(), prefix.length(), "replace".length())); + + return (ICompletionProposal[]) result.toArray(new ICompletionProposal[result.size()]); + } catch (Exception e) { + // ... log the exception ... + return NO_COMPLETIONS; + } + } + + private String lastWord(IDocument doc, int offset) { + try { + for (int n = offset - 1; n >= 0; n--) { + char c = doc.getChar(n); + if (!Character.isJavaIdentifierPart(c)) + return doc.get(n + 1, offset - n - 1); + } + } catch (BadLocationException e) { + // ... log the exception ... + } + return ""; + } + + private String lastIndent(IDocument doc, int offset) { + try { + int start = offset - 1; + while (start >= 0 && doc.getChar(start) != '\n') + start--; + int end = start; + while (end > offset && Character.isSpaceChar(doc.getChar(end))) + end++; + return doc.get(start + 1, end - start - 1); + } catch (BadLocationException e) { + e.printStackTrace(); + } + return ""; + } + + @Override + public IContextInformation[] computeContextInformation(ITextViewer arg0, int arg1) { + return NO_CONTEXTS; + } + + @Override + public char[] getCompletionProposalAutoActivationCharacters() { + return PROPOSAL_ACTIVATION_CHARS; + } + + @Override + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + @Override + public IContextInformationValidator getContextInformationValidator() { + return null; + } + + @Override + public String getErrorMessage() { + return null; + } + +} diff --git a/JavaCompilerPlugin/bundles/pom.xml b/JavaCompilerPlugin/bundles/pom.xml index 7dd904b..8fd0b42 100644 --- a/JavaCompilerPlugin/bundles/pom.xml +++ b/JavaCompilerPlugin/bundles/pom.xml @@ -14,4 +14,25 @@ JavaCompilerPlugin.Plugin + + + + + maven-dependency-plugin + + + install + + copy-dependencies + + + ${project.basedir}/JavaCompilerPlugin.Plugin/lib + true + true + + + + + + \ No newline at end of file diff --git a/JavaCompilerPlugin/releng/JavaCompilerPlugin.Configuration/pom.xml b/JavaCompilerPlugin/releng/JavaCompilerPlugin.Configuration/pom.xml index 18dec15..81a28bd 100644 --- a/JavaCompilerPlugin/releng/JavaCompilerPlugin.Configuration/pom.xml +++ b/JavaCompilerPlugin/releng/JavaCompilerPlugin.Configuration/pom.xml @@ -63,21 +63,7 @@ - - maven-dependency-plugin - - - install - - copy-dependencies - - - ${project.basedir}/bundles/JavaCompilerPlugin.Plugin/lib - true - - - - + org.eclipse.tycho