Java Code Examples for org.eclipse.jdt.core.dom.AbstractTypeDeclaration#getParent()
The following examples show how to use
org.eclipse.jdt.core.dom.AbstractTypeDeclaration#getParent() .
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: JavaFileParser.java From buck with Apache License 2.0 | 6 votes |
@Nullable private String getFullyQualifiedTypeName(AbstractTypeDeclaration node) { LinkedList<String> nameParts = new LinkedList<>(); nameParts.add(node.getName().toString()); ASTNode parent = node.getParent(); 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); }
Example 2
Source File: ReferencedClassesParser.java From BUILD_file_generator with Apache License 2.0 | 4 votes |
@Override public boolean visit(MethodInvocation node) { visitExpressionIfName(node.getExpression()); if (node.getExpression() != null) { return true; } // node is of the form `methodName(...)`, and not eg., `Foo.methodName()`. org.eclipse.jdt.core.dom.SimpleName simpleName = node.getName(); if (compilationUnit.findDeclaringNode(simpleName.resolveBinding()) != null) { // simpleName is defined somewhere in this compilation unit - so no need to import it. return true; } // Do not report methods that appear in inner/anonymous classes that have a superclass: // Jade doesn't currently fetch inherited symbols for inner/anonymous classes, which // leads to inherited methods being imported. (b/35660499, b/35727475) // This isn't perfect because another class might call a same-named method; if this // becomes a problem, I'll use a blacklist. AbstractTypeDeclaration containingClass = getContainingClass(node); if (!(containingClass.getParent() instanceof CompilationUnit) && containingClass instanceof TypeDeclaration && ((TypeDeclaration) containingClass).getSuperclassType() != null) { return true; } if (isDescendantOfAnonymousClassDeclaration(node)) { return true; } // Work around Eclipse JDT Bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=462192, // where `simpleName.resolveBinding() == null` happens even though 'simpleName' is // defined in the current compilation unit. Set<String> methods = methodsOfClass.get(containingClass); if (methods.isEmpty()) { methods.addAll(getMethodDeclarations(containingClass)); } if (!methods.contains(simpleName.getIdentifier())) { int startPosition = simpleName.getStartPosition(); symbols.put( simpleName.getIdentifier(), Metadata.create( compilationUnit.getLineNumber(startPosition), compilationUnit.getColumnNumber(startPosition), true)); } return true; }