Package org.springframework.roo.classpath.details

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


            @CliOption(key = "type", mandatory = true, optionContext = PROJECT, help = "The Java type of the @Embeddable class") final JavaType fieldType,
            @CliOption(key = "class", mandatory = false, unspecifiedDefaultValue = "*", optionContext = UPDATE_PROJECT, help = "The name of the @Entity class to receive this field") final JavaType typeName,
            @CliOption(key = "permitReservedWords", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether reserved words are ignored by Roo") final boolean permitReservedWords) {

        // Check if the field type is a JPA @Embeddable class
        final ClassOrInterfaceTypeDetails cid = typeLocationService
                .getTypeDetails(fieldType);
        Validate.notNull(
                cid,
                "The specified target '--type' does not exist or can not be found. Please create this type first.");
        Validate.notNull(cid.getAnnotation(EMBEDDABLE),
                "The field embedded command is only applicable to JPA @Embeddable field types.");

        // Check if the requested entity is a JPA @Entity
        final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService
                .getTypeDetails(typeName);
        Validate.notNull(javaTypeDetails,
                "The type specified, '%s', doesn't exist", typeName);

        final String physicalTypeIdentifier = javaTypeDetails
                .getDeclaredByMetadataId();
        final PhysicalTypeMetadata targetTypeMetadata = (PhysicalTypeMetadata) metadataService
                .get(physicalTypeIdentifier);
        Validate.notNull(
                targetTypeMetadata,
                "The specified target '--class' does not exist or can not be found. Please create this type first.");
        final PhysicalTypeDetails targetPtd = targetTypeMetadata
                .getMemberHoldingTypeDetails();
        Validate.isInstanceOf(MemberHoldingTypeDetails.class, targetPtd);

        final ClassOrInterfaceTypeDetails targetTypeCid = (ClassOrInterfaceTypeDetails) targetPtd;
        final MemberDetails memberDetails = memberDetailsScanner
                .getMemberDetails(this.getClass().getName(), targetTypeCid);
        Validate.isTrue(
                memberDetails.getAnnotation(ENTITY) != null
                        || memberDetails.getAnnotation(PERSISTENT) != null,
View Full Code Here


        if (CollectionUtils.isEmpty(repositories)) {
            return null;
        }

        // Use the first such repository (could refine this later)
        final ClassOrInterfaceTypeDetails repository = repositories.iterator()
                .next();

        // Return the additions the caller needs to make
        return getMethodAdditions(callerMID, method, repository.getName(),
                Arrays.asList(callerParameters));
    }
View Full Code Here

            @CliOption(key = "enumType", mandatory = false, help = "The fetch semantics at a JPA level") final EnumType enumType,
            @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs") final String comment,
            @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 cid = typeLocationService
                .getTypeDetails(typeName);
        Validate.notNull(cid, "The type specified, '%s', doesn't exist",
                typeName);

        final String physicalTypeIdentifier = cid.getDeclaredByMetadataId();
        final EnumField fieldDetails = new EnumField(physicalTypeIdentifier,
                fieldType, fieldName);
        if (column != null) {
            fieldDetails.setColumn(column);
        }
View Full Code Here

            @CliOption(key = "transient", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to mark the field as transient") final boolean transientModifier,
            @CliOption(key = "primitive", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates to use a primitive type if possible") final boolean primitive,
            @CliOption(key = "unique", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Indicates whether to mark the field with a unique constraint") final boolean unique,
            @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();
        if (primitive
                && legalNumericPrimitives.contains(fieldType
                        .getFullyQualifiedTypeName())) {
            fieldType = new JavaType(fieldType.getFullyQualifiedTypeName(), 0,
View Full Code Here

        // Set up
        final JavaType mockTargetType = mock(JavaType.class);
        when(mockTargetType.getSimpleTypeName()).thenReturn("NoSuchType");

        // Invoke
        final ClassOrInterfaceTypeDetails locatedType = typeParsingService
                .getTypeFromString(SOURCE_FILE, DECLARED_BY_MID, mockTargetType);

        // Check
        assertNull(locatedType);
    }
View Full Code Here

            @CliOption(key = "fetch", mandatory = false, help = "The fetch semantics at a JPA level") final Fetch fetch,
            @CliOption(key = "comment", mandatory = false, help = "An optional comment for JavaDocs") final String comment,
            @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 cid = typeLocationService
                .getTypeDetails(fieldType);
        Validate.notNull(
                cid,
                "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.");

        Validate.isTrue(cardinality == Cardinality.MANY_TO_ONE
                || cardinality == Cardinality.ONE_TO_ONE,
                "Cardinality must be MANY_TO_ONE or ONE_TO_ONE for the field reference command");

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

        final String physicalTypeIdentifier = javaTypeDetails
                .getDeclaredByMetadataId();
        final ReferenceField fieldDetails = new ReferenceField(
                physicalTypeIdentifier, fieldType, fieldName, cardinality);
        fieldDetails.setNotNull(notNull);
        fieldDetails.setNullRequired(nullRequired);
View Full Code Here

    public void testGetTypeFromStringWhenFileContainsNoTypes() {
        // Set up
        final JavaType mockTargetType = mock(JavaType.class);

        // Invoke
        final ClassOrInterfaceTypeDetails locatedType = typeParsingService
                .getTypeFromString(EMPTY_FILE, DECLARED_BY_MID, mockTargetType);

        // Check
        assertNull(locatedType);
    }
View Full Code Here

    public void testGetTypeFromStringWhenFileContainsThatType()
            throws Exception {
        // Set up
        final JavaType mockTargetType = mock(JavaType.class);
        final TypeDeclaration mockTypeDeclaration = mock(TypeDeclaration.class);
        final ClassOrInterfaceTypeDetails mockClassOrInterfaceTypeDetails = mock(ClassOrInterfaceTypeDetails.class);
        final JavaParserClassOrInterfaceTypeDetailsBuilder mockBuilder = mock(JavaParserClassOrInterfaceTypeDetailsBuilder.class);
        when(mockBuilder.build()).thenReturn(mockClassOrInterfaceTypeDetails);

        mockStatic(JavaParserUtils.class);
        when(
                JavaParserUtils.locateTypeDeclaration(
                        any(CompilationUnit.class), eq(mockTargetType)))
                .thenReturn(mockTypeDeclaration);

        mockStatic(JavaParserClassOrInterfaceTypeDetailsBuilder.class);
        when(
                JavaParserClassOrInterfaceTypeDetailsBuilder.getInstance(
                        any(CompilationUnit.class),
                        (CompilationUnitServices) eq(null),
                        eq(mockTypeDeclaration), eq(DECLARED_BY_MID),
                        eq(mockTargetType), eq(mockMetadataService),
                        eq(mockTypeLocationService))).thenReturn(mockBuilder);

        // Invoke
        final ClassOrInterfaceTypeDetails locatedType = typeParsingService
                .getTypeFromString(SOURCE_FILE, DECLARED_BY_MID, mockTargetType);

        // Check
        assertSame(mockClassOrInterfaceTypeDetails, locatedType);
    }
View Full Code Here

        // 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 testEnumNoChanges() throws Exception {
        // Set up
        final File file = getResource(ENUM_FILE_PATH);
        final String fileContents = getResourceContents(file);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails = typeParsingService
                .getTypeFromString(fileContents, ENUM_DECLARED_BY_MID,
                        ENUM_TYPE);

        // Invoke
        final String result = typeParsingService
                .updateAndGetCompilationUnitContents(file.getCanonicalPath(),
                        simpleInterfaceDetails);

        saveResult(file, result);

        final ClassOrInterfaceTypeDetails simpleInterfaceDetails2 = typeParsingService
                .getTypeFromString(result, ENUM_DECLARED_BY_MID, ENUM_TYPE);

        typeParsingService.updateAndGetCompilationUnitContents(
                file.getCanonicalPath(), simpleInterfaceDetails2);
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.