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

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


                || identifierAccessorMethod == null) {
            return null;
        }

        String transactionManager = null;
        final AnnotationMetadata jpaActiveRecordAnnotation = memberDetails
                .getAnnotation(ROO_JPA_ACTIVE_RECORD);
        if (jpaActiveRecordAnnotation != null) {
            final StringAttributeValue transactionManagerAttr = (StringAttributeValue) jpaActiveRecordAnnotation
                    .getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
            if (transactionManagerAttr != null) {
                transactionManager = transactionManagerAttr.getValue();
            }
        }
View Full Code Here


    }

    public AnnotationMetadata getAnnotation(final JavaType type) {
        Validate.notNull(type, "Annotation type to locate required");
        for (final MemberHoldingTypeDetails memberHoldingTypeDetails : details) {
            final AnnotationMetadata md = memberHoldingTypeDetails
                    .getAnnotation(type);
            if (md != null) {
                return md;
            }
        }
View Full Code Here

                "The specified target '--type' does not exist or can not be found. Please create this type first.");

        // Check if the requested entity is a JPA @Entity
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(this.getClass().getName(), cid);
        final AnnotationMetadata entityAnnotation = memberDetails
                .getAnnotation(ENTITY);
        final AnnotationMetadata persistentAnnotation = memberDetails
                .getAnnotation(PERSISTENT);
        Validate.isTrue(
                entityAnnotation != null || persistentAnnotation != null,
                "The field reference command is only applicable to JPA @Entity or Spring Data @Persistent target types.");
View Full Code Here

                "The specified target '--type' does not exist or can not be found. Please create this type first.");

        // Check if the requested entity is a JPA @Entity
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(this.getClass().getName(), cid);
        final AnnotationMetadata entityAnnotation = memberDetails
                .getAnnotation(ENTITY);
        final AnnotationMetadata persistentAnnotation = memberDetails
                .getAnnotation(PERSISTENT);

        if (entityAnnotation != null) {
            Validate.isTrue(cardinality == Cardinality.ONE_TO_MANY
                    || cardinality == Cardinality.MANY_TO_MANY,
View Full Code Here

                "The specified target '--type' does not exist or can not be found. Please create this type first.");

        // Check if the requested entity is a JPA @Entity
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(this.getClass().getName(), cid);
        final AnnotationMetadata entityAnnotation = memberDetails
                .getAnnotation(ENTITY);
        final AnnotationMetadata persistentAnnotation = memberDetails
                .getAnnotation(PERSISTENT);

        if (entityAnnotation != null) {
            Validate.isTrue(cardinality == Cardinality.ONE_TO_MANY
                    || cardinality == Cardinality.MANY_TO_MANY,
View Full Code Here

        layerAnnotationType = layerAnnotation;
    }

    @Override
    public Object getTagValue(final MemberHoldingTypeDetails type) {
        final AnnotationMetadata layerAnnotation = MemberFindingUtils
                .getAnnotationOfType(type.getAnnotations(), layerAnnotationType);
        if (layerAnnotation == null
                || layerAnnotation.getAttribute(domainTypesAttribute) == null) {
            return null;
        }
        final AnnotationAttributeValue<?> value = layerAnnotation
                .getAttribute(domainTypesAttribute);
        final List<JavaType> domainTypes = new ArrayList<JavaType>();
        if (value instanceof ClassAttributeValue) {
            domainTypes.add(((ClassAttributeValue) value).getValue());
        }
View Full Code Here

                            replacementAttributeValues.values()));
            addAnnotation(replacement);
            return true;
        }

        final AnnotationMetadata existing = existingBuilder.build();

        // Copy the existing attributes into the new attributes
        for (final JavaSymbolName existingAttributeName : existing
                .getAttributeNames()) {
            if (attributesToDeleteIfPresent != null
                    && attributesToDeleteIfPresent
                            .contains(existingAttributeName)) {
                hasChanged = true;
            }
            else {
                final AnnotationAttributeValue<?> existingValue = existing
                        .getAttribute(existingAttributeName);
                replacementAttributeValues.put(existingAttributeName,
                        existingValue);
            }
        }
View Full Code Here

    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

            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 '"
                            + value + "' for attribute '" + 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 '" + value
                            + "' to end in 'l' or 'L'");
            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

                final JavaSymbolName streamedContentFieldName = new JavaSymbolName(
                        fieldName + "StreamedContent");

                builderMethods.add(getFileUploadListenerMethod(field));

                final AnnotationMetadata annotation = field
                        .getAnnotation(ROO_UPLOADED_FILE);
                final String contentType = (String) annotation.getAttribute(
                        "contentType").getValue();
                final String fileExtension = StringUtils
                        .lowerCase(UploadedFileContentType.getFileExtension(
                                contentType).name());
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.