private IBinding[] getDeclarationsInScope() { if (fDeclarationsInScope == null) { ScopeAnalyzer analyzer= new ScopeAnalyzer(fCompilationUnit); fDeclarationsInScope= analyzer.getDeclarationsInScope(fPosition, ScopeAnalyzer.METHODS | ScopeAnalyzer.TYPES | ScopeAnalyzer.VARIABLES); } return fDeclarationsInScope; }
public static String[] getUsedVariableNames(ASTNode node) { CompilationUnit root= (CompilationUnit) node.getRoot(); Collection<String> res= (new ScopeAnalyzer(root)).getUsedVariableNames(node.getStartPosition(), node.getLength()); return res.toArray(new String[res.size()]); }
public IBinding[] getDeclarationsInScope(SimpleName selector, int flags) { try { // special case for switch on enum if (selector.getLocationInParent() == SwitchCase.EXPRESSION_PROPERTY) { ITypeBinding binding= ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding(); if (binding != null && binding.isEnum()) { return getEnumContants(binding); } } ITypeBinding parentTypeBinding= Bindings.getBindingOfParentType(selector); if (parentTypeBinding != null) { ITypeBinding binding= getQualifier(selector); DefaultBindingRequestor requestor= new DefaultBindingRequestor(parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); addTypeDeclarations(parentTypeBinding, flags, requestor); } else { addInherited(binding, flags, requestor); } List<IBinding> result= requestor.getResult(); return result.toArray(new IBinding[result.size()]); } return NO_BINDING; } finally { clearLists(); } }
public IBinding[] getDeclarationsInScope(int offset, int flags) { org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0); ASTNode node= finder.getCoveringNode(); if (node == null) { return NO_BINDING; } if (node instanceof SimpleName) { return getDeclarationsInScope((SimpleName) node, flags); } try { ITypeBinding binding= Bindings.getBindingOfParentType(node); DefaultBindingRequestor requestor= new DefaultBindingRequestor(binding, flags); addLocalDeclarations(node, offset, flags, requestor); if (binding != null) { addTypeDeclarations(binding, flags, requestor); } List<IBinding> result= requestor.getResult(); return result.toArray(new IBinding[result.size()]); } finally { clearLists(); } }
ITypeBinding binding= ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding(); if (binding != null && binding.isEnum()) { return hasEnumContants(declaration, binding.getTypeDeclaration()); ITypeBinding binding= getQualifier(selector); SearchRequestor requestor= new SearchRequestor(declaration, parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); if (requestor.found()) return requestor.isVisible(); addTypeDeclarations(parentTypeBinding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } else { addInherited(binding, flags, requestor); if (requestor.found()) return requestor.isVisible(); clearLists();
/** * Returns the reserved identifiers in the method to move. * * @return the reserved identifiers * @throws JavaModelException * if the method declaration could not be found */ protected String[] computeReservedIdentifiers() throws JavaModelException { final List<String> names= new ArrayList<>(); final MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode(fMethod, fSourceRewrite.getRoot()); if (declaration != null) { final List<SingleVariableDeclaration> parameters= declaration.parameters(); VariableDeclaration variable= null; for (int index= 0; index < parameters.size(); index++) { variable= parameters.get(index); names.add(variable.getName().getIdentifier()); } final Block body= declaration.getBody(); if (body != null) { final IBinding[] bindings= new ScopeAnalyzer(fSourceRewrite.getRoot()).getDeclarationsAfter(body.getStartPosition(), ScopeAnalyzer.VARIABLES); for (int index= 0; index < bindings.length; index++) names.add(bindings[index].getName()); } } final String[] result= new String[names.size()]; names.toArray(result); return result; }
if (hasFlag(TYPES, flags) && !binding.isAnonymous()) { if (requestor.acceptBinding(binding)) return true; addInherited(binding, flags, requestor); // add inherited addOuterDeclarationsForLocalType(binding, flags, requestor); } else { ITypeBinding declaringClass= binding.getDeclaringClass(); if (declaringClass != null) { if (addTypeDeclarations(declaringClass, flags, requestor)) // Recursively add inherited return true; } else if (hasFlag(TYPES, flags)) { if (fRoot.findDeclaringNode(binding) != null) { List types= fRoot.types();
public Collection<String> getUsedVariableNames(int offset, int length) { HashSet<String> result= new HashSet<>(); IBinding[] bindingsBefore= getDeclarationsInScope(offset, VARIABLES); for (int i= 0; i < bindingsBefore.length; i++) { result.add(bindingsBefore[i].getName()); } IBinding[] bindingsAfter= getDeclarationsAfter(offset + length, VARIABLES); for (int i= 0; i < bindingsAfter.length; i++) { result.add(bindingsAfter[i].getName()); } List<ImportDeclaration> imports= fRoot.imports(); for (int i= 0; i < imports.size(); i++) { ImportDeclaration decl= imports.get(i); if (decl.isStatic() && !decl.isOnDemand()) { result.add(ASTNodes.getSimpleNameIdentifier(decl.getName())); } } return result; } }
public TypeReferenceProcessor(Set oldSingleImports, Set oldDemandImports, CompilationUnit root, ImportRewrite impStructure, boolean ignoreLowerCaseNames) { fOldSingleImports= oldSingleImports; fOldDemandImports= oldDemandImports; fImpStructure= impStructure; fDoIgnoreLowerCaseNames= ignoreLowerCaseNames; ICompilationUnit cu= impStructure.getCompilationUnit(); fImplicitImports= new HashSet(3); fImplicitImports.add(""); //$NON-NLS-1$ fImplicitImports.add("java.lang"); //$NON-NLS-1$ fImplicitImports.add(cu.getParent().getElementName()); fAnalyzer= new ScopeAnalyzer(root); fCurrPackage= (IPackageFragment) cu.getParent(); fAllowDefaultPackageImports= cu.getJavaProject().getOption(JavaCore.COMPILER_COMPLIANCE, true).equals(JavaCore.VERSION_1_3); fImportsAdded= new HashSet(); fUnresolvedTypes= new HashMap(); }
private boolean addOuterDeclarationsForLocalType(ITypeBinding localBinding, int flags, IBindingRequestor requestor) { ASTNode node= fRoot.findDeclaringNode(localBinding); if (node == null) { return false; } if (node instanceof AbstractTypeDeclaration || node instanceof AnonymousClassDeclaration) { if (addLocalDeclarations(node.getParent(), flags, requestor)) return true; ITypeBinding parentTypeBinding= Bindings.getBindingOfParentType(node.getParent()); if (parentTypeBinding != null) { if (addTypeDeclarations(parentTypeBinding, flags, requestor)) return true; } } return false; }
return false; if (hasFlag(VARIABLES, flags)) { IVariableBinding[] variableBindings= binding.getDeclaredFields(); for (int i= 0; i < variableBindings.length; i++) { if (hasFlag(METHODS, flags)) { IMethodBinding[] methodBindings= binding.getDeclaredMethods(); for (int i= 0; i < methodBindings.length; i++) { if (hasFlag(TYPES, flags)) { ITypeBinding[] typeBindings= binding.getDeclaredTypes(); for (int i= 0; i < typeBindings.length; i++) { if (addInherited(superClass, flags, requestor)) // recursive return true; } else if (binding.isArray()) { if (addInherited(fRoot.getAST().resolveWellKnownType("java.lang.Object"), flags, requestor)) //$NON-NLS-1$ return true; if (addInherited(interfaces[i], flags, requestor)) // recursive return true;
IBinding[] visibleTypes= fAnalyzer.getDeclarationsInScope(ref, ScopeAnalyzer.TYPES); for (int i= 0; i < visibleTypes.length; i++) { ITypeBinding curr= ((ITypeBinding) visibleTypes[i]).getTypeDeclaration();
private boolean addLocalDeclarations(ASTNode node, int flags, IBindingRequestor requestor) { return addLocalDeclarations(node, node.getStartPosition(), flags, requestor); }
public IBinding[] getDeclarationsAfter(int offset, int flags) { try { org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0); ASTNode node= finder.getCoveringNode(); if (node == null) { return null; } ASTNode declaration= ASTResolving.findParentStatement(node); while (declaration instanceof Statement && declaration.getNodeType() != ASTNode.BLOCK) { declaration= declaration.getParent(); } if (declaration instanceof Block) { DefaultBindingRequestor requestor= new DefaultBindingRequestor(); DeclarationsAfterVisitor visitor= new DeclarationsAfterVisitor(node.getStartPosition(), flags, requestor); declaration.accept(visitor); List<IBinding> result= requestor.getResult(); return result.toArray(new IBinding[result.size()]); } return NO_BINDING; } finally { clearLists(); } }
MethodInvocation decl= (MethodInvocation) parent; if (selector == decl.getName()) { return getBinding(decl.getExpression()); QualifiedName qualifiedName= (QualifiedName) parent; if (selector == qualifiedName.getName()) { return getBinding(qualifiedName.getQualifier()); FieldAccess fieldAccess= (FieldAccess) parent; if (selector == fieldAccess.getName()) { return getBinding(fieldAccess.getExpression()); if (normalizedNode.getLocationInParent() == ClassInstanceCreation.TYPE_PROPERTY) { ClassInstanceCreation creation= (ClassInstanceCreation) normalizedNode.getParent(); return getBinding(creation.getExpression());
/** * Collects all elements available in a type and its hierarchy * @param binding The type binding * @param flags Flags defining the elements to report * @param requestor the requestor to which all results are reported * @return return <code>true</code> if the requestor has reported the binding as found and no further results are required */ private boolean addInherited(ITypeBinding binding, int flags, IBindingRequestor requestor) { return addInherited(binding, false, flags, requestor); }
ITypeBinding binding= ((SwitchStatement) selector.getParent().getParent()).getExpression().resolveTypeBinding(); if (binding != null && binding.isEnum()) { return hasEnumContants(declaration, binding.getTypeDeclaration()); ITypeBinding binding= getQualifier(selector); SearchRequestor requestor= new SearchRequestor(declaration, parentTypeBinding, flags); if (binding == null) { addLocalDeclarations(selector, flags, requestor); if (requestor.found()) return requestor.isVisible(); addTypeDeclarations(parentTypeBinding, flags, requestor); if (requestor.found()) return requestor.isVisible(); } else { addInherited(binding, flags, requestor); if (requestor.found()) return requestor.isVisible(); clearLists();
/** * Returns the reserved identifiers in the method to move. * * @return the reserved identifiers * @throws JavaModelException * if the method declaration could not be found */ protected String[] computeReservedIdentifiers() throws JavaModelException { final List<String> names= new ArrayList<>(); final MethodDeclaration declaration= ASTNodeSearchUtil.getMethodDeclarationNode(fMethod, fSourceRewrite.getRoot()); if (declaration != null) { final List<SingleVariableDeclaration> parameters= declaration.parameters(); VariableDeclaration variable= null; for (int index= 0; index < parameters.size(); index++) { variable= parameters.get(index); names.add(variable.getName().getIdentifier()); } final Block body= declaration.getBody(); if (body != null) { final IBinding[] bindings= new ScopeAnalyzer(fSourceRewrite.getRoot()).getDeclarationsAfter(body.getStartPosition(), ScopeAnalyzer.VARIABLES); for (int index= 0; index < bindings.length; index++) names.add(bindings[index].getName()); } } final String[] result= new String[names.size()]; names.toArray(result); return result; }
public IBinding[] getDeclarationsInScope(int offset, int flags) { org.eclipse.jdt.core.dom.NodeFinder finder= new org.eclipse.jdt.core.dom.NodeFinder(fRoot, offset, 0); ASTNode node= finder.getCoveringNode(); if (node == null) { return NO_BINDING; } if (node instanceof SimpleName) { return getDeclarationsInScope((SimpleName) node, flags); } try { ITypeBinding binding= Bindings.getBindingOfParentType(node); DefaultBindingRequestor requestor= new DefaultBindingRequestor(binding, flags); addLocalDeclarations(node, offset, flags, requestor); if (binding != null) { addTypeDeclarations(binding, flags, requestor); } List<IBinding> result= requestor.getResult(); return result.toArray(new IBinding[result.size()]); } finally { clearLists(); } }
if (hasFlag(TYPES, flags) && !binding.isAnonymous()) { if (requestor.acceptBinding(binding)) return true; addInherited(binding, flags, requestor); // add inherited addOuterDeclarationsForLocalType(binding, flags, requestor); } else { ITypeBinding declaringClass= binding.getDeclaringClass(); if (declaringClass != null) { if (addTypeDeclarations(declaringClass, flags, requestor)) // Recursively add inherited return true; } else if (hasFlag(TYPES, flags)) { if (fRoot.findDeclaringNode(binding) != null) { List<AbstractTypeDeclaration> types= fRoot.types();