Example usage for org.eclipse.jdt.internal.codeassist InternalCompletionContext getCompletionNode

List of usage examples for org.eclipse.jdt.internal.codeassist InternalCompletionContext getCompletionNode

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.codeassist InternalCompletionContext getCompletionNode.

Prototype

public ASTNode getCompletionNode() 

Source Link

Document

Return the completion node associated with the current completion.

Usage

From source file:org.eclipse.recommenders.completion.rcp.RecommendersCompletionContext.java

License:Open Source License

@Override
public Optional<ASTNode> getCompletionNode() {
    InternalCompletionContext ctx = doGetCoreContext();
    ASTNode res = ctx != null ? ctx.getCompletionNode() : null;
    return Optional.fromNullable(res);
}

From source file:org.eclipse.recommenders.internal.chain.rcp.TypeBindingAnalyzer.java

License:Open Source License

private static boolean isCompletionOnMethodParameter(final InternalCompletionContext context) {
    return context.getCompletionNode() instanceof CompletionOnQualifiedAllocationExpression
            || context.getCompletionNode() instanceof CompletionOnMessageSend
            || context.getCompletionNodeParent() instanceof MessageSend;
}

From source file:org.eclipse.recommenders.internal.subwords.rcp.SubwordsSessionProcessor.java

License:Open Source License

@Override
public void initializeContext(IRecommendersCompletionContext recContext) {
    try {// w  w w  .j a  va2  s. c o  m
        minPrefixLengthForTypes = prefs.minPrefixLengthForTypes;
        JavaContentAssistInvocationContext jdtContext = recContext.getJavaContext();
        ICompilationUnit cu = jdtContext.getCompilationUnit();
        int offset = jdtContext.getInvocationOffset();

        // Tricky: we bypass the normal code completion request (triggered at the actual cursor position) by
        // replacing all required keys manually and triggering content assist where we need it:

        // TODO maybe we can get rid of that call by simply using the 'right' collector for the first time? This
        // would save ~5 ms I guess.
        NoProposalCollectingCompletionRequestor collector = new NoProposalCollectingCompletionRequestor();
        cu.codeComplete(offset, collector, new TimeDelimitedProgressMonitor(COMPLETION_TIME_OUT, MILLISECONDS));
        InternalCompletionContext compContext = collector.getCoreContext();
        if (compContext == null) {
            Logs.log(LogMessages.ERROR_COMPLETION_CONTEXT_NOT_COLLECTED, cu.getPath());
            return;
        }

        CORE_CONTEXT.set(jdtContext, compContext);
        recContext.set(CompletionContextKey.INTERNAL_COMPLETIONCONTEXT, compContext);

        String prefix = getPrefix(jdtContext);
        int length = prefix.length();
        recContext.set(CompletionContextKey.COMPLETION_PREFIX, prefix);

        Map<IJavaCompletionProposal, CompletionProposal> baseProposals = Maps.newHashMap();

        recContext.set(JAVA_PROPOSALS, baseProposals);

        ASTNode completionNode = compContext.getCompletionNode();
        ASTNode completionNodeParent = compContext.getCompletionNodeParent();
        SortedSet<Integer> triggerlocations = computeTriggerLocations(offset, completionNode,
                completionNodeParent, length);

        Set<String> sortkeys = Sets.newHashSet();
        for (int trigger : triggerlocations) {
            Map<IJavaCompletionProposal, CompletionProposal> newProposals = getNewProposals(jdtContext,
                    trigger);
            testAndInsertNewProposals(recContext, baseProposals, sortkeys, newProposals);
        }

        if (jdtContext instanceof JavadocContentAssistInvocationContext) {
            ITextViewer viewer = jdtContext.getViewer();
            IEditorPart editor = lookupEditor(cu);
            JavadocContentAssistInvocationContext newJdtContext = new JavadocContentAssistInvocationContext(
                    viewer, offset - length, editor, 0);
            testAndInsertNewProposals(recContext, baseProposals, sortkeys,
                    HtmlTagProposals.computeHtmlTagProposals(htmlTagProposalComputer, newJdtContext));
        }
    } catch (Exception e) {
        Logs.log(LogMessages.ERROR_EXCEPTION_DURING_CODE_COMPLETION, e);
    }
}