/** * Try to acquire a binding corresponding to the given element * for more precise information about (type) annotations. * * Currently this lookup is only enabled when null-annotations are enabled for the project. * * @param element the element being rendered * @param node the AST node corresponding to the given element, or null, if no AST node is available. * @return either a binding corresponding to the given element or null. */ public static IBinding getHoverBinding(IJavaElement element, ASTNode node) { if (element.getJavaProject().getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true).equals(JavaCore.ENABLED)) { if (node == null) { if (element instanceof ISourceReference) { ASTParser p= ASTParser.newParser(ASTProvider.SHARED_AST_LEVEL); p.setProject(element.getJavaProject()); p.setBindingsRecovery(true); try { return p.createBindings(new IJavaElement[] { element }, null)[0]; } catch (OperationCanceledException e) { return null; } } } else { return resolveBinding(node); } } return null; }
/** * Try to acquire a binding corresponding to the given element * for more precise information about (type) annotations. * * Currently this lookup is only enabled when null-annotations are enabled for the project. * * @param element the element being rendered * @param node the AST node corresponding to the given element, or null, if no AST node is available. * @return either a binding corresponding to the given element or null. */ public static IBinding getHoverBinding(IJavaElement element, ASTNode node) { if (element.getJavaProject().getOption(JavaCore.COMPILER_ANNOTATION_NULL_ANALYSIS, true).equals(JavaCore.ENABLED)) { if (node == null) { if (element instanceof ISourceReference) { ASTParser p= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); p.setProject(element.getJavaProject()); p.setBindingsRecovery(true); try { return p.createBindings(new IJavaElement[] { element }, null)[0]; } catch (OperationCanceledException e) { return null; } } } else { return resolveBinding(node); } } return null; }
private static IBinding getHoveredNodeBinding(IJavaElement element, ITypeRoot editorInputElement, IRegion hoverRegion) { if (editorInputElement == null || hoverRegion == null) { return null; } IBinding binding; ASTNode node= getHoveredASTNode(editorInputElement, hoverRegion); if (node == null) { ASTParser p= ASTParser.newParser(IASTSharedValues.SHARED_AST_LEVEL); p.setProject(element.getJavaProject()); p.setBindingsRecovery(true); try { binding= p.createBindings(new IJavaElement[] { element }, null)[0]; } catch (OperationCanceledException e) { return null; } } else { binding= resolveBinding(node); } return binding; }