Package org.springframework.roo.classpath.details

Examples of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails


    public void testSimpleInterfaceNoChanges() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_INTERFACE_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents,
                        SIMPLE_INTERFACE_DECLARED_BY_MID, SIMPLE_INTERFACE_TYPE);

        // Invoke
        final String result = typeParsingService
View Full Code Here


    public void testSimpleClassNoChanges() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID,
                        SIMPLE_CLASS_TYPE);

        // Invoke
        final String result = typeParsingService
View Full Code Here

    public void testSimpleClass2NoChanges() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS2_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS2_DECLARED_BY_MID,
                        SIMPLE_CLASS2_TYPE);

        // Invoke
        final String result = typeParsingService
View Full Code Here

    public void testSimpleClass3NoChanges() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS3_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS3_DECLARED_BY_MID,
                        SIMPLE_CLASS3_TYPE);

        // Invoke
        final String result = typeParsingService
View Full Code Here

    public void testSimpleClass3AddField() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS3_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS3_DECLARED_BY_MID,
                        SIMPLE_CLASS3_TYPE);

        final SetField fieldDetails = new SetField(
                SIMPLE_CLASS3_DECLARED_BY_MID, new JavaType(
                        SET.getFullyQualifiedTypeName(), 0, DataType.TYPE,
                        null, Arrays.asList(SIMPLE_CLASS3_TYPE)),
                new JavaSymbolName("children"), SIMPLE_CLASS3_TYPE,
                Cardinality.ONE_TO_MANY);

        final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
                fieldDetails.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
                new ArrayList<AnnotationMetadataBuilder>(),
                fieldDetails.getFieldName(), fieldDetails.getFieldType());
        fieldBuilder.setFieldInitializer("new HashSet<SimpleClass3>()");

        ClassOrInterfaceTypeDetails newClassDetails = addField(
                simpleInterfaceDetails, fieldBuilder.build());

        // Invoke
        final String result = typeParsingService
                .getCompilationUnitContents(newClassDetails);

        saveResult(file, result, "-addField");

        checkSimple3Class(result);

        assertTrue(result
                .contains("private Set<SimpleClass3> children = new HashSet<SimpleClass3>();"));

        // Add another
        final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService
                .getTypeFromString(result, SIMPLE_CLASS3_DECLARED_BY_MID,
                        SIMPLE_CLASS3_TYPE);

        final ReferenceField fieldDetails2 = new ReferenceField(
                SIMPLE_CLASS3_DECLARED_BY_MID, SIMPLE_CLASS2_TYPE,
                new JavaSymbolName("referenceField"), Cardinality.MANY_TO_ONE);

        final FieldMetadataBuilder fieldBuilder2 = new FieldMetadataBuilder(
                fieldDetails2.getPhysicalTypeIdentifier(), Modifier.PRIVATE,
                new ArrayList<AnnotationMetadataBuilder>(),
                fieldDetails2.getFieldName(), fieldDetails2.getFieldType());

        ClassOrInterfaceTypeDetails newClassDetails2 = addField(
                simpleInterfaceDetails2, fieldBuilder2.build());

        // Invoke
        final String result2 = typeParsingService
                .getCompilationUnitContents(newClassDetails2);
View Full Code Here

    public void testRegresion_ROO_1505() throws Exception {
        // Set up
        final File file = getResource(ROO1505_CLASS_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, ROO1505_CLASS_DECLARED_BY_MID,
                        ROO1505_CLASS_TYPE);

        // Invoke
        final String result = typeParsingService
View Full Code Here

    public void testSimpleClassAddField() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID,
                        SIMPLE_CLASS_TYPE);

        final FieldMetadataBuilder fieldBuilder = new FieldMetadataBuilder(
                SIMPLE_CLASS_DECLARED_BY_MID, Modifier.PRIVATE,
                new JavaSymbolName("newFieldAddedByCode"), new JavaType(
                        String.class), "\"Create by code\"");
        final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addField(
                simpleInterfaceDetails, fieldBuilder.build());

        // Invoke
        final String result = typeParsingService
                .getCompilationUnitContents(newSimpleInterfaceDetails);
View Full Code Here

    public void testSimpleClassAddAnnotation() throws Exception {
        // Set up
        final File file = getResource(SIMPLE_CLASS_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, SIMPLE_CLASS_DECLARED_BY_MID,
                        SIMPLE_CLASS_TYPE);

        final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(
                new JavaType(
                        "org.springframework.roo.addon.tostring.RooToString"));
        final ClassOrInterfaceTypeDetails newSimpleInterfaceDetails = addAnnotation(
                simpleInterfaceDetails, annotationBuilder.build());

        // Invoke
        final String result = typeParsingService
                .getCompilationUnitContents(newSimpleInterfaceDetails);

        // Save to file for debug
        saveResult(file, result, "-addedAnnotation");

        checkSimpleClass(result);

        assertTrue(result
                .contains("import org.springframework.roo.addon.tostring.RooToString;"));
        assertTrue(result.contains("@RooToString"));

        // Invoke again
        final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService
                .getTypeFromString(result, SIMPLE_CLASS_DECLARED_BY_MID,
                        SIMPLE_CLASS_TYPE);

        final String result2 = typeParsingService
                .getCompilationUnitContents(simpleInterfaceDetails2);
View Full Code Here

    protected ItdTypeDetailsProvidingMetadataItem getMetadata(
            final String metadataIdentificationString,
            final JavaType aspectName,
            final PhysicalTypeMetadata governorPhysicalTypeMetadata,
            final String itdFilename) {
        final ClassOrInterfaceTypeDetails serviceClass = governorPhysicalTypeMetadata
                .getMemberHoldingTypeDetails();
        if (serviceClass == null) {
            return null;
        }

        ServiceInterfaceMetadata serviceInterfaceMetadata = null;
        ClassOrInterfaceTypeDetails serviceInterface = null;
        for (final JavaType implementedType : serviceClass.getImplementsTypes()) {
            final ClassOrInterfaceTypeDetails potentialServiceInterfaceTypeDetails = typeLocationService
                    .getTypeDetails(implementedType);
            if (potentialServiceInterfaceTypeDetails != null) {
                final LogicalPath path = PhysicalTypeIdentifier
                        .getPath(potentialServiceInterfaceTypeDetails
                                .getDeclaredByMetadataId());
                final String implementedTypeId = ServiceInterfaceMetadata
                        .createIdentifier(implementedType, path);
                if ((serviceInterfaceMetadata = (ServiceInterfaceMetadata) metadataService
                        .get(implementedTypeId)) != null) {
                    // Found the metadata for the service interface
                    serviceInterface = potentialServiceInterfaceTypeDetails;
                    break;
                }
            }
        }
        if (serviceInterface == null || serviceInterfaceMetadata == null
                || !serviceInterfaceMetadata.isValid()) {
            return null;
        }

        // Register this provider for changes to the service interface // TODO
        // move this down in case we return null early below?
        metadataDependencyRegistry.registerDependency(
                serviceInterfaceMetadata.getId(), metadataIdentificationString);

        final ServiceAnnotationValues serviceAnnotationValues = serviceInterfaceMetadata
                .getServiceAnnotationValues();
        final JavaType[] domainTypes = serviceAnnotationValues.getDomainTypes();
        if (domainTypes == null) {
            return null;
        }

        /*
         * For each domain type, collect (1) the plural and (2) the additions to
         * make to the service class for calling a lower layer when implementing
         * each service layer method. We use LinkedHashMaps for the latter
         * nested map to ensure repeatable order of code generation.
         */
        final Map<JavaType, String> domainTypePlurals = new HashMap<JavaType, String>();
        final Map<JavaType, JavaType> domainTypeToIdTypeMap = new HashMap<JavaType, JavaType>();
        // Collect the additions for each method for each supported domain type
        final Map<JavaType, Map<ServiceLayerMethod, MemberTypeAdditions>> allCrudAdditions = new LinkedHashMap<JavaType, Map<ServiceLayerMethod, MemberTypeAdditions>>();
        for (final JavaType domainType : domainTypes) {

            final JavaType idType = persistenceMemberLocator
                    .getIdentifierType(domainType);
            if (idType == null) {
                return null;
            }
            domainTypeToIdTypeMap.put(domainType, idType);
            // Collect the plural for this domain type

            final ClassOrInterfaceTypeDetails domainTypeDetails = typeLocationService
                    .getTypeDetails(domainType);
            if (domainTypeDetails == null) {
                return null;
            }
            final LogicalPath path = PhysicalTypeIdentifier
                    .getPath(domainTypeDetails.getDeclaredByMetadataId());
            final String pluralId = PluralMetadata.createIdentifier(domainType,
                    path);
            final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
                    .get(pluralId);
            if (pluralMetadata == null) {
                return null;
            }
            domainTypePlurals.put(domainType, pluralMetadata.getPlural());

            // Maintain a list of entities that are being handled by this layer
            managedEntityTypes.put(domainType, metadataIdentificationString);

            // Collect the additions the service class needs in order to invoke
            // each service layer method
            final Map<ServiceLayerMethod, MemberTypeAdditions> methodAdditions = new LinkedHashMap<ServiceLayerMethod, MemberTypeAdditions>();
            for (final ServiceLayerMethod method : ServiceLayerMethod.values()) {
                final Collection<MethodParameter> methodParameters = MethodParameter
                        .asList(method.getParameters(domainType, idType));
                final MemberTypeAdditions memberTypeAdditions = layerService
                        .getMemberTypeAdditions(metadataIdentificationString,
                                method.getKey(), domainType, idType,
                                LAYER_POSITION, methodParameters);
                if (memberTypeAdditions != null) {
                    // A lower layer implements this method
                    methodAdditions.put(method, memberTypeAdditions);
                }
            }
            allCrudAdditions.put(domainType, methodAdditions);

            // Register this provider for changes to the domain type or its
            // plural
            metadataDependencyRegistry.registerDependency(
                    domainTypeDetails.getDeclaredByMetadataId(),
                    metadataIdentificationString);
            metadataDependencyRegistry.registerDependency(pluralId,
                    metadataIdentificationString);
        }

View Full Code Here

            @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs") final String comment,
            @CliOption(key = "primitive", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to use a primitive type") final boolean primitive,
            @CliOption(key = "transient", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to mark the field as transient") final boolean transientModifier,
            @CliOption(key = "permitReservedWords", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether reserved words are ignored by Roo") final boolean permitReservedWords) {

        final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService
                .getTypeDetails(typeName);
        Validate.notNull(javaTypeDetails,
                "The type specified, '%s', doesn't exist", typeName);

        final String physicalTypeIdentifier = javaTypeDetails
                .getDeclaredByMetadataId();
        final BooleanField fieldDetails = new BooleanField(
                physicalTypeIdentifier, primitive ? JavaType.BOOLEAN_PRIMITIVE
                        : JavaType.BOOLEAN_OBJECT, fieldName);
        fieldDetails.setNotNull(notNull);
View Full Code Here

TOP

Related Classes of org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails

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.