List of usage examples for org.eclipse.jdt.core.dom AbstractTypeDeclaration getName
public SimpleName getName()
From source file:ca.ecliptical.pde.internal.ds.AnnotationProcessor.java
License:Open Source License
private boolean visitInvalidElementType(AbstractTypeDeclaration type) { Annotation annotation = findComponentAnnotation(type); if (annotation != null) reportProblem(annotation, null, problems, NLS.bind(Messages.AnnotationProcessor_invalidComponentImplementationClass, type.getName().getIdentifier()), type.getName().getIdentifier()); return errorLevel != ValidationErrorLevel.none; }
From source file:com.architexa.diagrams.relo.jdt.ParseUtilities.java
License:Open Source License
static private TypeDeclaration findTypeDeclaration(CompilationUnit cu, IType type) throws JavaModelException { IType declaringType = type.getDeclaringType(); if (declaringType == null) { Iterator<?> topLevelTypeDeclIt = cu.types().iterator(); while (topLevelTypeDeclIt.hasNext()) { AbstractTypeDeclaration td = (AbstractTypeDeclaration) topLevelTypeDeclIt.next(); if (td.getName().getIdentifier().equals(type.getElementName())) return (TypeDeclaration) td; }/*w w w . ja va2 s .c o m*/ } else { TypeDeclaration declaringTD = findTypeDeclaration(cu, declaringType); TypeDeclaration[] siblingTD = declaringTD.getTypes(); for (int i = 0; i < siblingTD.length; i++) { if (siblingTD[i].getName().getIdentifier().equals(type.getElementName())) return siblingTD[i]; } } logger.error("Could not find type for: " + type.getFullyQualifiedName()); return null; }
From source file:com.ecfeed.ui.common.EclipseModelImplementer.java
License:Open Source License
private EnumDeclaration getEnumDeclaration(CompilationUnit unit, String typeName) { String className = JavaUtils.getLocalName(typeName); for (Object object : unit.types()) { AbstractTypeDeclaration declaration = (AbstractTypeDeclaration) object; if (declaration.getName().toString().equals(className) && declaration instanceof EnumDeclaration) { return (EnumDeclaration) declaration; }//w w w. j a va2 s. co m } return null; }
From source file:com.facebook.buck.java.JavaFileParser.java
License:Apache License
private String getFullyQualifiedTypeName(AbstractTypeDeclaration node) { LinkedList<String> nameParts = Lists.newLinkedList(); nameParts.add(node.getName().toString()); ASTNode parent = node.getParent();// www. j av a 2 s . c om while (!(parent instanceof CompilationUnit)) { nameParts.addFirst(((AbstractTypeDeclaration) parent).getName().toString()); parent = parent.getParent(); } // A Java file might not have a package. Hopefully all of ours do though... PackageDeclaration packageDecl = ((CompilationUnit) parent).getPackage(); if (packageDecl != null) { nameParts.addFirst(packageDecl.getName().toString()); } return Joiner.on(".").join(nameParts); }
From source file:com.facebook.buck.jvm.java.JavaFileParser.java
License:Apache License
@Nullable private String getFullyQualifiedTypeName(AbstractTypeDeclaration node) { LinkedList<String> nameParts = new LinkedList<>(); nameParts.add(node.getName().toString()); ASTNode parent = node.getParent();/*from w w w . j av a2s .com*/ while (!(parent instanceof CompilationUnit)) { if (parent instanceof AbstractTypeDeclaration) { nameParts.addFirst(((AbstractTypeDeclaration) parent).getName().toString()); parent = parent.getParent(); } else if (parent instanceof AnonymousClassDeclaration) { // If this is defined in an anonymous class, then there is no meaningful fully qualified // name. return null; } else { throw new RuntimeException("Unexpected parent " + parent + " for " + node); } } // A Java file might not have a package. Hopefully all of ours do though... PackageDeclaration packageDecl = ((CompilationUnit) parent).getPackage(); if (packageDecl != null) { nameParts.addFirst(packageDecl.getName().toString()); } return Joiner.on(".").join(nameParts); }
From source file:com.facebook.nuclide.shim.EclipseJavaElementShim.java
License:Open Source License
private static SimpleName getNodeDeclName(ASTNode node) { try {//from w w w. j a va2 s . c o m AbstractTypeDeclaration decl = (AbstractTypeDeclaration) node; return decl.getName(); } catch (Exception ex) { return null; } }
From source file:com.google.currysrc.api.process.ast.TypeLocator.java
License:Apache License
/** * Creates a {@code TypeLocator} for the specified {@link ASTNode}. *///from w ww .j av a2s.c o m public TypeLocator(final AbstractTypeDeclaration typeDeclaration) { if (typeDeclaration.isLocalTypeDeclaration()) { throw new IllegalArgumentException("Local types not supported: " + typeDeclaration); } CompilationUnit cu = (CompilationUnit) typeDeclaration.getRoot(); this.packageMatcher = new PackageMatcher(PackageMatcher.getPackageName(cu)); // Traverse the type declarations towards the root, building up a list of type names in // reverse order. List<String> typeNames = Lists.newArrayList(); AbstractTypeDeclaration currentNode = typeDeclaration; while (typeDeclaration != null) { typeNames.add(currentNode.getName().getFullyQualifiedName()); // Handle nested / inner classes. ASTNode parentNode = currentNode.getParent(); if (parentNode != null) { if (parentNode == cu) { break; } if (!(parentNode instanceof AbstractTypeDeclaration)) { throw new AssertionError("Unexpected parent for nested/inner class: parent=" + parentNode + " of " + currentNode); } } currentNode = (AbstractTypeDeclaration) parentNode; } this.classNameElements = Lists.reverse(typeNames); }
From source file:com.google.currysrc.api.process.ast.TypeLocator.java
License:Apache License
private boolean matchNested(Iterator<String> reverseClassNamesIterator, AbstractTypeDeclaration node) { String subClassName = reverseClassNamesIterator.next(); if (!node.getName().getFullyQualifiedName().equals(subClassName)) { return false; }/*from w w w. j a va 2s . c om*/ if (!reverseClassNamesIterator.hasNext()) { return true; } ASTNode parentNode = node.getParent(); // This won't work with method-declared types. But they're not documented so...? if (!(parentNode instanceof AbstractTypeDeclaration)) { return false; } return matchNested(reverseClassNamesIterator, (AbstractTypeDeclaration) parentNode); }
From source file:com.google.currysrc.api.process.ast.TypeLocator.java
License:Apache License
@Override public AbstractTypeDeclaration find(CompilationUnit cu) { if (!packageMatcher.matches(cu)) { return null; }/* ww w . ja v a2 s .c o m*/ Iterator<String> classNameIterator = classNameElements.iterator(); String topLevelClassName = classNameIterator.next(); for (AbstractTypeDeclaration abstractTypeDeclaration : (List<AbstractTypeDeclaration>) cu.types()) { if (abstractTypeDeclaration.getName().getFullyQualifiedName().equals(topLevelClassName)) { // Top-level interface / class / enum match. return findNested(classNameIterator, abstractTypeDeclaration); } } return null; }
From source file:com.google.currysrc.api.process.ast.TypeLocator.java
License:Apache License
private AbstractTypeDeclaration findNested(Iterator<String> classNameIterator, AbstractTypeDeclaration typeDeclaration) { if (!classNameIterator.hasNext()) { return typeDeclaration; }//from www. jav a 2 s . c o m String subClassName = classNameIterator.next(); for (BodyDeclaration bodyDeclaration : (List<BodyDeclaration>) typeDeclaration.bodyDeclarations()) { if (bodyDeclaration instanceof AbstractTypeDeclaration) { AbstractTypeDeclaration subTypeDeclaration = (AbstractTypeDeclaration) bodyDeclaration; if (subTypeDeclaration.getName().getFullyQualifiedName().equals(subClassName)) { return findNested(classNameIterator, subTypeDeclaration); } } } return null; }