org.eclipse.jdt.internal.codeassist.InternalCompletionContext Java Examples

The following examples show how to use org.eclipse.jdt.internal.codeassist.InternalCompletionContext. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnippetCompletionProposal.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 6 votes vote down vote up
private static ClassScope getClassScope(CompletionProposalCollector completionProposalCollector) {
	ClassScope scope = null;
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		if (extendedContext != null) {
			Scope assistScope = ((Scope) Reflection.assistScopeField.get(extendedContext));
			if (assistScope != null) {
				scope = assistScope.classScope();
			}
		}
	} catch (IllegalAccessException ignore) {
		// ignore
	}
	return scope;
}
 
Example #3
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static ASTNode getAssistNode(CompletionProposalCollector completionProposalCollector) {
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		if (extendedContext == null) return null;
		return (ASTNode) Reflection.assistNodeField.get(extendedContext);
	} catch (Exception ignore) {
		return null;
	}
}
 
Example #4
Source File: PatchExtensionMethodCompletionProposal.java    From EasyMPermission with MIT License 5 votes vote down vote up
private static void copyNameLookupAndCompletionEngine(CompletionProposalCollector completionProposalCollector, IJavaCompletionProposal proposal,
		InternalCompletionProposal newProposal) {
	
	try {
		InternalCompletionContext context = (InternalCompletionContext) Reflection.contextField.get(completionProposalCollector);
		InternalExtendedCompletionContext extendedContext = (InternalExtendedCompletionContext) Reflection.extendedContextField.get(context);
		LookupEnvironment lookupEnvironment = (LookupEnvironment) Reflection.lookupEnvironmentField.get(extendedContext);
		Reflection.nameLookupField.set(newProposal, ((SearchableEnvironment) lookupEnvironment.nameEnvironment).nameLookup);
		Reflection.completionEngineField.set(newProposal, lookupEnvironment.typeRequestor);
	} catch (IllegalAccessException ignore) {
		// ignore
	}
}
 
Example #5
Source File: PostfixCompletionProposalComputer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private void updateTemplateEngine(InternalCompletionContext context) {
       ASTNode completionNode = context.getCompletionNode();
       ASTNode completionNodeParent = context.getCompletionNodeParent();
       postfixCompletionTemplateEngine.setASTNodes(completionNode, completionNodeParent);
}