Search in sources :

Example 1 with CompletionOnKeyword2

use of org.eclipse.jdt.internal.codeassist.complete.CompletionOnKeyword2 in project eclipse.jdt.ls by eclipse.

the class SnippetCompletionProposal method accept.

private static boolean accept(ICompilationUnit cu, CompletionContext completionContext, boolean acceptClass) {
    if (completionContext != null && completionContext.isExtended()) {
        if (completionContext.isInJavadoc()) {
            return false;
        }
        if (completionContext instanceof InternalCompletionContext) {
            InternalCompletionContext internalCompletionContext = (InternalCompletionContext) completionContext;
            ASTNode node = internalCompletionContext.getCompletionNode();
            if (node instanceof CompletionOnKeyword2) {
                return true;
            }
            if (node instanceof CompletionOnFieldType) {
                return true;
            }
            if (acceptClass && node instanceof CompletionOnSingleNameReference) {
                if (completionContext.getEnclosingElement() instanceof IMethod) {
                    CompilationUnit ast = CoreASTProvider.getInstance().getAST(cu, CoreASTProvider.WAIT_YES, null);
                    org.eclipse.jdt.core.dom.ASTNode astNode = ASTNodeSearchUtil.getAstNode(ast, completionContext.getTokenStart(), completionContext.getTokenEnd() - completionContext.getTokenStart() + 1);
                    return (astNode == null || (astNode.getParent() instanceof ExpressionStatement));
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) CompletionOnKeyword2(org.eclipse.jdt.internal.codeassist.complete.CompletionOnKeyword2) InternalCompletionContext(org.eclipse.jdt.internal.codeassist.InternalCompletionContext) CompletionOnFieldType(org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldType) ExpressionStatement(org.eclipse.jdt.core.dom.ExpressionStatement) ASTNode(org.eclipse.jdt.internal.compiler.ast.ASTNode) CompletionOnSingleNameReference(org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference) IMethod(org.eclipse.jdt.core.IMethod)

Aggregations

ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 IMethod (org.eclipse.jdt.core.IMethod)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 ExpressionStatement (org.eclipse.jdt.core.dom.ExpressionStatement)1 InternalCompletionContext (org.eclipse.jdt.internal.codeassist.InternalCompletionContext)1 CompletionOnFieldType (org.eclipse.jdt.internal.codeassist.complete.CompletionOnFieldType)1 CompletionOnKeyword2 (org.eclipse.jdt.internal.codeassist.complete.CompletionOnKeyword2)1 CompletionOnSingleNameReference (org.eclipse.jdt.internal.codeassist.complete.CompletionOnSingleNameReference)1 ASTNode (org.eclipse.jdt.internal.compiler.ast.ASTNode)1