Package org.springframework.roo.classpath.details

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


            return typesForModule;
        }

        final Collection<JavaType> types = new ArrayList<JavaType>();
        for (final JavaType javaType : typesForModule) {
            final ClassOrInterfaceTypeDetails typeDetails = typeLocationService
                    .getTypeDetails(javaType);
            if ((optionContext.contains(SUPERCLASS) && (Modifier
                    .isFinal(typeDetails.getModifier()) || typeDetails
                    .getPhysicalTypeCategory() == PhysicalTypeCategory.INTERFACE))
                    || (optionContext.contains(INTERFACE) && typeDetails
                            .getPhysicalTypeCategory() != PhysicalTypeCategory.INTERFACE)) {
                continue;
            }
            types.add(javaType);
        }
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

    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

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId, modifier, name,
                PhysicalTypeCategory.CLASS);

        if (!superclass.equals(OBJECT)) {
            final ClassOrInterfaceTypeDetails superclassClassOrInterfaceTypeDetails = typeLocationService
                    .getTypeDetails(superclass);
            if (superclassClassOrInterfaceTypeDetails != null) {
                cidBuilder
                        .setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(
                                superclassClassOrInterfaceTypeDetails));
            }
        }

        final List<JavaType> extendsTypes = new ArrayList<JavaType>();
        extendsTypes.add(superclass);
        cidBuilder.setExtendsTypes(extendsTypes);

        if (implementsType != null) {
            final Set<JavaType> implementsTypes = new LinkedHashSet<JavaType>();
            final ClassOrInterfaceTypeDetails typeDetails = typeLocationService
                    .getTypeDetails(declaredByMetadataId);
            if (typeDetails != null) {
                implementsTypes.addAll(typeDetails.getImplementsTypes());
            }
            implementsTypes.add(implementsType);
            cidBuilder.setImplementsTypes(implementsTypes);
        }
View Full Code Here

        typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
    }

    @Override
    public void createConstructor(final JavaType name, final Set<String> fields) {
        final ClassOrInterfaceTypeDetails javaTypeDetails = typeLocationService
                .getTypeDetails(name);
        Validate.notNull(javaTypeDetails,
                "The type specified, '%s', doesn't exist",
                name.getFullyQualifiedTypeName());

        final String declaredByMetadataId = PhysicalTypeIdentifier
                .createIdentifier(name,
                        pathResolver.getFocusedPath(Path.SRC_MAIN_JAVA));
        final List<FieldMetadata> constructorFields = new ArrayList<FieldMetadata>();
        final List<? extends FieldMetadata> declaredFields = javaTypeDetails
                .getDeclaredFields();
        if (fields != null) {
            for (final String field : fields) {
                declared: for (final FieldMetadata declaredField : declaredFields) {
                    if (field.equals(declaredField.getFieldName()
                            .getSymbolName())) {
                        constructorFields.add(declaredField);
                        break declared;
                    }
                }
            }
            if (constructorFields.isEmpty()) {
                // User supplied a set of fields that do not exist in the
                // class, so return without creating any constructor
                return;
            }
        }

        // Search for an existing constructor
        final List<JavaType> parameterTypes = new ArrayList<JavaType>();
        for (final FieldMetadata fieldMetadata : constructorFields) {
            parameterTypes.add(fieldMetadata.getFieldType());
        }

        final ConstructorMetadata result = javaTypeDetails
                .getDeclaredConstructor(parameterTypes);
        if (result != null) {
            // Found an existing constructor on this class
            return;
        }
View Full Code Here

            final String metadataIdentificationString,
            final JavaType aspectName,
            final PhysicalTypeMetadata governorPhysicalTypeMetadata,
            final String itdFilename) {
     
        final ClassOrInterfaceTypeDetails permissionEvaluatorClass = governorPhysicalTypeMetadata
                .getMemberHoldingTypeDetails();
        if (permissionEvaluatorClass == null) {
            return null;
        }
       
        JavaType permissionEvaluatorInterface = null;

        for (final JavaType implementedType : permissionEvaluatorClass
                .getImplementsTypes()) {
            if (implementedType.equals(PERMISSION_EVALUATOR)) {
                permissionEvaluatorInterface = implementedType;
                break;
            }
View Full Code Here

        if (usePermissionEvaluator == null || usePermissionEvaluator.getValue() == false){
          continue;
        }
        AnnotationAttributeValue<Collection<ClassAttributeValue>> domainTypes = annotationMetadata.getAttribute("domainTypes");
            for (ClassAttributeValue domainType : domainTypes.getValue()) {
          final ClassOrInterfaceTypeDetails domainTypeDetails = typeLocationService
                      .getTypeDetails(domainType.getValue());
              if (domainTypeDetails == null) {
                  return null;
              }
              final LogicalPath path = PhysicalTypeIdentifier
                      .getPath(domainTypeDetails.getDeclaredByMetadataId());
              final String pluralId = PluralMetadata.createIdentifier(domainType.getValue(),
                      path);
              final PluralMetadata pluralMetadata = (PluralMetadata) metadataService
                      .get(pluralId);
              if (pluralMetadata == null) {
View Full Code Here

                    final JavaType innerType = new JavaType(
                            castMember.getName(), name);
                    final String innerTypeMetadataId = PhysicalTypeIdentifier
                            .createIdentifier(innerType, PhysicalTypeIdentifier
                                    .getPath(declaredByMetadataId));
                    final ClassOrInterfaceTypeDetails cid = new JavaParserClassOrInterfaceTypeDetailsBuilder(
                            compilationUnit, compilationUnitServices,
                            castMember, innerTypeMetadataId, innerType,
                            metadataService, typeLocationService).build();
                    cidBuilder.addInnerType(cid);
                }
View Full Code Here

        // Flag to indicate whether we'll even try to create this metadata
        boolean produceMetadata = false;

        // Determine if we should generate the metadata on the basis of it
        // containing a trigger annotation
        final ClassOrInterfaceTypeDetails cid = governorPhysicalTypeMetadata
                .getMemberHoldingTypeDetails();
        if (cid != null) {
            // Only create metadata if the type is annotated with one of the
            // metadata triggers
            for (final JavaType trigger : metadataTriggers) {
                if (cid.getAnnotation(trigger) != null) {
                    produceMetadata = true;
                    break;
                }
            }
        }

        // Fall back to ignoring trigger annotations
        if (ignoreTriggerAnnotations) {
            produceMetadata = true;
        }

        // Cancel production if the governor type details are required, but
        // aren't available
        if (dependsOnGovernorTypeDetailAvailability && cid == null) {
            produceMetadata = false;
        }

        // Cancel production if the governor is not a class, and the subclass
        // only wants to know about classes
        if (cid != null && dependsOnGovernorBeingAClass
                && cid.getPhysicalTypeCategory() != PhysicalTypeCategory.CLASS) {
            produceMetadata = false;
        }

        final String itdFilename = governorPhysicalTypeMetadata
                .getItdCanonicalPath(this);
        if (!produceMetadata && isGovernor(cid)
                && fileManager.exists(itdFilename)) {
            // We don't seem to want metadata anymore, yet the ITD physically
            // exists, so get rid of it
            // This might be because the trigger annotation has been removed,
            // the governor is missing a class declaration, etc.
            deleteItd(metadataIdentificationString, itdFilename,
                    "not required for governor " + cid.getName(), true);
            return null;
        }

        if (produceMetadata) {
            // This type contains an annotation we were configured to detect, or
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.