Search in sources :

Example 6 with JavaContentAssistInvocationContext

use of org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext in project tdi-studio-se by Talend.

the class TalendJavaCompletionProcessor method createContext.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor#createContext(org.eclipse.jface.text.ITextViewer,
     * int)
     */
@Override
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
    if (viewer instanceof TalendJavaSourceViewer) {
        ((TalendJavaSourceViewer) viewer).updateContents();
        ICompilationUnit compilationUnit = ((TalendJavaSourceViewer) viewer).getCompilationUnit();
        if (compilationUnit != null) {
            CompletionProposalCollector cpc = new CompletionProposalCollector(compilationUnit);
            // set an empty editor Part as it's the only constructor where the viewer can be used.
            JavaContentAssistInvocationContext invocContext = new JavaContentAssistInvocationContext(viewer, offset, new NullEditorPart());
            cpc.setInvocationContext(invocContext);
            return invocContext;
        } else {
            return null;
        }
    } else {
        return null;
    }
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) CompletionProposalCollector(org.eclipse.jdt.ui.text.java.CompletionProposalCollector)

Example 7 with JavaContentAssistInvocationContext

use of org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext in project bndtools by bndtools.

the class BundleClassCompletionProposalComputer method computeCompletionProposals.

public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
    List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
    if (!(context instanceof JavaContentAssistInvocationContext)) {
        return Collections.emptyList();
    }
    try {
        int offset = context.getInvocationOffset();
        CharSequence prefix = context.computeIdentifierPrefix();
        result.add(new CompletionProposal("foobar", offset - prefix.length(), prefix.length(), offset - prefix.length() + 6));
        result.add(new CompletionProposal("fizzbuzz", offset - prefix.length(), prefix.length(), offset - prefix.length() + 8));
    } catch (BadLocationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}
Also used : JavaContentAssistInvocationContext(org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) CompletionProposal(org.eclipse.jface.text.contentassist.CompletionProposal) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

JavaContentAssistInvocationContext (org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext)7 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)4 ArrayList (java.util.ArrayList)3 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)3 Point (org.eclipse.swt.graphics.Point)3 TextViewer (org.eclipse.che.jdt.javaeditor.TextViewer)2 IBuffer (org.eclipse.jdt.core.IBuffer)2 IType (org.eclipse.jdt.core.IType)2 DocumentAdapter (org.eclipse.jdt.internal.core.DocumentAdapter)2 JavaAllCompletionProposalComputer (org.eclipse.jdt.internal.ui.text.java.JavaAllCompletionProposalComputer)2 RelevanceSorter (org.eclipse.jdt.internal.ui.text.java.RelevanceSorter)2 IJavaCompletionProposal (org.eclipse.jdt.ui.text.java.IJavaCompletionProposal)2 BadLocationException (org.eclipse.jface.text.BadLocationException)2 IDocument (org.eclipse.jface.text.IDocument)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 IContextInformation (org.eclipse.che.jface.text.contentassist.IContextInformation)1 CompletionContext (org.eclipse.jdt.core.CompletionContext)1 IJavaElement (org.eclipse.jdt.core.IJavaElement)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1