Package com.github.antlrjavaparser.api.expr

Examples of com.github.antlrjavaparser.api.expr.NormalAnnotationExpr


            annotationExpression = new SingleMemberAnnotationExpr(nameToUse,
                    toUse);
        }
        else {
            // We have a number of pairs being presented
            annotationExpression = new NormalAnnotationExpr(nameToUse,
                    new ArrayList<MemberValuePair>());
        }

        // Add our AnnotationExpr to the actual annotations that will eventually
        // be flushed through to the compilation unit
        JavaParserCommentMetadataBuilder.updateCommentsToJavaParser(
                annotationExpression, annotation.getCommentStructure());
        annotations.add(annotationExpression);

        // Add member-value pairs to our AnnotationExpr
        if (!memberValuePairs.isEmpty()) {
            // Have to check here for cases where we need to change an existing
            // MarkerAnnotationExpr to a NormalAnnotationExpr or
            // SingleMemberAnnotationExpr
            if (annotationExpression instanceof MarkerAnnotationExpr) {
                final MarkerAnnotationExpr mae = (MarkerAnnotationExpr) annotationExpression;

                annotations.remove(mae);

                if (memberValuePairs.size() == 1
                        && (memberValuePairs.get(0).getName() == null || "value"
                                .equals(memberValuePairs.get(0).getName()))) {
                    final Expression toUse = JavaParserUtils
                            .importExpressionIfRequired(compilationUnitServices
                                    .getEnclosingTypeName(),
                                    compilationUnitServices.getImports(),
                                    memberValuePairs.get(0).getValue());
                    annotationExpression = new SingleMemberAnnotationExpr(
                            nameToUse, toUse);
                    JavaParserCommentMetadataBuilder
                            .updateCommentsToJavaParser(annotationExpression,
                                    annotation.getCommentStructure());
                    annotations.add(annotationExpression);
                }
                else {
                    // We have a number of pairs being presented
                    annotationExpression = new NormalAnnotationExpr(nameToUse,
                            new ArrayList<MemberValuePair>());
                    JavaParserCommentMetadataBuilder
                            .updateCommentsToJavaParser(annotationExpression,
                                    annotation.getCommentStructure());
                    annotations.add(annotationExpression);
                }
            }
            if (annotationExpression instanceof SingleMemberAnnotationExpr) {
                // Potentially upgrade this expression to a NormalAnnotationExpr
                final SingleMemberAnnotationExpr smae = (SingleMemberAnnotationExpr) annotationExpression;
                if (memberValuePairs.size() == 1
                        && memberValuePairs.get(0).getName() == null
                        || memberValuePairs.get(0).getName().equals("value")
                        || memberValuePairs.get(0).getName().equals("")) {
                    // They specified only a single member-value pair, and it is
                    // the default anyway, so we need not do anything except
                    // update the value
                    final Expression toUse = JavaParserUtils
                            .importExpressionIfRequired(compilationUnitServices
                                    .getEnclosingTypeName(),
                                    compilationUnitServices.getImports(),
                                    memberValuePairs.get(0).getValue());
                    smae.setMemberValue(toUse);
                    return;
                }

                // There is > 1 expression, or they have provided some sort of
                // non-default value, so it's time to upgrade the expression
                // (whilst retaining any potentially existing expression values)
                final Expression existingValue = smae.getMemberValue();
                annotationExpression = new NormalAnnotationExpr(smae.getName(),
                        new ArrayList<MemberValuePair>());
                ((NormalAnnotationExpr) annotationExpression).getPairs().add(
                        new MemberValuePair("value", existingValue));
            }
            Validate.isInstanceOf(
View Full Code Here


                for (final JavaSymbolName attributeName : nestedAnnotation
                        .getAttributeNames()) {
                    memberValuePairs.add(convert(nestedAnnotation
                            .getAttribute(attributeName)));
                }
                annotationExpr = new NormalAnnotationExpr(
                        JavaParserUtils.getNameExpr(nestedAnnotation
                                .getAnnotationType()
                                .getFullyQualifiedTypeName()), memberValuePairs);
            }
            // Rely on the nested instance to know its member value pairs
View Full Code Here

                annotationPairs.add(new MemberValuePair("value", a
                        .getMemberValue()));
            }
        }
        else if (annotationExpr instanceof NormalAnnotationExpr) {
            final NormalAnnotationExpr a = (NormalAnnotationExpr) annotationExpr;
            // Must iterate over the expressions
            if (a.getPairs() != null) {
                annotationPairs = a.getPairs();
            }
        }

        // Iterate over the annotation attributes, creating our parsed
        // attributes map
View Full Code Here

                    "Unable to determine annotation name from '%s'",
                    annotationExpr);
            return nameToFind;
        }
        else if (annotationExpr instanceof NormalAnnotationExpr) {
            final NormalAnnotationExpr a = (NormalAnnotationExpr) annotationExpr;
            final NameExpr nameToFind = a.getName();
            Validate.notNull(nameToFind,
                    "Unable to determine annotation name from '%s'",
                    annotationExpr);
            return nameToFind;
        }
View Full Code Here

TOP

Related Classes of com.github.antlrjavaparser.api.expr.NormalAnnotationExpr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.