Example usage for org.eclipse.jdt.core.dom AbstractTypeDeclaration isLocalTypeDeclaration

List of usage examples for org.eclipse.jdt.core.dom AbstractTypeDeclaration isLocalTypeDeclaration

Introduction

In this page you can find the example usage for org.eclipse.jdt.core.dom AbstractTypeDeclaration isLocalTypeDeclaration.

Prototype

public boolean isLocalTypeDeclaration() 

Source Link

Document

Returns whether this type declaration is a local type.

Usage

From source file:com.google.currysrc.api.process.ast.TypeLocator.java

License:Apache License

/**
 * Creates a {@code TypeLocator} for the specified {@link ASTNode}.
 *//*  w  ww  .  j  a  v a  2 s.  co 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);
}