Search in sources :

Example 16 with NormalAnnotation

use of org.eclipse.jdt.core.dom.NormalAnnotation in project eclipse-pmd by acanda.

the class SuppressWarningsQuickFix method createReplacementSuppressWarningsAnnotation.

private Annotation createReplacementSuppressWarningsAnnotation(final Annotation existingAnnotation, final AST ast) {
    final Annotation replacement;
    if (existingAnnotation == null || existingAnnotation.isMarkerAnnotation()) {
        final SingleMemberAnnotation annotation = createAnnotation(ast, SingleMemberAnnotation.class);
        annotation.setValue(createPMDLiteralValue(ast));
        replacement = annotation;
    } else if (existingAnnotation.isSingleMemberAnnotation()) {
        final SingleMemberAnnotation existingSingleMemberAnnotation = (SingleMemberAnnotation) existingAnnotation;
        final SingleMemberAnnotation annotation = createAnnotation(ast, SingleMemberAnnotation.class);
        annotation.setValue(createArrayInitializer(existingSingleMemberAnnotation.getValue()));
        replacement = annotation;
    } else if (existingAnnotation.isNormalAnnotation()) {
        final NormalAnnotation existingNormalAnnotation = (NormalAnnotation) existingAnnotation;
        final NormalAnnotation annotation = createAnnotation(ast, NormalAnnotation.class);
        createAnnotationValues(existingNormalAnnotation, annotation);
        replacement = annotation;
    } else {
        replacement = existingAnnotation;
    }
    return replacement;
}
Also used : SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) Annotation(org.eclipse.jdt.core.dom.Annotation) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation)

Example 17 with NormalAnnotation

use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.

the class RequestMappingSymbolProvider method getContentTypes.

private String[] getContentTypes(Annotation node) {
    if (node.isNormalAnnotation()) {
        NormalAnnotation normNode = (NormalAnnotation) node;
        List<?> values = normNode.values();
        for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
            Object object = iterator.next();
            if (object instanceof MemberValuePair) {
                MemberValuePair pair = (MemberValuePair) object;
                String valueName = pair.getName().getIdentifier();
                if (valueName != null && valueName.equals("produces")) {
                    Expression expression = pair.getValue();
                    return ASTUtils.getExpressionValueAsArray(expression);
                }
            }
        }
    }
    return new String[0];
}
Also used : MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) Expression(org.eclipse.jdt.core.dom.Expression) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation)

Example 18 with NormalAnnotation

use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.

the class RequestMappingSymbolProvider method getAcceptTypes.

private String[] getAcceptTypes(Annotation node) {
    if (node.isNormalAnnotation()) {
        NormalAnnotation normNode = (NormalAnnotation) node;
        List<?> values = normNode.values();
        for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
            Object object = iterator.next();
            if (object instanceof MemberValuePair) {
                MemberValuePair pair = (MemberValuePair) object;
                String valueName = pair.getName().getIdentifier();
                if (valueName != null && valueName.equals("consumes")) {
                    Expression expression = pair.getValue();
                    return ASTUtils.getExpressionValueAsArray(expression);
                }
            }
        }
    }
    return new String[0];
}
Also used : MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) Expression(org.eclipse.jdt.core.dom.Expression) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation)

Example 19 with NormalAnnotation

use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.

the class RequestMappingSymbolProvider method getMethod.

private String[] getMethod(Annotation node) {
    String[] methods = null;
    if (node.isNormalAnnotation()) {
        NormalAnnotation normNode = (NormalAnnotation) node;
        List<?> values = normNode.values();
        for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
            Object object = iterator.next();
            if (object instanceof MemberValuePair) {
                MemberValuePair pair = (MemberValuePair) object;
                String valueName = pair.getName().getIdentifier();
                if (valueName != null && valueName.equals("method")) {
                    Expression expression = pair.getValue();
                    methods = ASTUtils.getExpressionValueAsArray(expression);
                    break;
                }
            }
        }
    } else if (node instanceof SingleMemberAnnotation) {
        methods = getRequestMethod((SingleMemberAnnotation) node);
    }
    if (methods == null && node.getParent() instanceof MethodDeclaration) {
        Annotation parentAnnotation = getParentAnnotation(node);
        if (parentAnnotation != null) {
            methods = getMethod(parentAnnotation);
        }
    }
    return methods;
}
Also used : MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) Expression(org.eclipse.jdt.core.dom.Expression) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) MethodDeclaration(org.eclipse.jdt.core.dom.MethodDeclaration) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) Annotation(org.eclipse.jdt.core.dom.Annotation) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation)

Example 20 with NormalAnnotation

use of org.eclipse.jdt.core.dom.NormalAnnotation in project sts4 by spring-projects.

the class RequestMappingSymbolProvider method getPath.

private String[] getPath(Annotation node) {
    if (node.isNormalAnnotation()) {
        NormalAnnotation normNode = (NormalAnnotation) node;
        List<?> values = normNode.values();
        for (Iterator<?> iterator = values.iterator(); iterator.hasNext(); ) {
            Object object = iterator.next();
            if (object instanceof MemberValuePair) {
                MemberValuePair pair = (MemberValuePair) object;
                String valueName = pair.getName().getIdentifier();
                if (valueName != null && (valueName.equals("value") || valueName.equals("path"))) {
                    Expression expression = pair.getValue();
                    return ASTUtils.getExpressionValueAsArray(expression);
                }
            }
        }
    } else if (node.isSingleMemberAnnotation()) {
        SingleMemberAnnotation singleNode = (SingleMemberAnnotation) node;
        Expression expression = singleNode.getValue();
        return ASTUtils.getExpressionValueAsArray(expression);
    }
    return new String[] { "" };
}
Also used : MemberValuePair(org.eclipse.jdt.core.dom.MemberValuePair) Expression(org.eclipse.jdt.core.dom.Expression) SingleMemberAnnotation(org.eclipse.jdt.core.dom.SingleMemberAnnotation) NormalAnnotation(org.eclipse.jdt.core.dom.NormalAnnotation)

Aggregations

NormalAnnotation (org.eclipse.jdt.core.dom.NormalAnnotation)23 MemberValuePair (org.eclipse.jdt.core.dom.MemberValuePair)13 SingleMemberAnnotation (org.eclipse.jdt.core.dom.SingleMemberAnnotation)10 ASTNode (org.eclipse.jdt.core.dom.ASTNode)9 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)8 MethodDeclaration (org.eclipse.jdt.core.dom.MethodDeclaration)7 Annotation (org.eclipse.jdt.core.dom.Annotation)6 Expression (org.eclipse.jdt.core.dom.Expression)6 ListRewrite (org.eclipse.jdt.core.dom.rewrite.ListRewrite)6 AST (org.eclipse.jdt.core.dom.AST)5 StringLiteral (org.eclipse.jdt.core.dom.StringLiteral)5 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)4 ITypeBinding (org.eclipse.jdt.core.dom.ITypeBinding)4 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)4 HashSet (java.util.HashSet)3 ASTVisitor (org.eclipse.jdt.core.dom.ASTVisitor)3 FieldDeclaration (org.eclipse.jdt.core.dom.FieldDeclaration)3 IMethodBinding (org.eclipse.jdt.core.dom.IMethodBinding)3 ImportDeclaration (org.eclipse.jdt.core.dom.ImportDeclaration)3 PackageDeclaration (org.eclipse.jdt.core.dom.PackageDeclaration)3