/** * Returns the topmost ancestor of <code>name</code> that is still a {@link Name}. * <p> * <b>Note:</b> The returned node may resolve to a different binding than the given <code>name</code>! * * @param name a name node * @return the topmost name * @see #getNormalizedNode(ASTNode) */ public static Name getTopMostName(Name name) { Name result= name; while(result.getParent() instanceof Name) { result= (Name)result.getParent(); } return result; }
/** * Returns the topmost ancestor of <code>name</code> that is still a {@link Name}. * <p> * <b>Note:</b> The returned node may resolve to a different binding than the given <code>name</code>! * * @param name a name node * @return the topmost name * @see #getNormalizedNode(ASTNode) */ public static Name getTopMostName(Name name) { Name result= name; while(result.getParent() instanceof Name) { result= (Name)result.getParent(); } return result; }
private static Expression getQualifiedReference(Name fieldName) { if (doesParentQualify(fieldName)) return (Expression) fieldName.getParent(); return fieldName; }
private static Expression getQualifiedReference(Name fieldName) { if (doesParentQualify(fieldName)) return (Expression) fieldName.getParent(); return fieldName; }
private static Expression getQualifiedReference(Name fieldName) { if (doesParentQualify(fieldName)) return (Expression) fieldName.getParent(); return fieldName; }
private static VariableDeclaration getVariableDeclaration(Name node) { IBinding binding= node.resolveBinding(); if (binding == null && node.getParent() instanceof VariableDeclaration) { return (VariableDeclaration) node.getParent(); } if (binding != null && binding.getKind() == IBinding.VARIABLE) { CompilationUnit cu= ASTNodes.getParent(node, CompilationUnit.class); return ASTNodes.findVariableDeclaration( ((IVariableBinding) binding), cu); } return null; }
private static String getTypeName(int typeKind, Name node) { String name= ASTNodes.getSimpleNameIdentifier(node); if (typeKind == K_CLASS || typeKind == K_INTERFACE) { ASTNode parent= node.getParent(); if (parent.getLocationInParent() == ParameterizedType.TYPE_PROPERTY) { String typeArgBaseName= name.startsWith(String.valueOf('T')) ? String.valueOf('S') : String.valueOf('T'); // use 'S' or 'T' int nTypeArgs= ((ParameterizedType) parent.getParent()).typeArguments().size(); StringBuffer buf= new StringBuffer(name); buf.append('<'); if (nTypeArgs == 1) { buf.append(typeArgBaseName); } else { for (int i= 0; i < nTypeArgs; i++) { if (i != 0) buf.append(", "); //$NON-NLS-1$ buf.append(typeArgBaseName).append(i + 1); } } buf.append('>'); return buf.toString(); } } return name; }
private static VariableDeclaration getVariableDeclaration(Name node) { IBinding binding= node.resolveBinding(); if (binding == null && node.getParent() instanceof VariableDeclaration) return (VariableDeclaration) node.getParent(); if (binding != null && binding.getKind() == IBinding.VARIABLE) { CompilationUnit cu= (CompilationUnit) ASTNodes.getParent(node, CompilationUnit.class); return ASTNodes.findVariableDeclaration( ((IVariableBinding) binding), cu); } return null; }
private static VariableDeclaration getVariableDeclaration(Name node) { IBinding binding= node.resolveBinding(); if (binding == null && node.getParent() instanceof VariableDeclaration) return (VariableDeclaration) node.getParent(); if (binding != null && binding.getKind() == IBinding.VARIABLE) { CompilationUnit cu= ASTNodes.getParent(node, CompilationUnit.class); return ASTNodes.findVariableDeclaration( ((IVariableBinding) binding), cu); } return null; }
private static VariableDeclaration getVariableDeclaration(Name node) { IBinding binding= node.resolveBinding(); if (binding == null && node.getParent() instanceof VariableDeclaration) return (VariableDeclaration) node.getParent(); if (binding != null && binding.getKind() == IBinding.VARIABLE) { CompilationUnit cu= (CompilationUnit) ASTNodes.getParent(node, CompilationUnit.class); return ASTNodes.findVariableDeclaration( ((IVariableBinding) binding), cu); } return null; }
private static boolean doesParentQualify(Name fieldName) { ASTNode parent= fieldName.getParent(); Assert.isNotNull(parent); if (parent instanceof FieldAccess && ((FieldAccess) parent).getName() == fieldName) return true; if (parent instanceof QualifiedName && ((QualifiedName) parent).getName() == fieldName) return true; if (parent instanceof MethodInvocation && ((MethodInvocation) parent).getName() == fieldName) return true; return false; }
private static boolean doesParentQualify(Name fieldName) { ASTNode parent= fieldName.getParent(); Assert.isNotNull(parent); if (parent instanceof FieldAccess && ((FieldAccess) parent).getName() == fieldName) return true; if (parent instanceof QualifiedName && ((QualifiedName) parent).getName() == fieldName) return true; if (parent instanceof MethodInvocation && ((MethodInvocation) parent).getName() == fieldName) return true; return false; }
private static boolean doesParentQualify(Name fieldName) { ASTNode parent= fieldName.getParent(); Assert.isNotNull(parent); if (parent instanceof FieldAccess && ((FieldAccess) parent).getName() == fieldName) return true; if (parent instanceof QualifiedName && ((QualifiedName) parent).getName() == fieldName) return true; if (parent instanceof MethodInvocation && ((MethodInvocation) parent).getName() == fieldName) return true; return false; }
public String initialize(CompilationUnit root, ASTNode node) { if (!(node instanceof Name)) return SearchMessages.OccurrencesFinder_no_element; fRoot= root; fSelectedNode= (Name)node; fTarget= fSelectedNode.resolveBinding(); if (fTarget == null) return SearchMessages.OccurrencesFinder_no_binding; fTarget= getBindingDeclaration(fTarget); fTargetIsStaticMethodImport= isStaticImport(fSelectedNode.getParent()); return null; }
/** * Is the specified name a qualified entity, e.g. preceded by 'this', * 'super' or part of a method invocation? * * @param name * the name to check * @return <code>true</code> if this entity is qualified, * <code>false</code> otherwise */ protected static boolean isQualifiedEntity(final Name name) { Assert.isNotNull(name); final ASTNode parent= name.getParent(); if ((parent instanceof QualifiedName && ((QualifiedName) parent).getName().equals(name)) || (parent instanceof FieldAccess && ((FieldAccess) parent).getName().equals(name)) || (parent instanceof SuperFieldAccess)) return true; else if (parent instanceof MethodInvocation) { final MethodInvocation invocation= (MethodInvocation) parent; return invocation.getExpression() != null && invocation.getName().equals(name); } return false; }
/** * Is the specified name a qualified entity, e.g. preceded by 'this', * 'super' or part of a method invocation? * * @param name * the name to check * @return <code>true</code> if this entity is qualified, * <code>false</code> otherwise */ protected static boolean isQualifiedEntity(final Name name) { Assert.isNotNull(name); final ASTNode parent= name.getParent(); if (parent instanceof QualifiedName && ((QualifiedName) parent).getName().equals(name) || parent instanceof FieldAccess && ((FieldAccess) parent).getName().equals(name) || parent instanceof SuperFieldAccess) return true; else if (parent instanceof MethodInvocation) { final MethodInvocation invocation= (MethodInvocation) parent; return invocation.getExpression() != null && invocation.getName().equals(name); } return false; }
/** * Is the specified name a qualified entity, e.g. preceded by 'this', * 'super' or part of a method invocation? * * @param name * the name to check * @return <code>true</code> if this entity is qualified, * <code>false</code> otherwise */ protected static boolean isQualifiedEntity(final Name name) { Assert.isNotNull(name); final ASTNode parent= name.getParent(); if (parent instanceof QualifiedName && ((QualifiedName) parent).getName().equals(name) || parent instanceof FieldAccess && ((FieldAccess) parent).getName().equals(name) || parent instanceof SuperFieldAccess) return true; else if (parent instanceof MethodInvocation) { final MethodInvocation invocation= (MethodInvocation) parent; return invocation.getExpression() != null && invocation.getName().equals(name); } return false; }
@Override public String initialize(CompilationUnit root, ASTNode node) { if (!(node instanceof Name)) return SearchMessages.OccurrencesFinder_no_element; fRoot= root; fSelectedNode= (Name)node; fTarget= fSelectedNode.resolveBinding(); if (fTarget == null) return SearchMessages.OccurrencesFinder_no_binding; fTarget= getBindingDeclaration(fTarget); fTargetIsStaticMethodImport= isStaticImport(fSelectedNode.getParent()); fReadDescription= Messages.format(SearchMessages.OccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fTarget.getName())); fWriteDescription= Messages.format(SearchMessages.OccurrencesFinder_occurrence_write_description, BasicElementLabels.getJavaElementName(fTarget.getName())); return null; }
@Override public String initialize(CompilationUnit root, ASTNode node) { if (!(node instanceof Name)) return SearchMessages.OccurrencesFinder_no_element; fRoot= root; fSelectedNode= (Name)node; fTarget= fSelectedNode.resolveBinding(); if (fTarget == null) return SearchMessages.OccurrencesFinder_no_binding; fTarget= getBindingDeclaration(fTarget); fTargetIsStaticMethodImport= isStaticImport(fSelectedNode.getParent()); fReadDescription= Messages.format(SearchMessages.OccurrencesFinder_occurrence_description, BasicElementLabels.getJavaElementName(fTarget.getName())); fWriteDescription= Messages.format(SearchMessages.OccurrencesFinder_occurrence_write_description, BasicElementLabels.getJavaElementName(fTarget.getName())); return null; }