Java Code Examples for org.eclipse.jdt.core.dom.NodeFinder#getCoveringNode()

The following examples show how to use org.eclipse.jdt.core.dom.NodeFinder#getCoveringNode() . 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: JavaStatementPostfixContext.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private void initDomAST() {
		if (isReadOnly())
			return;
		
		ASTParser parser= ASTParser.newParser(AST.JLS8);
		parser.setSource(getCompilationUnit());
		parser.setResolveBindings(true);
		org.eclipse.jdt.core.dom.ASTNode domAst = parser.createAST(new NullProgressMonitor());
		
//		org.eclipse.jdt.core.dom.AST ast = domAst.getAST();
		
		NodeFinder nf = new NodeFinder(domAst, getCompletionOffset(), 1);
		org.eclipse.jdt.core.dom.ASTNode cv = nf.getCoveringNode();
		
		bodyDeclaration = ASTResolving.findParentBodyDeclaration(cv);
		parentDeclaration = ASTResolving.findParentType(cv);
		domInitialized = true;
	}
 
Example 2
Source File: ASTNodeSearchUtil.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
private static ASTNode findNode(ISourceRange range, CompilationUnit cuNode){
	NodeFinder nodeFinder= new NodeFinder(cuNode, range.getOffset(), range.getLength());
	ASTNode coveredNode= nodeFinder.getCoveredNode();
	if (coveredNode != null) {
		return coveredNode;
	} else {
		return nodeFinder.getCoveringNode();
	}
}
 
Example 3
Source File: ASTNodeSearchUtil.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private static ASTNode findNode(ISourceRange range, CompilationUnit cuNode){
	NodeFinder nodeFinder= new NodeFinder(cuNode, range.getOffset(), range.getLength());
	ASTNode coveredNode= nodeFinder.getCoveredNode();
	if (coveredNode != null)
		return coveredNode;
	else
		return nodeFinder.getCoveringNode();
}
 
Example 4
Source File: CompilationUnitRange.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
public ASTNode getNode(CompilationUnit rootNode) {
	NodeFinder finder= new NodeFinder(rootNode, fSourceRange.getOffset(), fSourceRange.getLength());
	ASTNode result= finder.getCoveringNode();
	if (result != null)
		return result;
	return finder.getCoveredNode();
}
 
Example 5
Source File: CopyQualifiedNameAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private Object getSelectedElement(JavaEditor editor) {
	ISourceViewer viewer= editor.getViewer();
	if (viewer == null)
		return null;

	Point selectedRange= viewer.getSelectedRange();
	int length= selectedRange.y;
	int offset= selectedRange.x;

	ITypeRoot element= JavaUI.getEditorInputTypeRoot(editor.getEditorInput());
	if (element == null)
		return null;

	CompilationUnit ast= SharedASTProvider.getAST(element, SharedASTProvider.WAIT_YES, null);
	if (ast == null)
		return null;

	NodeFinder finder= new NodeFinder(ast, offset, length);
	ASTNode node= finder.getCoveringNode();

	IBinding binding= null;
	if (node instanceof Name) {
		binding= getConstructorBindingIfAvailable((Name)node);
		if (binding != null)
			return binding;
		binding= ((Name)node).resolveBinding();
	} else if (node instanceof MethodInvocation) {
		binding= ((MethodInvocation)node).resolveMethodBinding();
	} else if (node instanceof MethodDeclaration) {
		binding= ((MethodDeclaration)node).resolveBinding();
	} else if (node instanceof Type) {
		binding= ((Type)node).resolveBinding();
	} else if (node instanceof AnonymousClassDeclaration) {
		binding= ((AnonymousClassDeclaration)node).resolveBinding();
	} else if (node instanceof TypeDeclaration) {
		binding= ((TypeDeclaration)node).resolveBinding();
	} else if (node instanceof CompilationUnit) {
		return ((CompilationUnit)node).getJavaElement();
	} else if (node instanceof Expression) {
		binding= ((Expression)node).resolveTypeBinding();
	} else if (node instanceof ImportDeclaration) {
		binding= ((ImportDeclaration)node).resolveBinding();
	} else if (node instanceof MemberRef) {
		binding= ((MemberRef)node).resolveBinding();
	} else if (node instanceof MemberValuePair) {
		binding= ((MemberValuePair)node).resolveMemberValuePairBinding();
	} else if (node instanceof PackageDeclaration) {
		binding= ((PackageDeclaration)node).resolveBinding();
	} else if (node instanceof TypeParameter) {
		binding= ((TypeParameter)node).resolveBinding();
	} else if (node instanceof VariableDeclaration) {
		binding= ((VariableDeclaration)node).resolveBinding();
	}

	if (binding != null)
		return binding.getJavaElement();

	return null;
}
 
Example 6
Source File: ProblemLocation.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
public ASTNode getCoveringNode(CompilationUnit astRoot) {
	NodeFinder finder= new NodeFinder(astRoot, fOffset, fLength);
	return finder.getCoveringNode();
}