org.eclipse.jdt.core.dom.AbstractTypeDeclaration#getParent ( )源码实例Demo

下面列出了org.eclipse.jdt.core.dom.AbstractTypeDeclaration#getParent ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: buck   文件: JavaFileParser.java
@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);
}
 
@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;
}