Package org.springframework.roo.classpath.details.annotations

Examples of org.springframework.roo.classpath.details.annotations.AnnotationMetadata


    private static MemberValuePair convert(
            final AnnotationAttributeValue<?> value) {
        if (value instanceof NestedAnnotationAttributeValue) {
            final NestedAnnotationAttributeValue castValue = (NestedAnnotationAttributeValue) value;
            AnnotationExpr annotationExpr;
            final AnnotationMetadata nestedAnnotation = castValue.getValue();
            if (castValue.getValue().getAttributeNames().size() == 0) {
                annotationExpr = new MarkerAnnotationExpr(
                        JavaParserUtils.getNameExpr(nestedAnnotation
                                .getAnnotationType()
                                .getFullyQualifiedTypeName()));
            }
            else if (castValue.getValue().getAttributeNames().size() == 1) {
                annotationExpr = new SingleMemberAnnotationExpr(
                        JavaParserUtils.getNameExpr(nestedAnnotation
                                .getAnnotationType()
                                .getFullyQualifiedTypeName()), convert(
                                nestedAnnotation.getAttribute(nestedAnnotation
                                        .getAttributeNames().get(0)))
                                .getValue());
            }
            else {
                final List<MemberValuePair> memberValuePairs = new ArrayList<MemberValuePair>();
                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
            return new MemberValuePair(value.getName().getSymbolName(),
View Full Code Here


    @Override
    public AnnotationMetadata build() {
        final AnnotationMetadataBuilder annotationMetadataBuilder = new AnnotationMetadataBuilder(
                annotationType, attributeValues);

        final AnnotationMetadata md = annotationMetadataBuilder.build();
        md.setCommentStructure(commentStructure);

        return md;
    }
View Full Code Here

            annotationName = new JavaSymbolName("__ARRAY_ELEMENT__");
        }

        if (expression instanceof AnnotationExpr) {
            final AnnotationExpr annotationExpr = (AnnotationExpr) expression;
            final AnnotationMetadata value = getInstance(annotationExpr,
                    compilationUnitServices).build();
            return new NestedAnnotationAttributeValue(annotationName, value);
        }

        if (expression instanceof BooleanLiteralExpr) {
            final boolean value = ((BooleanLiteralExpr) expression).getValue();
            return new BooleanAttributeValue(annotationName, value);
        }

        if (expression instanceof CharLiteralExpr) {
            final String value = ((CharLiteralExpr) expression).getValue();
            Validate.isTrue(
                    value.length() == 1,
                    "Expected a char expression, but instead received '%s' for attribute '%s'",
                    value, annotationName);
            final char c = value.charAt(0);
            return new CharAttributeValue(annotationName, c);
        }

        if (expression instanceof LongLiteralExpr) {
            String value = ((LongLiteralExpr) expression).getValue();
            Validate.isTrue(
                    value.toUpperCase().endsWith("L"),
                    "Expected long literal expression '%s' to end in 'l' or 'L'",
                    value);
            value = value.substring(0, value.length() - 1);
            final long l = new Long(value);
            return new LongAttributeValue(annotationName, l);
        }

        if (expression instanceof IntegerLiteralExpr) {
            final String value = ((IntegerLiteralExpr) expression).getValue();
            final int i = new Integer(value);
            return new IntegerAttributeValue(annotationName, i);
        }

        if (expression instanceof DoubleLiteralExpr) {
            String value = ((DoubleLiteralExpr) expression).getValue();
            boolean floatingPrecisionOnly = false;
            if (value.toUpperCase().endsWith("F")) {
                value = value.substring(0, value.length() - 1);
                floatingPrecisionOnly = true;
            }
            if (value.toUpperCase().endsWith("D")) {
                value = value.substring(0, value.length() - 1);
            }
            final double d = new Double(value);
            return new DoubleAttributeValue(annotationName, d,
                    floatingPrecisionOnly);
        }

        if (expression instanceof BinaryExpr) {
            String result = "";
            BinaryExpr current = (BinaryExpr) expression;
            while (current != null) {
                String right = "";
                if (current.getRight() instanceof StringLiteralExpr) {
                    right = ((StringLiteralExpr) current.getRight()).getValue();
                }
                else if (current.getRight() instanceof NameExpr) {
                    right = ((NameExpr) current.getRight()).getName();
                }

                result = right + result;
                if (current.getLeft() instanceof StringLiteralExpr) {
                    final String left = ((StringLiteralExpr) current.getLeft())
                            .getValue();
                    result = left + result;
                }
                if (current.getLeft() instanceof BinaryExpr) {
                    current = (BinaryExpr) current.getLeft();
                }
                else {
                    current = null;
                }
            }
            return new StringAttributeValue(annotationName, result);
        }

        if (expression instanceof StringLiteralExpr) {
            final String value = ((StringLiteralExpr) expression).getValue();
            return new StringAttributeValue(annotationName, value);
        }

        if (expression instanceof FieldAccessExpr) {
            final FieldAccessExpr field = (FieldAccessExpr) expression;
            final String fieldName = field.getField();

            // Determine the type
            final Expression scope = field.getScope();
            NameExpr nameToFind = null;
            if (scope instanceof FieldAccessExpr) {
                final FieldAccessExpr fScope = (FieldAccessExpr) scope;
                nameToFind = JavaParserUtils.getNameExpr(fScope.toString());
            }
            else if (scope instanceof NameExpr) {
                nameToFind = (NameExpr) scope;
            }
            else {
                throw new UnsupportedOperationException(
                        "A FieldAccessExpr for '"
                                + field.getScope()
                                + "' should return a NameExpr or FieldAccessExpr (was "
                                + field.getScope().getClass().getName() + ")");
            }
            final JavaType fieldType = JavaParserUtils.getJavaType(
                    compilationUnitServices, nameToFind, null);

            final EnumDetails enumDetails = new EnumDetails(fieldType,
                    new JavaSymbolName(fieldName));
            return new EnumAttributeValue(annotationName, enumDetails);
        }

        if (expression instanceof NameExpr) {
            final NameExpr field = (NameExpr) expression;
            final String name = field.getName();
            // As we have no way of finding out the real type
            final JavaType fieldType = new JavaType("unknown.Object");
            final EnumDetails enumDetails = new EnumDetails(fieldType,
                    new JavaSymbolName(name));
            return new EnumAttributeValue(annotationName, enumDetails);
        }

        if (expression instanceof ClassExpr) {
            final ClassExpr clazz = (ClassExpr) expression;
            final Type nameToFind = clazz.getType();
            final JavaType javaType = JavaParserUtils.getJavaType(
                    compilationUnitServices, nameToFind, null);
            return new ClassAttributeValue(annotationName, javaType);
        }

        if (expression instanceof ArrayInitializerExpr) {
            final ArrayInitializerExpr castExp = (ArrayInitializerExpr) expression;
            final List<AnnotationAttributeValue<?>> arrayElements = new ArrayList<AnnotationAttributeValue<?>>();
            for (final Expression e : castExp.getValues()) {
                arrayElements.add(convert(null, e, compilationUnitServices));
            }
            return new ArrayAttributeValue<AnnotationAttributeValue<?>>(
                    annotationName, arrayElements);
        }

        if (expression instanceof UnaryExpr) {
            final UnaryExpr castExp = (UnaryExpr) expression;
            if (castExp.getOperator() == Operator.negative) {
                String value = castExp.toString();
                value = value.toUpperCase().endsWith("L") ? value.substring(0,
                        value.length() - 1) : value;
                final long l = new Long(value);
                return new LongAttributeValue(annotationName, l);
            }
            else {
                throw new UnsupportedOperationException(
View Full Code Here

    public AnnotationMetadata getTypeAnnotation(final JavaType annotationType) {
        Validate.notNull(annotationType, "Annotation type required");
        IdentifiableAnnotatedJavaStructure current = this;
        while (current != null) {
            final AnnotationMetadata result = current
                    .getAnnotation(annotationType);
            if (result != null) {
                return result;
            }
            if (current instanceof ClassOrInterfaceTypeDetails) {
View Full Code Here

        bodyBuilder.appendFormalLine("menuModel = new DefaultMenuModel();");
        bodyBuilder.appendFormalLine("Submenu submenu;");
        bodyBuilder.appendFormalLine("MenuItem item;");

        for (final ClassOrInterfaceTypeDetails managedBean : managedBeans) {
            final AnnotationMetadata annotation = MemberFindingUtils
                    .getAnnotationOfType(managedBean.getAnnotations(),
                            ROO_JSF_MANAGED_BEAN);
            if (annotation == null) {
                continue;
            }

            final AnnotationAttributeValue<?> includeOnMenuAttributeValue = annotation
                    .getAttribute(new JavaSymbolName("includeOnMenu"));
            if (includeOnMenuAttributeValue != null
                    && !((Boolean) includeOnMenuAttributeValue.getValue())
                            .booleanValue()) {
                continue;
            }

            final AnnotationAttributeValue<?> entityAttributeValue = annotation
                    .getAttribute(new JavaSymbolName("entity"));
            final JavaType entity = (JavaType) entityAttributeValue.getValue();
            final String entityLabel = entity.getSimpleTypeName().length() > 26 ? entity
                    .getSimpleTypeName().substring(0, 23) + "..."
                    : entity.getSimpleTypeName();

            final AnnotationAttributeValue<?> beanNameAttributeValue = annotation
                    .getAttribute(new JavaSymbolName("beanName"));
            final String beanName = (String) beanNameAttributeValue.getValue();

            bodyBuilder.appendFormalLine("");
            bodyBuilder.appendFormalLine("submenu = new Submenu();");
View Full Code Here

            members = enumClazz.getMembers();
        }

        if (annotationsList != null) {
            for (final AnnotationExpr candidate : annotationsList) {
                final AnnotationMetadata md = JavaParserAnnotationMetadataBuilder
                        .getInstance(candidate, compilationUnitServices)
                        .build();
                cidBuilder.addAnnotation(md);
            }
        }
View Full Code Here

                        compilationUnitServices, pt, fullTypeParameters);
                final List<AnnotationExpr> annotationsList = p.getAnnotations();
                final List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
                if (annotationsList != null) {
                    for (final AnnotationExpr candidate : annotationsList) {
                        final AnnotationMetadata annotationMetadata = JavaParserAnnotationMetadataBuilder
                                .getInstance(candidate, compilationUnitServices)
                                .build();
                        annotations.add(annotationMetadata);
                    }
                }
View Full Code Here

    }

    private String convertToInitializer(final FieldMetadata field) {
        String initializer = " ";
        short index = 1;
        final AnnotationMetadata min = MemberFindingUtils.getAnnotationOfType(
                field.getAnnotations(), MIN);
        if (min != null) {
            final AnnotationAttributeValue<?> value = min
                    .getAttribute(new JavaSymbolName("value"));
            if (value != null) {
                index = new Short(value.getValue().toString());
            }
        }
        final JavaType fieldType = field.getFieldType();
        if (field.getFieldName().getSymbolName().contains("email")
                || field.getFieldName().getSymbolName().contains("Email")) {
            initializer = "some@email.com";
        }
        else if (fieldType.equals(JavaType.STRING)) {
            initializer = "some"
                    + field.getFieldName()
                            .getSymbolNameCapitalisedFirstLetter() + index;
        }
        else if (fieldType.equals(new JavaType(Date.class.getName()))
                || fieldType.equals(new JavaType(Calendar.class.getName()))) {
            final Calendar cal = Calendar.getInstance();
            AnnotationMetadata dateTimeFormat = null;
            String style = null;
            if ((dateTimeFormat = MemberFindingUtils.getAnnotationOfType(
                    field.getAnnotations(), DATE_TIME_FORMAT)) != null) {
                final AnnotationAttributeValue<?> value = dateTimeFormat
                        .getAttribute(new JavaSymbolName("style"));
                if (value != null) {
                    style = value.getValue().toString();
                }
            }
View Full Code Here

        // If useXmlConfiguration is true, do not add @Service
        if (!serviceAnnotationValues.useXmlConfiguration()) {
            // Introduce the @Service annotation via the ITD if it's not already
            // on
            // the service's Java class
            final AnnotationMetadata serviceAnnotation = new AnnotationMetadataBuilder(
                    SERVICE).build();
            if (!governorDetails.isRequestingAnnotatedWith(serviceAnnotation,
                    getId())) {
                builder.addAnnotation(serviceAnnotation);
            }
        }

        // Introduce the @Transactional annotation via the ITD if it's not
        // already on the service's Java class
        if (serviceAnnotationValues.isTransactional()) {
            final AnnotationMetadata transactionalAnnotation = new AnnotationMetadataBuilder(
                    TRANSACTIONAL).build();
            if (!governorDetails.isRequestingAnnotatedWith(
                    transactionalAnnotation, getId())) {
                builder.addAnnotation(transactionalAnnotation);
            }
View Full Code Here

        // Otherwise we look through all DoD-annotated classes for this entity's
        // one
        for (final ClassOrInterfaceTypeDetails dodType : typeLocationService
                .findClassesOrInterfaceDetailsWithAnnotation(ROO_DATA_ON_DEMAND)) {
            final AnnotationMetadata dodAnnotation = MemberFindingUtils
                    .getFirstAnnotation(dodType, ROO_DATA_ON_DEMAND);
            if (dodAnnotation != null
                    && dodAnnotation.getAttribute("entity").getValue()
                            .equals(entity)) {
                return dodType.getName();
            }
        }
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.annotations.AnnotationMetadata

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.