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

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

Introduction

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

Prototype

public boolean isLocalTypeDeclaration() 

Source Link

Document

Returns whether this type declaration is a local type.

Usage

From source file:edu.uci.ics.sourcerer.extractor.ast.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/* www. j  a v a  2 s  .c  o m*/
 *<ul>
 *  <li>For any annotation declaration:
 *  <ul>
 *    <li>Annotation entity to <code>IEntityWriter</code>.</li>
 *    <li>Inside relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@SuppressWarnings("unchecked")
@Override
public boolean visit(AnnotationTypeDeclaration node) {
    // Get the fqn
    String fqn = null;
    if (node.isPackageMemberTypeDeclaration()) {
        fqn = fqnStack.getTypeFqn(node.getName().getIdentifier());
    } else if (node.isMemberTypeDeclaration()) {
        if (node.getName().getIdentifier().length() > 0) {
            fqn = fqnStack.getMemberFqn(node.getName().getIdentifier());
        } else {
            logger.severe("A annotation declaration should not declare an annonymous type!");
            fqn = fqnStack.getAnonymousClassFqn();
        }
    } else if (node.isLocalTypeDeclaration()) {
        ITypeBinding binding = node.resolveBinding();
        fqn = fqnStack.getLocalFqn(node.getName().getIdentifier(), binding);
    } else {
        logger.severe("Unsure what type the declaration is!");
        fqn = "(ERROR)" + node.getName().getIdentifier();
    }

    // Write the entity
    entityWriter.writeAnnotation(fqn, node.getModifiers(),
            MetricsCalculator.computeLinesOfCode(getSource(node)), getLocation(node));

    // Write the inside relation
    relationWriter.writeInside(fqn, fqnStack.getFqn(), getUnknownLocation());

    fqnStack.push(fqn, Entity.ANNOTATION);

    accept(node.getJavadoc());
    accept(node.bodyDeclarations());

    return false;
}

From source file:edu.uci.ics.sourcerer.tools.java.extractor.eclipse.ReferenceExtractorVisitor.java

License:Open Source License

/**
 * This method writes:/*from  w  ww.jav  a2 s.  c  o m*/
 *<ul>
 *  <li>For any annotation declaration:
 *  <ul>
 *    <li>Annotation entity to <code>IEntityWriter</code>.</li>
 *    <li>Inside relation to <code>IRelationWriter</code>.</li>
 *  </ul></li>
 *</ul>
 */
@Override
public boolean visit(AnnotationTypeDeclaration node) {
    // Get the fqn
    String fqn = null;
    if (node.isPackageMemberTypeDeclaration()) {
        fqn = fqnStack.peek(EnclosingPackage.class).getTypeFqn(node.getName().getIdentifier());
    } else if (node.isMemberTypeDeclaration()) {
        if (node.getName().getIdentifier().length() > 0) {
            fqn = fqnStack.peek(EnclosingDeclaredType.class).getMemberFqn(node.getName().getIdentifier());
        } else {
            throw new IllegalStateException("A annotation declaration should not declare an annonymous type!");
        }
    } else if (node.isLocalTypeDeclaration()) {
        ITypeBinding binding = node.resolveBinding();
        if (binding == null) {
            fqn = createUnknownFqn(node.getName().getIdentifier());
        } else {
            fqn = fqnStack.peek(EnclosingBlock.class).getLocalFqn(node.getName().getIdentifier(), binding);
        }
    } else {
        throw new IllegalArgumentException("Unknown annotation type declaration type: " + node);
    }

    // Push the stack
    String parentFqn = fqnStack.getFqn();
    fqnStack.push(fqn, Entity.ANNOTATION);

    // Visit the children
    accept(node.getJavadoc());
    accept(node.modifiers());
    accept(node.bodyDeclarations());

    // Write the entity
    entityWriter.writeEntity(Entity.ANNOTATION, fqn, node.getModifiers(), createMetrics(node),
            createLocation(node));

    // Write the contains relation
    relationWriter.writeRelation(Relation.CONTAINS, parentFqn, fqn, createUnknownLocation());

    // Write the extends relation
    relationWriter.writeRelation(Relation.EXTENDS, fqn, "java.lang.Object", createUnknownLocation());

    // Write the implements relation
    relationWriter.writeRelation(Relation.IMPLEMENTS, fqn, "java.lang.annotation.Annotation",
            createUnknownLocation());

    fqnStack.pop();
    return false;
}