Java Code Examples for org.eclipse.jdt.core.dom.IBinding#getJavaElement()
The following examples show how to use
org.eclipse.jdt.core.dom.IBinding#getJavaElement() .
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: SignatureHelpHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 6 votes |
private IMethod getMethod(ASTNode node) throws JavaModelException { IBinding binding; if (node instanceof MethodInvocation) { binding = ((MethodInvocation) node).resolveMethodBinding(); } else if (node instanceof MethodRef) { binding = ((MethodRef) node).resolveBinding(); } else if (node instanceof ClassInstanceCreation) { binding = ((ClassInstanceCreation) node).resolveConstructorBinding(); } else { binding = null; } if (binding != null) { IJavaElement javaElement = binding.getJavaElement(); if (javaElement instanceof IMethod) { IMethod method = (IMethod) javaElement; return method; } } return null; }
Example 2
Source File: ReorgCorrectionsSubProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private static boolean canModifyAccessRules(IBinding binding) { IJavaElement element= binding.getJavaElement(); if (element == null) return false; IPackageFragmentRoot root= JavaModelUtil.getPackageFragmentRoot(element); if (root == null) return false; try { IClasspathEntry classpathEntry= root.getRawClasspathEntry(); if (classpathEntry == null) return false; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) return true; if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) { ClasspathContainerInitializer classpathContainerInitializer= JavaCore.getClasspathContainerInitializer(classpathEntry.getPath().segment(0)); IStatus status= classpathContainerInitializer.getAccessRulesStatus(classpathEntry.getPath(), root.getJavaProject()); return status.isOK(); } } catch (JavaModelException e) { return false; } return false; }
Example 3
Source File: PrepareRenameHandler.java From eclipse.jdt.ls with Eclipse Public License 2.0 | 5 votes |
private boolean isBinaryOrPackage(ASTNode node) { if (node instanceof Name) { IBinding resolvedBinding = ((Name) node).resolveBinding(); IJavaElement element = resolvedBinding != null ? resolvedBinding.getJavaElement() : null; try { if (element == null || element.getElementType() == IJavaElement.PACKAGE_FRAGMENT || !RefactoringAvailabilityTester.isRenameElementAvailable(element)) { return true; } } catch (CoreException e) { JavaLanguageServerPlugin.logException(e.getMessage(), e); return true; } } return false; }
Example 4
Source File: QuickAssistProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private static boolean getRenameRefactoringProposal(IInvocationContext context, ASTNode node, IProblemLocation[] locations, Collection<ICommandAccess> resultingCollections) throws CoreException { if (!(context instanceof AssistContext)) { return false; } IEditorPart editor= ((AssistContext)context).getEditor(); if (!(editor instanceof JavaEditor)) return false; if (!(node instanceof SimpleName)) { return false; } SimpleName name= (SimpleName) node; IBinding binding= name.resolveBinding(); if (binding == null) { return false; } IJavaElement javaElement= binding.getJavaElement(); if (javaElement == null || !RefactoringAvailabilityTester.isRenameElementAvailable(javaElement)) { return false; } if (resultingCollections == null) { return true; } RenameRefactoringProposal proposal= new RenameRefactoringProposal((JavaEditor) editor); if (locations.length != 0) { proposal.setRelevance(IProposalRelevance.RENAME_REFACTORING_ERROR); } else if (containsQuickFixableRenameLocal(locations)) { proposal.setRelevance(IProposalRelevance.RENAME_REFACTORING_QUICK_FIX); } resultingCollections.add(proposal); return true; }
Example 5
Source File: CopyQualifiedNameAction.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
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; }