Java Code Examples for org.eclipse.jdt.core.dom.QualifiedName#getQualifier()
The following examples show how to use
org.eclipse.jdt.core.dom.QualifiedName#getQualifier() .
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: MoveInstanceMethodProcessor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
/** * Is the specified name a target access? * * @param name * the name to check * @return <code>true</code> if this name is a target access, * <code>false</code> otherwise */ protected boolean isTargetAccess(final Name name) { Assert.isNotNull(name); final IBinding binding= name.resolveBinding(); if (Bindings.equals(fTarget, binding)) return true; if (name.getParent() instanceof FieldAccess) { final FieldAccess access= (FieldAccess) name.getParent(); final Expression expression= access.getExpression(); if (expression instanceof Name) return isTargetAccess((Name) expression); } else if (name instanceof QualifiedName) { final QualifiedName qualified= (QualifiedName) name; if (qualified.getQualifier() != null) return isTargetAccess(qualified.getQualifier()); } return false; }
Example 2
Source File: SuperTypeConstraintsCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override public final void endVisit(final QualifiedName node) { final ASTNode parent= node.getParent(); final Name qualifier= node.getQualifier(); IBinding binding= qualifier.resolveBinding(); if (binding instanceof ITypeBinding) { final ConstraintVariable2 variable= fModel.createTypeVariable((ITypeBinding) binding, new CompilationUnitRange(RefactoringASTParser.getCompilationUnit(node), new SourceRange(qualifier.getStartPosition(), qualifier.getLength()))); if (variable != null) qualifier.setProperty(PROPERTY_CONSTRAINT_VARIABLE, variable); } binding= node.getName().resolveBinding(); if (binding instanceof IVariableBinding && !(parent instanceof ImportDeclaration)) endVisit((IVariableBinding) binding, qualifier, node); else if (binding instanceof ITypeBinding && parent instanceof MethodDeclaration) endVisit((ITypeBinding) binding, node); }
Example 3
Source File: ASTNodes.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
public static SimpleName getLeftMostSimpleName(Name name) { if (name instanceof SimpleName) { return (SimpleName)name; } else { final SimpleName[] result= new SimpleName[1]; ASTVisitor visitor= new ASTVisitor() { @Override public boolean visit(QualifiedName qualifiedName) { Name left= qualifiedName.getQualifier(); if (left instanceof SimpleName) result[0]= (SimpleName)left; else left.accept(this); return false; } }; name.accept(visitor); return result[0]; } }
Example 4
Source File: UnusedImportsNodeCollector.java From j2cl with Apache License 2.0 | 5 votes |
@Override public boolean visit(QualifiedName qualifiedName) { // We need the first component of the qualified name for example for Foo.Bar.baz // we are looking for the import of Foo. Name qualifier = qualifiedName.getQualifier(); while (!qualifier.isSimpleName()) { qualifier = ((QualifiedName) qualifier).getQualifier(); } referencedNames.add(qualifier.getFullyQualifiedName()); return false; }
Example 5
Source File: FullConstraintCreator.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override public ITypeConstraint[] create(QualifiedName qualifiedName){ SimpleName name= qualifiedName.getName(); Name qualifier= qualifiedName.getQualifier(); IBinding nameBinding= name.resolveBinding(); if (nameBinding instanceof IVariableBinding){ IVariableBinding vb= (IVariableBinding)nameBinding; if (vb.isField()) return createConstraintsForAccessToField(vb, qualifier, qualifiedName); } //TODO other bindings return new ITypeConstraint[0]; }
Example 6
Source File: AbstractLoopUtilities.java From JDeodorant with MIT License | 5 votes |
public static boolean isLengthFieldAccess(Expression expression) { SimpleName name = null; ITypeBinding typeBinding = null; if (expression instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName) expression; name = qualifiedName.getName(); Name qualifier = qualifiedName.getQualifier(); typeBinding = qualifier.resolveTypeBinding(); } else if (expression instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess)expression; name = fieldAccess.getName(); Expression fieldAsccessExpression = fieldAccess.getExpression(); typeBinding = fieldAsccessExpression.resolveTypeBinding(); } if (name != null && typeBinding != null) { IBinding nameBinding = name.resolveBinding(); if (nameBinding != null && nameBinding.getKind() == IBinding.VARIABLE && typeBinding != null) { IVariableBinding nameVariableBinding = (IVariableBinding) nameBinding; return (nameVariableBinding.getName().equals("length") && typeBinding.isArray()); } } return false; }
Example 7
Source File: BindingSignatureVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(QualifiedName name) { if (name.getQualifier() != null) { handleExpression(name.getQualifier()); } handleExpression(name.getName()); return false; }
Example 8
Source File: StyledStringVisitor.java From JDeodorant with MIT License | 5 votes |
public boolean visit(QualifiedName name) { /* * Name . SimpleName */ activateDiffStyle(name); if (name.getQualifier() != null) { handleExpression(name.getQualifier()); appendPeriod(); } handleExpression(name.getName()); deactivateDiffStyle(name); return false; }
Example 9
Source File: CodeStyleFix.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
private static ToStaticAccessOperation[] createToStaticAccessOperations(CompilationUnit astRoot, HashMap<ASTNode, Block> createdBlocks, IProblemLocation problem, boolean conservative) { ASTNode selectedNode= problem.getCoveringNode(astRoot); if (selectedNode == null) { return null; } Expression qualifier= null; IBinding accessBinding= null; if (selectedNode instanceof SimpleName) { selectedNode= selectedNode.getParent(); } if (selectedNode instanceof QualifiedName) { QualifiedName name= (QualifiedName) selectedNode; qualifier= name.getQualifier(); accessBinding= name.resolveBinding(); } else if (selectedNode instanceof MethodInvocation) { MethodInvocation methodInvocation= (MethodInvocation) selectedNode; qualifier= methodInvocation.getExpression(); accessBinding= methodInvocation.getName().resolveBinding(); } else if (selectedNode instanceof FieldAccess) { FieldAccess fieldAccess= (FieldAccess) selectedNode; qualifier= fieldAccess.getExpression(); accessBinding= fieldAccess.getName().resolveBinding(); } if (accessBinding != null && qualifier != null) { if (conservative && ASTResolving.findParentStatement(qualifier) == null) return null; ToStaticAccessOperation declaring= null; ITypeBinding declaringTypeBinding= getDeclaringTypeBinding(accessBinding); if (declaringTypeBinding != null) { declaringTypeBinding= declaringTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments declaring= new ToStaticAccessOperation(declaringTypeBinding, qualifier, createdBlocks); } ToStaticAccessOperation instance= null; ITypeBinding instanceTypeBinding= Bindings.normalizeTypeBinding(qualifier.resolveTypeBinding()); if (instanceTypeBinding != null) { instanceTypeBinding= instanceTypeBinding.getTypeDeclaration(); // use generic to avoid any type arguments if (instanceTypeBinding.getTypeDeclaration() != declaringTypeBinding) { instance= new ToStaticAccessOperation(instanceTypeBinding, qualifier, createdBlocks); } } if (declaring != null && instance != null) { return new ToStaticAccessOperation[] {declaring, instance}; } else { return new ToStaticAccessOperation[] {declaring}; } } return null; }
Example 10
Source File: MethodDeclarationUtility.java From JDeodorant with MIT License | 4 votes |
public static AbstractVariable createVariable(SimpleName simpleName, AbstractVariable rightPart) { IBinding binding = simpleName.resolveBinding(); if(binding != null && binding.getKind() == IBinding.VARIABLE) { IVariableBinding variableBinding = (IVariableBinding)binding; AbstractVariable currentVariable = null; if(rightPart == null) currentVariable = new PlainVariable(variableBinding); else currentVariable = new CompositeVariable(variableBinding, rightPart); if(simpleName.getParent() instanceof QualifiedName) { QualifiedName qualifiedName = (QualifiedName)simpleName.getParent(); Name qualifier = qualifiedName.getQualifier(); if(qualifier instanceof SimpleName) { SimpleName qualifierSimpleName = (SimpleName)qualifier; if(!qualifierSimpleName.equals(simpleName)) return createVariable(qualifierSimpleName, currentVariable); else return currentVariable; } else if(qualifier instanceof QualifiedName) { QualifiedName qualifiedName2 = (QualifiedName)qualifier; return createVariable(qualifiedName2.getName(), currentVariable); } } else if(simpleName.getParent() instanceof FieldAccess) { FieldAccess fieldAccess = (FieldAccess)simpleName.getParent(); Expression fieldAccessExpression = fieldAccess.getExpression(); if(fieldAccessExpression instanceof FieldAccess) { FieldAccess fieldAccess2 = (FieldAccess)fieldAccessExpression; return createVariable(fieldAccess2.getName(), currentVariable); } else if(fieldAccessExpression instanceof SimpleName) { SimpleName fieldAccessSimpleName = (SimpleName)fieldAccessExpression; return createVariable(fieldAccessSimpleName, currentVariable); } else if(fieldAccessExpression instanceof ThisExpression) { return currentVariable; } } else { return currentVariable; } } return null; }