Example usage for org.eclipse.jdt.core.dom Annotation getTypeName

List of usage examples for org.eclipse.jdt.core.dom Annotation getTypeName

Introduction

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

Prototype

public Name getTypeName() 

Source Link

Document

Returns the annotation type name of this annotation.

Usage

From source file:boa.datagen.util.Java7Visitor.java

License:Apache License

protected boa.types.Ast.Modifier.Builder getAnnotationBuilder(Annotation node) {
    boa.types.Ast.Modifier.Builder b = boa.types.Ast.Modifier.newBuilder();
    //      b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Modifier.ModifierKind.ANNOTATION);
    b.setAnnotationName(node.getTypeName().getFullyQualifiedName());
    return b;/*from w  w  w  . j ava  2 s  . c  om*/
}

From source file:boa.datagen.util.JavaVisitor.java

License:Apache License

private boa.types.Ast.Modifier.Builder getAnnotationBuilder(Annotation node) {
    boa.types.Ast.Modifier.Builder b = boa.types.Ast.Modifier.newBuilder();
    //      b.setPosition(pos.build());
    b.setKind(boa.types.Ast.Modifier.ModifierKind.ANNOTATION);
    b.setAnnotationName(node.getTypeName().getFullyQualifiedName());
    return b;//from w  w w .j  a  v a  2  s  . co  m
}

From source file:ch.acanda.eclipse.pmd.java.resolution.SuppressWarningsQuickFix.java

License:Open Source License

private Annotation findExistingSuppressWarningsAnnotation(final List<IExtendedModifier> modifiers) {
    for (final IExtendedModifier modifier : modifiers) {
        if (modifier.isAnnotation()) {
            final Annotation annotation = (Annotation) modifier;
            final Name typeName = annotation.getTypeName();
            if (typeName.isSimpleName() && "SuppressWarnings".equals(typeName.getFullyQualifiedName())
                    || typeName.isQualifiedName()
                            && "java.lang.SuppressWarnings".equals(typeName.getFullyQualifiedName())) {
                return annotation;
            }//from  ww  w .  j  a  v a2 s . c  om
        }
    }
    return null;
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.JavaSyncUtils.java

License:Open Source License

public static Object getLookupKeyForJavaAnnotation(Annotation annotation) {
    StringBuilder key = new StringBuilder(annotation.getTypeName().toString() + '(');

    if (annotation.isSingleMemberAnnotation()) {
        key.append(((SingleMemberAnnotation) annotation).getValue().toString() + ",");
    } else if (annotation.isNormalAnnotation()) {
        for (Object o : ((NormalAnnotation) annotation).values()) {
            MemberValuePair mvp = (MemberValuePair) o;
            key.append(mvp.getName().toString() + "=" + mvp.getValue().toString() + ",");
        }//from  w  ww.ja  v  a 2s  .  c o m
    }
    key.append(')');
    return key.toString();
}

From source file:com.crispico.flower.mp.metamodel.codesyncjava.algorithm.reverse.ReverseJavaAnnotation.java

License:Open Source License

@Override
protected Object getFeatureValueFromAST(EStructuralFeature feature, JavaAnnotationHolder astElement) {
    Annotation annotation = astElement.getAnnotation();

    if (astElement == null)
        throw new IllegalArgumentException("astElement is null");
    switch (feature.getFeatureID()) {
    case EcorePackage.EANNOTATION__SOURCE:
        return annotation.getTypeName().toString();
    case EcorePackage.EANNOTATION__DETAILS:
        if (annotation.isNormalAnnotation()) {
            return ((NormalAnnotation) annotation).values();
        } else if (annotation.isSingleMemberAnnotation()) {
            return ((SingleMemberAnnotation) annotation).getValue();
        } else/*ww  w.  java 2 s .  c om*/
            return null;
    default:
        throw new IllegalArgumentException("Cannot get value for feature in ReverseJavaAnnotation:" + feature);
    }
}

From source file:com.google.devtools.j2cpp.translate.GwtConverter.java

License:Open Source License

private boolean hasAnnotation(Class<?> annotation, List<IExtendedModifier> modifiers) {
    // Annotation bindings don't have the annotation's package.
    String annotationName = annotation.getSimpleName();
    for (IExtendedModifier mod : modifiers) {
        if (mod.isAnnotation()) {
            Annotation annotationNode = (Annotation) mod;
            String modName = annotationNode.getTypeName().getFullyQualifiedName();
            if (modName.equals(annotationName)) {
                if (annotationName.equals("GwtIncompatible") && annotationNode.isSingleMemberAnnotation()) {
                    Expression value = ((SingleMemberAnnotation) annotationNode).getValue();
                    if (value instanceof StringLiteral) {
                        if (compatibleAPIs.contains(((StringLiteral) value).getLiteralValue())) {
                            // Pretend incompatible annotation isn't present, since what it's
                            // flagging is J2ObjC-compatible.
                            return false;
                        }/*from   ww  w .  j a v a2  s. c  o m*/
                    }
                }
                return true;
            }
        }
    }
    return false;
}

From source file:com.google.devtools.j2objc.InputFilePreprocessor.java

License:Apache License

private void extractPackagePrefix(InputFile file, CompilationUnit unit) {
    // We should only reach here if it's a package-info.java file.
    assert file.getUnitName().endsWith("package-info.java");
    @SuppressWarnings("unchecked")
    List<Annotation> annotations = (List<Annotation>) unit.getPackage().annotations();
    for (Annotation annotation : annotations) {
        // getFullyQualifiedName() might not actually return a fully qualified name.
        String name = annotation.getTypeName().getFullyQualifiedName();
        if (name.endsWith("ObjectiveCName")) {
            // Per Eclipse docs, binding resolution can be a resource hog.
            if (annotation.resolveAnnotationBinding().getAnnotationType().getQualifiedName()
                    .equals(ObjectiveCName.class.getCanonicalName())) {
                String key = unit.getPackage().getName().getFullyQualifiedName();
                String val = (String) ((SingleMemberAnnotation) annotation).getValue()
                        .resolveConstantExpressionValue();
                String previousVal = Options.addPackagePrefix(key, val);
                if (previousVal != null && !previousVal.equals(val)) {
                    ErrorUtil.error(String.format(
                            "Package %s has name %s defined in file %s, but" + "is already named %s", key, val,
                            file.getPath(), previousVal));
                }//from  w  w w. ja va 2s .  c o  m
            }
        }
    }
}

From source file:com.google.devtools.j2objc.PackageInfoPreProcessor.java

License:Apache License

protected void processUnit(InputFile file, CompilationUnit unit) {
    // We should only reach here if it's a package-info.java file.
    assert file.getUnitName().endsWith("package-info.java");
    @SuppressWarnings("unchecked")
    List<Annotation> annotations = (List<Annotation>) unit.getPackage().annotations();
    for (Annotation annotation : annotations) {
        // getFullyQualifiedName() might not actually return a fully qualified name.
        String name = annotation.getTypeName().getFullyQualifiedName();
        if (name.endsWith("ObjectiveCName")) {
            // Per Eclipse docs, binding resolution can be a resource hog.
            if (annotation.resolveAnnotationBinding().getAnnotationType().getQualifiedName()
                    .equals(ObjectiveCName.class.getCanonicalName())) {
                String key = unit.getPackage().getName().getFullyQualifiedName();
                String val = (String) ((SingleMemberAnnotation) annotation).getValue()
                        .resolveConstantExpressionValue();
                String previousVal = Options.addPackagePrefix(key, val);
                if (previousVal != null && !previousVal.equals(val)) {
                    ErrorUtil.error(String.format(
                            "Package %s has name %s defined in file %s, but" + "is already named %s", key, val,
                            file.getPath(), previousVal));
                }//from   w  w w  .  j a  v a  2 s.  c  om
            }
        }
    }
}

From source file:com.google.devtools.j2objc.pipeline.InputFilePreprocessor.java

License:Apache License

private void extractPackagePrefix(InputFile file, CompilationUnit unit) {
    // We should only reach here if it's a package-info.java file.
    assert file.getUnitName().endsWith("package-info.java");
    @SuppressWarnings("unchecked")
    List<Annotation> annotations = (List<Annotation>) unit.getPackage().annotations();
    for (Annotation annotation : annotations) {
        // getFullyQualifiedName() might not actually return a fully qualified name.
        String name = annotation.getTypeName().getFullyQualifiedName();
        if (name.endsWith("ObjectiveCName")) {
            // Per Eclipse docs, binding resolution can be a resource hog.
            if (annotation.resolveAnnotationBinding().getAnnotationType().getQualifiedName()
                    .equals(ObjectiveCName.class.getCanonicalName())) {
                String key = unit.getPackage().getName().getFullyQualifiedName();
                String val = (String) ((SingleMemberAnnotation) annotation).getValue()
                        .resolveConstantExpressionValue();
                Options.addPackagePrefix(key, val);
            }/*from  w w w  .  j a  va  2  s . c o m*/
        }
    }
}

From source file:com.google.gdt.eclipse.core.JavaASTUtils.java

License:Open Source License

@SuppressWarnings("unchecked")
public static boolean hasSuppressWarnings(BodyDeclaration decl, String warningType) {
    List<IExtendedModifier> modifiers = decl.modifiers();
    for (IExtendedModifier modifier : modifiers) {
        if (modifier.isAnnotation()) {
            assert (modifier instanceof Annotation);
            Annotation annotation = (Annotation) modifier;

            // Get the (simple) type name of the annotation (we can't resolve the
            // annotation's type if binding resolution is disabled on our AST).
            Name annotationType = annotation.getTypeName();
            if (annotationType.isQualifiedName()) {
                annotationType = ((QualifiedName) annotationType).getName();
            }/*from   ww w  .  j av a  2 s.c  o  m*/
            assert (annotationType.isSimpleName());
            String annotationTypeName = ((SimpleName) annotationType).getIdentifier();

            // Look for @SuppressWarnings annotations
            if (annotationTypeName.equals(SuppressWarnings.class.getSimpleName())) {
                // Now extract the parameter representing the set of warnings that
                // should be suppressed
                if (annotation instanceof SingleMemberAnnotation) {
                    SingleMemberAnnotation suppressWarnings = (SingleMemberAnnotation) annotation;
                    Expression annotationValue = suppressWarnings.getValue();
                    return containsAnnotationValue(annotationValue, warningType);
                } else if (annotation instanceof NormalAnnotation) {
                    NormalAnnotation suppressWarnings = (NormalAnnotation) annotation;
                    List<MemberValuePair> annotationValues = suppressWarnings.values();
                    for (MemberValuePair annotationValue : annotationValues) {
                        SimpleName annotationValueName = annotationValue.getName();
                        if (annotationValueName.getIdentifier().equals("value")) {
                            return containsAnnotationValue(annotationValue.getValue(), warningType);
                        }
                    }
                }

                return false;
            }
        }
    }

    return false;
}