Search in sources :

Example 1 with JavaPackage

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

the class JavaParserUtils method getJavaType.

/**
 * Resolves the effective {@link JavaType} a {@link NameExpr} represents.
 * <p>
 * You should use {@link #getJavaType(CompilationUnitServices, Type, Set)}
 * where possible so that type arguments are preserved (a {@link NameExpr}
 * does not contain type arguments).
 * <p>
 * A name expression can be either qualified or unqualified.
 * <p>
 * If a name expression is qualified and the qualification starts with a
 * lowercase letter, that represents the fully-qualified name. If the
 * qualification starts with an uppercase letter, the package name is
 * prepended to the qualifier.
 * <p>
 * If a name expression is unqualified, the imports are scanned. If the
 * unqualified name expression is found in the imports, that import
 * declaration represents the fully-qualified name. If the unqualified name
 * expression is not found in the imports, it indicates the name to find is
 * either in the same package as the qualified name expression, or the type
 * relates to a member of java.lang. If part of java.lang, the fully
 * qualified name is treated as part of java.lang. Otherwise the compilation
 * unit package plus unqualified name expression represents the fully
 * qualified name expression.
 *
 * @param compilationUnitServices for package management (required)
 * @param nameToFind to locate (required)
 * @param typeParameters names to consider type parameters (can be null if
 *            there are none)
 * @return the effective Java type (never null)
 */
public static JavaType getJavaType(final CompilationUnitServices compilationUnitServices, final NameExpr nameToFind, final Set<JavaSymbolName> typeParameters) {
    Validate.notNull(compilationUnitServices, "Compilation unit services required");
    Validate.notNull(nameToFind, "Name to find is required");
    final JavaPackage compilationUnitPackage = compilationUnitServices.getCompilationUnitPackage();
    if (nameToFind instanceof QualifiedNameExpr) {
        final QualifiedNameExpr qne = (QualifiedNameExpr) nameToFind;
        // Handle qualified name expressions that are related to inner types
        // (eg Foo.Bar)
        final NameExpr qneQualifier = qne.getQualifier();
        final NameExpr enclosedBy = getNameExpr(compilationUnitServices.getEnclosingTypeName().getSimpleTypeName());
        if (isEqual(qneQualifier, enclosedBy)) {
            // This qualified name expression is simply an inner type
            // reference
            final String name = compilationUnitServices.getEnclosingTypeName().getFullyQualifiedTypeName() + "." + nameToFind.getName();
            return new JavaType(name, compilationUnitServices.getEnclosingTypeName());
        }
        // package (ROO-1210)
        if (qne.toString().length() > 1 && Character.isUpperCase(qne.toString().charAt(0))) {
            // First letter is uppercase, so this likely requires prepending
            // of some package name
            final ImportDeclaration importDeclaration = getImportDeclarationFor(compilationUnitServices, qne.getQualifier());
            if (importDeclaration == null) {
                if (!compilationUnitPackage.getFullyQualifiedPackageName().equals("")) {
                    // package
                    return new JavaType(compilationUnitServices.getCompilationUnitPackage().getFullyQualifiedPackageName() + "." + qne.toString());
                }
            } else {
                return new JavaType(importDeclaration.getName() + "." + qne.getName());
            }
        // This name expression (which contains a dot) had its qualifier
        // imported, so let's use the import
        } else {
            // a package
            return new JavaType(qne.toString());
        }
    }
    if ("?".equals(nameToFind.getName())) {
        return new JavaType(OBJECT.getFullyQualifiedTypeName(), 0, DataType.TYPE, JavaType.WILDCARD_NEITHER_ARG, null);
    }
    // list
    if (typeParameters != null && typeParameters.contains(new JavaSymbolName(nameToFind.getName()))) {
        return new JavaType(nameToFind.getName(), 0, DataType.VARIABLE, null, null);
    }
    // Check if we are looking for the enclosingType itself
    final NameExpr enclosingTypeName = getNameExpr(compilationUnitServices.getEnclosingTypeName().getSimpleTypeName());
    if (isEqual(enclosingTypeName, nameToFind)) {
        return compilationUnitServices.getEnclosingTypeName();
    }
    // check if the compilation unit itself declares that type
    for (final TypeDeclaration internalType : compilationUnitServices.getInnerTypes()) {
        final NameExpr nameExpr = getNameExpr(internalType.getName());
        if (isEqual(nameExpr, nameToFind)) {
            // Found, so now we need to convert the internalType to a proper
            // JavaType
            final String name = compilationUnitServices.getEnclosingTypeName().getFullyQualifiedTypeName() + "." + nameToFind.getName();
            return new JavaType(name);
        }
    }
    final ImportDeclaration importDeclaration = getImportDeclarationFor(compilationUnitServices, nameToFind);
    if (importDeclaration == null) {
        if (JdkJavaType.isPartOfJavaLang(nameToFind.getName())) {
            return new JavaType("java.lang." + nameToFind.getName());
        }
        final String name = compilationUnitPackage.getFullyQualifiedPackageName().equals("") ? nameToFind.getName() : compilationUnitPackage.getFullyQualifiedPackageName() + "." + nameToFind.getName();
        return new JavaType(name);
    }
    return new JavaType(importDeclaration.getName().toString());
}
Also used : QualifiedNameExpr(com.github.antlrjavaparser.api.expr.QualifiedNameExpr) JdkJavaType(org.springframework.roo.model.JdkJavaType) JavaType(org.springframework.roo.model.JavaType) JavaSymbolName(org.springframework.roo.model.JavaSymbolName) NameExpr(com.github.antlrjavaparser.api.expr.NameExpr) QualifiedNameExpr(com.github.antlrjavaparser.api.expr.QualifiedNameExpr) ImportDeclaration(com.github.antlrjavaparser.api.ImportDeclaration) TypeDeclaration(com.github.antlrjavaparser.api.body.TypeDeclaration) JavaPackage(org.springframework.roo.model.JavaPackage)

Example 2 with JavaPackage

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

the class AbstractViewGeneratorMetadataProvider method getMetadata.

@Override
protected ItdTypeDetailsProvidingMetadataItem getMetadata(final String metadataIdentificationString, final JavaType aspectName, final PhysicalTypeMetadata governorPhysicalTypeMetadata, final String itdFilename) {
    // Use provided MVCViewGenerationService to generate views
    MVCViewGenerationService<T> viewGenerationService = getViewGenerationService();
    ClassOrInterfaceTypeDetails controllerDetail = governorPhysicalTypeMetadata.getMemberHoldingTypeDetails();
    // Getting controller metadata
    final String controllerMetadataKey = ControllerMetadata.createIdentifier(controllerDetail);
    final ControllerMetadata controllerMetadata = getMetadataService().get(controllerMetadataKey);
    if (controllerMetadata == null) {
        return null;
    }
    // Getting entity and check if is a readOnly entity or not
    final JavaType entity = controllerMetadata.getEntity();
    JavaType viewType = viewGenerationService.getType();
    JavaType itemController = null;
    JavaType collectionController = null;
    final JavaPackage controllerPackage = controllerDetail.getType().getPackage();
    final String pathPrefix = controllerMetadata.getAnnotationValues().getPathPrefix();
    if (controllerMetadata.getType() != ControllerType.ITEM) {
        // Locate ItemController
        Collection<ClassOrInterfaceTypeDetails> itemControllers = getControllerLocator().getControllers(entity, ControllerType.ITEM, viewType);
        if (itemControllers.isEmpty()) {
            // We can't create metadata "Jet"
            return null;
        } else {
            // Get controller with the same package
            itemController = filterControllerByPackageAndPrefix(itemControllers, controllerPackage, pathPrefix);
            Validate.notNull(itemControllers, "ERROR: Can't find ITEM-type controller related to controller '%s'", controllerDetail.getType().getFullyQualifiedTypeName());
        }
    }
    if (controllerMetadata.getType() != ControllerType.COLLECTION) {
        // Locate ItemController
        Collection<ClassOrInterfaceTypeDetails> collectionControllers = getControllerLocator().getControllers(entity, ControllerType.COLLECTION, viewType);
        // Get controller with the same package
        collectionController = filterControllerByPackageAndPrefix(collectionControllers, controllerPackage, pathPrefix);
        Validate.notNull(collectionController, "ERROR: Can't find Collection-type controller related to controller '%s'", controllerDetail.getType().getFullyQualifiedTypeName());
    }
    JavaType detailItemController = null;
    JavaType detailCollectionController = null;
    if (controllerMetadata.getType() == ControllerType.DETAIL) {
        if (controllerMetadata.getLastDetailsInfo().type == JpaRelationType.AGGREGATION) {
            // Locate controller item which handles details elements
            JavaType detailEntity = controllerMetadata.getLastDetailEntity();
            Collection<ClassOrInterfaceTypeDetails> detailsControllersToCheck = getControllerLocator().getControllers(detailEntity, ControllerType.ITEM, viewType);
            for (ClassOrInterfaceTypeDetails controller : detailsControllersToCheck) {
                if (controllerPackage.equals(controller.getType().getPackage())) {
                    detailItemController = controller.getType();
                    break;
                }
            }
            Validate.notNull(detailItemController, "ERROR: Can't find Item-type controller for details entity '%s' related to controller '%s'", detailEntity.getFullyQualifiedTypeName(), controllerDetail.getType().getFullyQualifiedTypeName());
            // Locate controller collection which handles details elements
            detailsControllersToCheck = getControllerLocator().getControllers(detailEntity, ControllerType.COLLECTION, viewType);
            for (ClassOrInterfaceTypeDetails controller : detailsControllersToCheck) {
                if (controllerPackage.equals(controller.getType().getPackage())) {
                    detailCollectionController = controller.getType();
                    break;
                }
            }
            Validate.notNull(detailItemController, "ERROR: Can't find Collection-type controller for details entity '%s' related to controller '%s'", detailEntity.getFullyQualifiedTypeName(), controllerDetail.getType().getFullyQualifiedTypeName());
        } else {
            // ** COMPOSITION **
            // Locate controller item which handles details elements
            Collection<ClassOrInterfaceTypeDetails> detailsControllersToCheck = getControllerLocator().getControllers(entity, ControllerType.DETAIL_ITEM, viewType);
            for (ClassOrInterfaceTypeDetails controller : detailsControllersToCheck) {
                if (controllerPackage.equals(controller.getType().getPackage())) {
                    DetailAnnotationValues annotationValues = new DetailAnnotationValues(controller);
                    if (controllerMetadata.getDetailAnnotaionFieldValue().equals(annotationValues.getRelationField())) {
                        detailItemController = controller.getType();
                    }
                    break;
                }
            }
            Validate.notNull(detailItemController, "ERROR: Can't find Detail-Item-type controller for details entity '%s' related to controller '%s' (relation '%s')", entity.getFullyQualifiedTypeName(), controllerDetail.getType().getFullyQualifiedTypeName(), controllerMetadata.getDetailAnnotaionFieldValue());
        }
    }
    if (controllerMetadata.getType() == ControllerType.DETAIL_ITEM) {
        // Locate controller item which handles details elements
        Collection<ClassOrInterfaceTypeDetails> detailsControllersToCheck = getControllerLocator().getControllers(entity, ControllerType.DETAIL, viewType);
        for (ClassOrInterfaceTypeDetails controller : detailsControllersToCheck) {
            if (controllerPackage.equals(controller.getType().getPackage())) {
                DetailAnnotationValues annotationValues = new DetailAnnotationValues(controller);
                if (controllerMetadata.getDetailAnnotaionFieldValue().equals(annotationValues.getRelationField())) {
                    detailCollectionController = controller.getType();
                }
                break;
            }
        }
        Validate.notNull(detailCollectionController, "ERROR: Can't find Detail-type controller for details entity '%s' related to controller '%s' (relation '%s')", entity.getFullyQualifiedTypeName(), controllerDetail.getType().getFullyQualifiedTypeName(), controllerMetadata.getDetailAnnotaionFieldValue());
    }
    Validate.notNull(entity, "ERROR: You should provide a valid entity for controller '%s'", controllerDetail.getType().getFullyQualifiedTypeName());
    final ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity);
    Validate.notNull(entityDetails, "ERROR: Can't load details of %s", entity.getFullyQualifiedTypeName());
    final JpaEntityMetadata entityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(entityDetails));
    Validate.notNull(entityMetadata, "ERROR: Can't get Jpa Entity metada of %s", entity.getFullyQualifiedTypeName());
    MemberDetails entityMemberDetails = getMemberDetails(entityDetails);
    // Get entity plural
    final String entityPlural = getPluralService().getPlural(entity);
    final String entityIdentifierPlural = getPluralService().getPlural(entityMetadata.getCurrentIndentifierField().getFieldName());
    // Getting service and its metadata
    final JavaType service = controllerMetadata.getService();
    ClassOrInterfaceTypeDetails serviceDetails = getTypeLocationService().getTypeDetails(service);
    final String serviceMetadataKey = ServiceMetadata.createIdentifier(serviceDetails);
    registerDependency(serviceMetadataKey, metadataIdentificationString);
    final ServiceMetadata serviceMetadata = getMetadataService().get(serviceMetadataKey);
    // Prepare information about ONE-TO-ONE relations
    final List<Pair<RelationInfo, JpaEntityMetadata>> compositionRelationOneToOne = new ArrayList<Pair<RelationInfo, JpaEntityMetadata>>();
    ClassOrInterfaceTypeDetails childEntityDetails;
    JpaEntityMetadata childEntityMetadata;
    for (RelationInfo info : entityMetadata.getRelationInfos().values()) {
        if (info.cardinality == Cardinality.ONE_TO_ONE) {
            childEntityDetails = getTypeLocationService().getTypeDetails(info.childType);
            childEntityMetadata = getMetadataService().get(JpaEntityMetadata.createIdentifier(childEntityDetails));
            compositionRelationOneToOne.add(Pair.of(info, childEntityMetadata));
        }
    }
    List<FieldMetadata> dateTimeFields;
    List<FieldMetadata> enumFields;
    if (controllerMetadata.getType() == ControllerType.DETAIL || controllerMetadata.getType() == ControllerType.DETAIL_ITEM) {
        ClassOrInterfaceTypeDetails childCid = getTypeLocationService().getTypeDetails(controllerMetadata.getLastDetailEntity());
        MemberDetails childMemberDetails = getMemberDetails(childCid);
        dateTimeFields = getDateTimeFields(childMemberDetails);
        enumFields = getEnumFields(childMemberDetails);
    } else {
        dateTimeFields = getDateTimeFields(entityMemberDetails);
        enumFields = getEnumFields(entityMemberDetails);
    }
    Map<String, MethodMetadata> findersToAdd = new HashMap<String, MethodMetadata>();
    Map<JavaType, List<FieldMetadata>> formBeansDateTimeFields = new HashMap<JavaType, List<FieldMetadata>>();
    Map<JavaType, List<FieldMetadata>> formBeansEnumFields = new HashMap<JavaType, List<FieldMetadata>>();
    // Getting annotated finders
    final SearchAnnotationValues searchAnnotationValues = new SearchAnnotationValues(governorPhysicalTypeMetadata);
    // Add finders only if controller is of search type
    Map<String, JavaType> finderReturnTypes = new HashMap<String, JavaType>();
    Map<String, JavaType> finderFormBeans = new HashMap<String, JavaType>();
    if (controllerMetadata.getType() == ControllerType.SEARCH && searchAnnotationValues != null && searchAnnotationValues.getFinders() != null) {
        List<String> finders = new ArrayList<String>(Arrays.asList(searchAnnotationValues.getFinders()));
        // Search indicated finders in its related service
        for (MethodMetadata serviceFinder : serviceMetadata.getFinders()) {
            String finderName = serviceFinder.getMethodName().getSymbolName();
            if (finders.contains(finderName)) {
                findersToAdd.put(finderName, serviceFinder);
                // FormBean parameters is always the first finder parameter
                JavaType formBean = serviceFinder.getParameterTypes().get(0).getJavaType();
                // Save the associated formBean to the current finder
                finderFormBeans.put(finderName, formBean);
                // Getting the returnType for this finder
                JavaType returnType = serviceFinder.getReturnType();
                // Save the associated returnType to the current finder
                finderReturnTypes.put(finderName, returnType);
                // Get dateTime and Enum of formBean
                MemberDetails formBeanDetails = getMemberDetails(formBean);
                List<FieldMetadata> formBeanDateTimeFields = getDateTimeFields(formBeanDetails);
                List<FieldMetadata> formBeanEnumFields = getEnumFields(formBeanDetails);
                if (!formBeanDateTimeFields.isEmpty()) {
                    formBeansDateTimeFields.put(formBean, formBeanDateTimeFields);
                }
                if (!formBeanEnumFields.isEmpty()) {
                    formBeansEnumFields.put(formBean, formBeanEnumFields);
                }
                // Add dependencies between modules
                List<JavaType> types = new ArrayList<JavaType>();
                types.add(serviceFinder.getReturnType());
                types.addAll(serviceFinder.getReturnType().getParameters());
                for (AnnotatedJavaType parameter : serviceFinder.getParameterTypes()) {
                    types.add(parameter.getJavaType());
                    types.addAll(parameter.getJavaType().getParameters());
                }
                for (JavaType parameter : types) {
                    getTypeLocationService().addModuleDependency(governorPhysicalTypeMetadata.getType().getModule(), parameter);
                }
                finders.remove(finderName);
            }
        }
        // Check all finders have its service method
        if (!finders.isEmpty()) {
            throw new IllegalArgumentException(String.format("ERROR: Service %s does not have these finder methods: %s ", service.getFullyQualifiedTypeName(), StringUtils.join(finders, ", ")));
        }
    }
    T viewMetadata = createMetadataInstance(metadataIdentificationString, aspectName, governorPhysicalTypeMetadata, controllerMetadata, serviceMetadata, entityMetadata, entityPlural, entityIdentifierPlural, compositionRelationOneToOne, itemController, collectionController, dateTimeFields, enumFields, findersToAdd, formBeansDateTimeFields, formBeansEnumFields, detailItemController, detailCollectionController);
    // Fill view context
    ViewContext ctx = viewGenerationService.createViewContext(controllerMetadata, entity, entityMetadata, viewMetadata);
    // Checking if Spring Security has been installed
    if (getProjectOperations().isFeatureInstalled(FeatureNames.SECURITY)) {
        ctx.setSecurityEnabled(true);
    }
    final String module = controllerDetail.getType().getModule();
    switch(controllerMetadata.getType()) {
        case COLLECTION:
            // Obtain the details controllers to use only them that includes "list" value in the
            // views parameter of @RooDetail annotation. If @RooDetail doesn't include views
            // parameter, include it.
            List<T> detailsControllersForListView = getDetailsControllers(controllerMetadata, controllerPackage, entity, viewType, "list");
            // Add list view
            if (viewMetadata.shouldGenerateView("list")) {
                viewGenerationService.addListView(module, entityMetadata, entityMemberDetails, detailsControllersForListView, ctx);
            }
            if (!entityMetadata.isReadOnly()) {
                // If not readOnly, add create view
                if (viewMetadata.shouldGenerateView("create")) {
                    viewGenerationService.addCreateView(module, entityMetadata, entityMemberDetails, ctx);
                }
                if (viewMetadata.shouldGenerateView("listDeleteModal")) {
                    // If not readOnly, add the modal dialogs for delete and delete batch
                    viewGenerationService.addListDeleteModalView(module, entityMetadata, entityMemberDetails, ctx);
                    if (viewMetadata.shouldGenerateView("listDeleteModalBatch")) {
                        viewGenerationService.addListDeleteModalBatchView(module, entityMetadata, entityMemberDetails, ctx);
                    }
                }
            }
            break;
        case ITEM:
            // Obtain the details controllers to use only them that includes "show" value in the
            // views parameter of @RooDetail annotation.
            List<T> detailsControllersForShowView = getDetailsControllers(controllerMetadata, controllerPackage, entity, viewType, "show");
            // Add show view
            if (viewMetadata.shouldGenerateView("show")) {
                viewGenerationService.addShowView(module, entityMetadata, entityMemberDetails, detailsControllersForShowView, ctx);
            }
            if (viewMetadata.shouldGenerateView("showInLine")) {
                // Add showInline view
                viewGenerationService.addShowInlineView(module, entityMetadata, entityMemberDetails, ctx);
            }
            if (!entityMetadata.isReadOnly() && viewMetadata.shouldGenerateView("edit")) {
                // If not readOnly, add update view
                viewGenerationService.addUpdateView(module, entityMetadata, entityMemberDetails, ctx);
            }
            break;
        case DETAIL:
            viewGenerationService.addDetailsViews(module, entityMetadata, entityMemberDetails, controllerMetadata, viewMetadata, ctx);
            // Add this metadata as upstream dependency for parent controllers
            // for updating views of parent controllers
            JavaType parentEntity = entityMetadata.getAnnotatedEntity();
            List<ClassOrInterfaceTypeDetails> parentControllers = new ArrayList<ClassOrInterfaceTypeDetails>();
            parentControllers.addAll(getControllerLocator().getControllers(parentEntity, ControllerType.COLLECTION, viewType));
            parentControllers.addAll(getControllerLocator().getControllers(parentEntity, ControllerType.ITEM, viewType));
            parentControllers.addAll(getControllerLocator().getControllers(parentEntity, ControllerType.SEARCH, viewType));
            for (ClassOrInterfaceTypeDetails parentController : parentControllers) {
                String viewMetadatIdentifier = createLocalIdentifier(parentController);
                registerDependency(metadataIdentificationString, viewMetadatIdentifier);
            }
            break;
        case DETAIL_ITEM:
            viewGenerationService.addDetailsItemViews(module, entityMetadata, entityMemberDetails, controllerMetadata, viewMetadata, ctx);
            RelationInfoExtended last = controllerMetadata.getLastDetailsInfo();
            ClassOrInterfaceTypeDetails childCid = getTypeLocationService().getTypeDetails(last.childType);
            MemberDetails detailMemberDetails = getMemberDetails(childCid);
            // Update i18n labels of detail entity
            if (shouldGenerateI18nLabels()) {
                Map<String, String> labels = viewGenerationService.getI18nLabels(detailMemberDetails, last.childType, last.childEntityMetadata, controllerMetadata, module, ctx);
                getI18nOperations().addOrUpdateLabels(module, labels);
            }
            break;
        case SEARCH:
            // in @RooSearch annotation
            if (searchAnnotationValues != null && searchAnnotationValues.getFinders() != null) {
                List<String> finders = new ArrayList<String>(Arrays.asList(searchAnnotationValues.getFinders()));
                // Generating views for all finders
                for (String finderName : finders) {
                    // Getting the formBean for this finder
                    JavaType formBean = finderFormBeans.get(finderName);
                    viewGenerationService.addFinderFormView(module, entityMetadata, viewMetadata, formBean, finderName, ctx);
                    // Getting the returnType for this finder
                    JavaType returnType = finderReturnTypes.get(finderName);
                    if (!returnType.getParameters().isEmpty()) {
                        returnType = returnType.getParameters().get(0);
                    }
                    // Obtain the details controllers to use only them that includes this finder value in the
                    // views parameter of @RooDetail annotation.
                    List<T> detailsControllersForFinderListView = getDetailsControllers(controllerMetadata, controllerPackage, entity, viewType, finderName);
                    viewGenerationService.addFinderListView(module, entityMetadata, entityMemberDetails, viewMetadata, formBean, returnType, finderName, detailsControllersForFinderListView, ctx);
                }
            }
            break;
        default:
            throw new IllegalArgumentException();
    }
    // be included on it. Must be fixed on future versions.
    if (shouldUpdateMenu()) {
        viewGenerationService.updateMenuView(module, ctx);
    }
    if (shouldGenerateI18nLabels()) {
        // Update i18n labels
        Map<String, String> labels = viewGenerationService.getI18nLabels(entityMemberDetails, entity, entityMetadata, controllerMetadata, module, ctx);
        getI18nOperations().addOrUpdateLabels(module, labels);
        // Add labels for child composite entity as well
        for (Pair<RelationInfo, JpaEntityMetadata> compositionRelation : compositionRelationOneToOne) {
            MemberDetails childMemberDetails = getMemberDetailsScanner().getMemberDetails(this.getClass().getName(), getTypeLocationService().getTypeDetails(compositionRelation.getKey().childType));
            Map<String, String> i18nLabels = viewGenerationService.getI18nLabels(childMemberDetails, compositionRelation.getKey().childType, compositionRelation.getValue(), null, module, ctx);
            getI18nOperations().addOrUpdateLabels(module, i18nLabels);
        }
    }
    // Register dependency between JavaBeanMetadata and this one
    final String javaBeanMetadataKey = JavaBeanMetadata.createIdentifier(entityDetails);
    registerDependency(javaBeanMetadataKey, metadataIdentificationString);
    // Register dependency between JpaEntityMetadata and this one
    final String jpaEntityMetadataKey = JpaEntityMetadata.createIdentifier(entityDetails);
    registerDependency(jpaEntityMetadataKey, metadataIdentificationString);
    return viewMetadata;
}
Also used : FieldMetadata(org.springframework.roo.classpath.details.FieldMetadata) SearchAnnotationValues(org.springframework.roo.addon.web.mvc.controller.addon.finder.SearchAnnotationValues) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DetailAnnotationValues(org.springframework.roo.addon.web.mvc.controller.addon.DetailAnnotationValues) JavaPackage(org.springframework.roo.model.JavaPackage) ArrayList(java.util.ArrayList) List(java.util.List) JpaEntityMetadata(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata) Pair(org.apache.commons.lang3.tuple.Pair) ControllerMetadata(org.springframework.roo.addon.web.mvc.controller.addon.ControllerMetadata) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) AnnotatedJavaType(org.springframework.roo.classpath.details.annotations.AnnotatedJavaType) JdkJavaType(org.springframework.roo.model.JdkJavaType) JpaJavaType(org.springframework.roo.model.JpaJavaType) JavaType(org.springframework.roo.model.JavaType) RelationInfo(org.springframework.roo.addon.jpa.addon.entity.JpaEntityMetadata.RelationInfo) RelationInfoExtended(org.springframework.roo.addon.web.mvc.controller.addon.RelationInfoExtended) MethodMetadata(org.springframework.roo.classpath.details.MethodMetadata) ClassOrInterfaceTypeDetails(org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails) MemberDetails(org.springframework.roo.classpath.scanner.MemberDetails) ServiceMetadata(org.springframework.roo.addon.layers.service.addon.ServiceMetadata)

Example 3 with JavaPackage

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

the class WebFinderOperationsImpl method checkAndUseApplicationModule.

/**
 * Checks if module provided in package is an application module. If not, find an
 * application module and use it with default package.
 *
 * @param controllerPackage the provided JavaPackage to check
 * @return
 */
private JavaPackage checkAndUseApplicationModule(JavaPackage controllerPackage) {
    if (!typeLocationService.hasModuleFeature(projectOperations.getPomFromModuleName(controllerPackage.getModule()), ModuleFeatureName.APPLICATION)) {
        LOGGER.log(Level.WARNING, "Focused or specified module isn't an application module (containing a class " + "annotated with @SpringBootApplication). Looking for an application module and default package...");
        // Validate that project has at least one application module
        Validate.notEmpty(typeLocationService.getModuleNames(ModuleFeatureName.APPLICATION), "The project must have at least one application module to publish web finders.");
        // Get the first application module
        String moduleName = typeLocationService.getModuleNames(ModuleFeatureName.APPLICATION).iterator().next();
        Pom module = projectOperations.getPomFromModuleName(moduleName);
        controllerPackage = new JavaPackage(typeLocationService.getTopLevelPackageForModule(module).concat(".web"), moduleName);
    }
    return controllerPackage;
}
Also used : JavaPackage(org.springframework.roo.model.JavaPackage) Pom(org.springframework.roo.project.maven.Pom)

Example 4 with JavaPackage

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

the class JavaTypeConverter method locateNew.

private String locateNew(final String value, final String topLevelPath) {
    String newValue = value;
    if (value.startsWith(TOP_LEVEL_PACKAGE_SYMBOL)) {
        if (value.length() > 1) {
            newValue = (value.charAt(1) == '.' ? topLevelPath : topLevelPath + ".") + value.substring(1);
        } else {
            newValue = topLevelPath + ".";
        }
    }
    lastUsed.setTopLevelPackage(new JavaPackage(topLevelPath));
    return newValue;
}
Also used : JavaPackage(org.springframework.roo.model.JavaPackage)

Example 5 with JavaPackage

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

the class LastUsedImpl method setPromptPath.

private void setPromptPath(final String fullyQualifiedName) {
    if (topLevelPackage == null) {
        return;
    }
    String moduleName = "";
    if (module != null && StringUtils.isNotBlank(module.getModuleName())) {
        moduleName = AnsiEscapeCode.decorate(module.getModuleName() + MODULE_PATH_SEPARATOR, AnsiEscapeCode.FG_CYAN);
    }
    topLevelPackage = new JavaPackage(typeLocationService.getTopLevelPackageForModule(projectOperations.getFocusedModule()));
    final String path = moduleName + fullyQualifiedName.replace(topLevelPackage.getFullyQualifiedPackageName(), TOP_LEVEL_PACKAGE_SYMBOL);
    shell.setPromptPath(path, StringUtils.isNotBlank(moduleName));
}
Also used : JavaPackage(org.springframework.roo.model.JavaPackage)

Aggregations

JavaPackage (org.springframework.roo.model.JavaPackage)24 JavaType (org.springframework.roo.model.JavaType)11 ArrayList (java.util.ArrayList)7 ClassOrInterfaceTypeDetails (org.springframework.roo.classpath.details.ClassOrInterfaceTypeDetails)6 QualifiedNameExpr (com.github.antlrjavaparser.api.expr.QualifiedNameExpr)5 Pom (org.springframework.roo.project.maven.Pom)5 ImportDeclaration (com.github.antlrjavaparser.api.ImportDeclaration)4 NameExpr (com.github.antlrjavaparser.api.expr.NameExpr)4 MethodMetadata (org.springframework.roo.classpath.details.MethodMetadata)4 JdkJavaType (org.springframework.roo.model.JdkJavaType)4 TypeDeclaration (com.github.antlrjavaparser.api.body.TypeDeclaration)3 ClassOrInterfaceType (com.github.antlrjavaparser.api.type.ClassOrInterfaceType)3 FieldMetadata (org.springframework.roo.classpath.details.FieldMetadata)3 AnnotatedJavaType (org.springframework.roo.classpath.details.annotations.AnnotatedJavaType)3 JavaSymbolName (org.springframework.roo.model.JavaSymbolName)3 BodyDeclaration (com.github.antlrjavaparser.api.body.BodyDeclaration)2 ClassOrInterfaceDeclaration (com.github.antlrjavaparser.api.body.ClassOrInterfaceDeclaration)2 EnumConstantDeclaration (com.github.antlrjavaparser.api.body.EnumConstantDeclaration)2 EnumDeclaration (com.github.antlrjavaparser.api.body.EnumDeclaration)2 AnnotationExpr (com.github.antlrjavaparser.api.expr.AnnotationExpr)2