Search in sources :

Example 76 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class DefaultPhysicalTypeMetadataProvider method get.

public MetadataItem get(final String metadataIdentificationString) {
    if (fileManager == null) {
        fileManager = getFileManager();
    }
    Validate.notNull(fileManager, "FileManager is required");
    if (metadataDependencyRegistry == null) {
        metadataDependencyRegistry = getMetadataDependencyRegistry();
    }
    Validate.notNull(metadataDependencyRegistry, "MetadataDependencyRegistry is required");
    if (projectOperations == null) {
        projectOperations = getProjectOperations();
    }
    Validate.notNull(projectOperations, "ProjectOperations is required");
    if (typeLocationService == null) {
        typeLocationService = getTypeLocationService();
    }
    Validate.notNull(typeLocationService, "TypeLocationService is required");
    if (typeParsingService == null) {
        typeParsingService = getTypeParsingService();
    }
    Validate.notNull(typeParsingService, "TypeParsingService is required");
    Validate.isTrue(PhysicalTypeIdentifier.isValid(metadataIdentificationString), "Metadata id '%s' is not valid for this metadata provider", metadataIdentificationString);
    final String canonicalPath = typeLocationService.getPhysicalTypeCanonicalPath(metadataIdentificationString);
    if (StringUtils.isBlank(canonicalPath)) {
        return null;
    }
    metadataDependencyRegistry.deregisterDependencies(metadataIdentificationString);
    if (!fileManager.exists(canonicalPath)) {
        // that was found but could not be parsed
        return null;
    }
    final JavaType javaType = PhysicalTypeIdentifier.getJavaType(metadataIdentificationString);
    final ClassOrInterfaceTypeDetails typeDetails = typeParsingService.getTypeAtLocation(canonicalPath, metadataIdentificationString, javaType);
    if (typeDetails == null) {
        return null;
    }
    final PhysicalTypeMetadata result = new DefaultPhysicalTypeMetadata(metadataIdentificationString, canonicalPath, typeDetails);
    final ClassOrInterfaceTypeDetails details = result.getMemberHoldingTypeDetails();
    if (details != null && details.getPhysicalTypeCategory() == PhysicalTypeCategory.CLASS && details.getExtendsTypes().size() == 1) {
        // This is a class, and it extends another class
        if (details.getSuperclass() != null) {
            // We have a dependency on the superclass, and there is metadata
            // available for the superclass
            // We won't implement the full MetadataNotificationListener
            // here, but rely on MetadataService's fallback
            // (which is to evict from cache and call get again given
            // JavaParserMetadataProvider doesn't implement
            // MetadataNotificationListener, then notify everyone we've
            // changed)
            final String superclassId = details.getSuperclass().getDeclaredByMetadataId();
            metadataDependencyRegistry.registerDependency(superclassId, result.getId());
        } else {
            // type change, in the hope we discover our parent someday
            for (final LogicalPath sourcePath : projectOperations.getPathResolver().getSourcePaths()) {
                final String possibleSuperclass = PhysicalTypeIdentifier.createIdentifier(details.getExtendsTypes().get(0), sourcePath);
                metadataDependencyRegistry.registerDependency(possibleSuperclass, result.getId());
            }
        }
    }
    MemberDetails memberDetails = new MemberDetailsBuilder(Arrays.asList(details)).build();
    // Loop until such time as we complete a full loop where no changes are
    // made to the result
    boolean additionalLoopRequired = true;
    while (additionalLoopRequired) {
        additionalLoopRequired = false;
        for (final MemberDetailsDecorator decorator : decorators) {
            final MemberDetails newResult = decorator.decorateTypes(DefaultPhysicalTypeMetadataProvider.class.getName(), memberDetails);
            Validate.isTrue(newResult != null, "Decorator '%s' returned an illegal result", decorator.getClass().getName());
            if (!newResult.equals(memberDetails)) {
                additionalLoopRequired = true;
                memberDetails = newResult;
            }
        }
    }
    return new DefaultPhysicalTypeMetadata(metadataIdentificationString, canonicalPath, (ClassOrInterfaceTypeDetails) memberDetails.getDetails().get(0));
}
Also used : JavaType(org.springframework.roo.model.JavaType) DefaultPhysicalTypeMetadata(org.springframework.roo.classpath.details.DefaultPhysicalTypeMetadata) DefaultPhysicalTypeMetadata(org.springframework.roo.classpath.details.DefaultPhysicalTypeMetadata) LogicalPath(org.springframework.roo.project.LogicalPath) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) MemberDetailsBuilder(org.springframework.roo.classpath.scanner.MemberDetailsBuilder) MemberDetailsDecorator(org.springframework.roo.classpath.scanner.MemberDetailsDecorator)

Example 77 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class TypeLocationServiceImpl method updateAttributeCache.

private void updateAttributeCache(final MemberHoldingTypeDetails cid) {
    Validate.notNull(cid, "Member holding type details required");
    if (!typeAnnotationMap.containsKey(cid.getDeclaredByMetadataId())) {
        typeAnnotationMap.put(cid.getDeclaredByMetadataId(), new HashSet<JavaType>());
    }
    if (!typeCustomDataMap.containsKey(cid.getDeclaredByMetadataId())) {
        typeCustomDataMap.put(cid.getDeclaredByMetadataId(), new HashSet<Object>());
    }
    final Set<JavaType> previousAnnotations = typeAnnotationMap.get(cid.getDeclaredByMetadataId());
    for (final JavaType previousAnnotation : previousAnnotations) {
        final Set<String> midSet = annotationToMidMap.get(previousAnnotation);
        if (midSet != null) {
            midSet.remove(cid.getDeclaredByMetadataId());
        }
    }
    previousAnnotations.clear();
    for (final AnnotationMetadata annotationMetadata : cid.getAnnotations()) {
        if (!annotationToMidMap.containsKey(annotationMetadata.getAnnotationType())) {
            annotationToMidMap.put(annotationMetadata.getAnnotationType(), new HashSet<String>());
        }
        previousAnnotations.add(annotationMetadata.getAnnotationType());
        annotationToMidMap.get(annotationMetadata.getAnnotationType()).add(cid.getDeclaredByMetadataId());
    }
    final Set<Object> previousCustomDataSet = typeCustomDataMap.get(cid.getDeclaredByMetadataId());
    for (final Object previousCustomData : previousCustomDataSet) {
        final Set<String> midSet = tagToMidMap.get(previousCustomData);
        if (midSet != null) {
            midSet.remove(cid.getDeclaredByMetadataId());
        }
    }
    previousCustomDataSet.clear();
    for (final Object customData : cid.getCustomData().keySet()) {
        if (!tagToMidMap.containsKey(customData)) {
            tagToMidMap.put(customData, new HashSet<String>());
        }
        previousCustomDataSet.add(customData);
        tagToMidMap.get(customData).add(cid.getDeclaredByMetadataId());
    }
}
Also used : JavaType(org.springframework.roo.model.JavaType) AnnotationMetadata(org.springframework.roo.classpath.details.annotations.AnnotationMetadata)

Example 78 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class TypeLocationServiceImpl method getPhysicalTypeCanonicalPath.

public String getPhysicalTypeCanonicalPath(final String physicalTypeId) {
    final LogicalPath logicalPath = PhysicalTypeIdentifier.getPath(physicalTypeId);
    final JavaType javaType = PhysicalTypeIdentifier.getJavaType(physicalTypeId);
    final Pom pom = getProjectOperations().getPomFromModuleName(logicalPath.getModule());
    final String canonicalFilePath = pom.getPathLocation(logicalPath.getPath()) + javaType.getRelativeFileName();
    if (getFileManager().exists(canonicalFilePath)) {
        getTypeCache().cacheTypeAgainstModule(pom, javaType);
        getTypeCache().cacheFilePathAgainstTypeIdentifier(canonicalFilePath, physicalTypeId);
    }
    return canonicalFilePath;
}
Also used : JavaType(org.springframework.roo.model.JavaType) LogicalPath(org.springframework.roo.project.LogicalPath) Pom(org.springframework.roo.project.maven.Pom)

Example 79 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class TypeLocationServiceImpl method processTypesWithAnnotation.

public void processTypesWithAnnotation(final List<JavaType> annotationsToDetect, final LocatedTypeCallback callback) {
    Validate.notNull(annotationsToDetect, "Annotations to detect required");
    Validate.notNull(callback, "Callback required");
    // be added
    for (final JavaType annotationType : annotationsToDetect) {
        if (!annotationToMidMap.containsKey(annotationType)) {
            annotationToMidMap.put(annotationType, new HashSet<String>());
        }
    }
    // Before processing the call any changes to the project should be
    // processed and the cache updated accordingly
    updateTypeCache();
    for (final JavaType annotationType : annotationsToDetect) {
        for (final String locatedMid : annotationToMidMap.get(annotationType)) {
            final ClassOrInterfaceTypeDetails located = getTypeCache().getTypeDetails(locatedMid);
            callback.process(located);
        }
    }
}
Also used : JavaType(org.springframework.roo.model.JavaType) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)

Example 80 with JavaType

use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.

the class TypeLocationServiceImpl method getTypesForModule.

public Collection<JavaType> getTypesForModule(final Pom module) {
    if ("pom".equals(module.getPackaging())) {
        return Collections.emptySet();
    }
    final Set<String> typeNames = getTypesForModule(module.getPath());
    final Collection<JavaType> javaTypes = new ArrayList<JavaType>();
    for (final String typeName : typeNames) {
        javaTypes.add(new JavaType(typeName, module.getModuleName()));
    }
    return javaTypes;
}
Also used : JavaType(org.springframework.roo.model.JavaType) ArrayList(java.util.ArrayList)

Aggregations

JavaType (org.springframework.roo.model.JavaType)411 RooJavaType (org.springframework.roo.model.RooJavaType)212 ArrayList (java.util.ArrayList)142 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)133 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)129 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)114 JdkJavaType (org.springframework.roo.model.JdkJavaType)110 SpringJavaType (org.springframework.roo.model.SpringJavaType)101 JpaJavaType (org.springframework.roo.model.JpaJavaType)83 AnnotationMetadataBuilder (org.springframework.roo.classpath.details.annotations.AnnotationMetadataBuilder)78 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)76 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)72 InvocableMemberBodyBuilder (org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder)70 MethodMetadataBuilder (org.springframework.roo.classpath.details.MethodMetadataBuilder)65 LogicalPath (org.springframework.roo.project.LogicalPath)62 SpringletsJavaType (org.springframework.roo.model.SpringletsJavaType)60 AnnotationMetadata (org.springframework.roo.classpath.details.annotations.AnnotationMetadata)59 Jsr303JavaType (org.springframework.roo.model.Jsr303JavaType)38 MemberDetails (org.springframework.roo.classpath.scanner.MemberDetails)35 ClassOrInterfaceTypeDetailsBuilder (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetailsBuilder)30