X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.ui%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fui%2Feditor%2Fcompletion%2FSCLCompletionAssistProcessor.java;h=c02946c7bf7e829eaa6d05db6a3ab31ab8676246;hb=refs%2Fchanges%2F84%2F2484%2F12;hp=8d9a56b8555e390c6fc64754c7ef23ba00f70256;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionAssistProcessor.java b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionAssistProcessor.java index 8d9a56b85..c02946c7b 100644 --- a/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionAssistProcessor.java +++ b/bundles/org.simantics.scl.ui/src/org/simantics/scl/ui/editor/completion/SCLCompletionAssistProcessor.java @@ -1,79 +1,79 @@ -package org.simantics.scl.ui.editor.completion; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.ITextViewer; -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 SCLCompletionAssistProcessor implements IContentAssistProcessor { - -// private String lastPrefix = null; - private String lastError = ""; - private SCLTextEditorEnvironment sclTextEditorEnvironment; - - public SCLCompletionAssistProcessor(SCLTextEditorEnvironment sclTextEditorEnvironment) { - this.sclTextEditorEnvironment = sclTextEditorEnvironment; - } - - @Override - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) { - ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); - // adjust offset to end of normalized selection - if (selection.getOffset() == tmpOffset) - tmpOffset = selection.getOffset() + selection.getLength(); - final int offset = tmpOffset; - IDocument document = viewer.getDocument(); - String tmpPrefix = ""; - try { - tmpPrefix = getPrefix(document, offset); - } catch (BadLocationException e) { - e.printStackTrace(); - } - sclTextEditorEnvironment.updateEnvironment(document); - return sclTextEditorEnvironment.getCompletionProposals(tmpPrefix, offset); - } - - private static String getPrefix(IDocument doc, int offset) throws BadLocationException { - int docLen = doc.getLength(); - if (doc == null || offset > docLen || docLen == 0) - return ""; - - int length= 0; - while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.') - length++; - - return doc.get(offset + 1, length); - } - - @Override - public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { - return null; - } - - private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' }; - - @Override - public char[] getCompletionProposalAutoActivationCharacters() { - return AUTO_ACTIVATION_CHARS; - } - - @Override - public char[] getContextInformationAutoActivationCharacters() { - return null; - } - - @Override - public String getErrorMessage() { - return lastError; - } - - @Override - public IContextInformationValidator getContextInformationValidator() { - return null; - } - -} +package org.simantics.scl.ui.editor.completion; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITextViewer; +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 SCLCompletionAssistProcessor implements IContentAssistProcessor { + +// private String lastPrefix = null; + private String lastError = ""; //$NON-NLS-1$ + private SCLTextEditorEnvironment sclTextEditorEnvironment; + + public SCLCompletionAssistProcessor(SCLTextEditorEnvironment sclTextEditorEnvironment) { + this.sclTextEditorEnvironment = sclTextEditorEnvironment; + } + + @Override + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) { + ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); + // adjust offset to end of normalized selection + if (selection.getOffset() == tmpOffset) + tmpOffset = selection.getOffset() + selection.getLength(); + final int offset = tmpOffset; + IDocument document = viewer.getDocument(); + String tmpPrefix = ""; //$NON-NLS-1$ + try { + tmpPrefix = getPrefix(document, offset); + } catch (BadLocationException e) { + e.printStackTrace(); + } + sclTextEditorEnvironment.updateEnvironment(document); + return sclTextEditorEnvironment.getCompletionProposals(tmpPrefix, offset); + } + + private static String getPrefix(IDocument doc, int offset) throws BadLocationException { + int docLen = doc.getLength(); + if (doc == null || offset > docLen || docLen == 0) + return ""; //$NON-NLS-1$ + + int length= 0; + while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.') + length++; + + return doc.get(offset + 1, length); + } + + @Override + public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { + return null; + } + + private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' }; + + @Override + public char[] getCompletionProposalAutoActivationCharacters() { + return AUTO_ACTIVATION_CHARS; + } + + @Override + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + @Override + public String getErrorMessage() { + return lastError; + } + + @Override + public IContextInformationValidator getContextInformationValidator() { + return null; + } + +}