Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaType


    private void createPermissionEvaluator(
            final JavaPackage permissionEvaluatorPackage) {
        installPermissionEvaluatorTemplate(permissionEvaluatorPackage);
        final LogicalPath focusedSrcMainJava = LogicalPath.getInstance(
                SRC_MAIN_JAVA, projectOperations.getFocusedModuleName());
        JavaType permissionEvaluatorClass = new JavaType(
                permissionEvaluatorPackage.getFullyQualifiedPackageName()
                        + ".ApplicationPermissionEvaluator");
        final String identifier = pathResolver.getFocusedCanonicalPath(
                Path.SRC_MAIN_JAVA, permissionEvaluatorClass);
        if (fileManager.exists(identifier)) {
View Full Code Here


            sb.append(".").append(name.getEnclosingType().getSimpleTypeName());
        }
        compilationUnitPackage = new JavaPackage(sb.toString());

        // Determine the type name, adding type parameters if possible
        final JavaType newName = JavaParserUtils.getJavaType(
                compilationUnitServices, typeDeclaration);

        // Revert back to the original type name (thus avoiding unnecessary
        // inferences about java.lang types; see ROO-244)
        name = new JavaType(newName.getFullyQualifiedTypeName(),
                newName.getEnclosingType(), newName.getArray(),
                newName.getDataType(), newName.getArgName(),
                newName.getParameters());

        final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(
                declaredByMetadataId);

        physicalTypeCategory = PhysicalTypeCategory.CLASS;
        if (typeDeclaration instanceof ClassOrInterfaceDeclaration) {
            clazz = (ClassOrInterfaceDeclaration) typeDeclaration;
            if (clazz.isInterface()) {
                physicalTypeCategory = PhysicalTypeCategory.INTERFACE;
            }

        }
        else if (typeDeclaration instanceof EnumDeclaration) {
            enumClazz = (EnumDeclaration) typeDeclaration;
            physicalTypeCategory = PhysicalTypeCategory.ENUMERATION;
        }

        Validate.notNull(physicalTypeCategory, "%s (%s for %s)",
                UNSUPPORTED_MESSAGE_PREFIX, typeDeclaration.getClass()
                        .getSimpleName(), name);

        cidBuilder.setName(name);
        cidBuilder.setPhysicalTypeCategory(physicalTypeCategory);

        imports = compilationUnit.getImports();
        if (imports == null) {
            imports = new ArrayList<ImportDeclaration>();
            compilationUnit.setImports(imports);
        }

        // Verify the package declaration appears to be correct
        if(compilationUnitPackage.equals(name.getPackage()) != true) {
          String warningStr = "[Warning] Compilation unit package '" + compilationUnitPackage + "' unexpected for type '" + name.getPackage() + "', it may be a nested class.";
          LOGGER.log(Level.WARNING, warningStr);
        }

        for (final ImportDeclaration importDeclaration : imports) {
            if (importDeclaration.getName() instanceof QualifiedNameExpr) {
                final String qualifier = ((QualifiedNameExpr) importDeclaration
                        .getName()).getQualifier().toString();
                final String simpleName = importDeclaration.getName().getName();
                final String fullName = qualifier + "." + simpleName;
                // We want to calculate these...

                final JavaType type = new JavaType(fullName);
                final JavaPackage typePackage = importDeclaration.isAsterisk() ? new JavaPackage(
                        fullName) : type.getPackage();

                // Process any comments for the import
                final CommentStructure commentStructure = new CommentStructure();
                JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                        commentStructure, importDeclaration);

                final ImportMetadataBuilder newImport = new ImportMetadataBuilder(
                        declaredByMetadataId, 0, typePackage, type,
                        importDeclaration.isStatic(),
                        importDeclaration.isAsterisk());

                newImport.setCommentStructure(commentStructure);

                cidBuilder.add(newImport.build());
            }
        }

        // Convert Java Parser modifier into JDK modifier
        cidBuilder.setModifier(JavaParserUtils.getJdkModifier(typeDeclaration
                .getModifiers()));

        // Type parameters
        final Set<JavaSymbolName> typeParameterNames = new HashSet<JavaSymbolName>();
        for (final JavaType param : name.getParameters()) {
            final JavaSymbolName arg = param.getArgName();
            // Fortunately type names can only appear at the top-level
            if (arg != null && !JavaType.WILDCARD_NEITHER.equals(arg)
                    && !JavaType.WILDCARD_EXTENDS.equals(arg)
                    && !JavaType.WILDCARD_SUPER.equals(arg)) {
                typeParameterNames.add(arg);
            }
        }

        List<ClassOrInterfaceType> implementsList;
        List<AnnotationExpr> annotationsList = null;
        List<BodyDeclaration> members = null;

        if (clazz != null) {
            final List<ClassOrInterfaceType> extendsList = clazz.getExtends();
            if (extendsList != null) {
                for (final ClassOrInterfaceType candidate : extendsList) {
                    final JavaType javaType = JavaParserUtils.getJavaTypeNow(
                            compilationUnitServices, candidate,
                            typeParameterNames);
                    cidBuilder.addExtendsTypes(javaType);
                }
            }

            final List<JavaType> extendsTypes = cidBuilder.getExtendsTypes();
            // Obtain the superclass, if this is a class and one is available
            if (physicalTypeCategory == PhysicalTypeCategory.CLASS
                    && extendsTypes.size() == 1) {
                final JavaType superclass = extendsTypes.get(0);
                final String superclassId = typeLocationService
                        .getPhysicalTypeIdentifier(superclass);
                PhysicalTypeMetadata superPtm = null;
                if (superclassId != null) {
                    superPtm = (PhysicalTypeMetadata) metadataService
                            .get(superclassId);
                }
                if (superPtm != null
                        && superPtm.getMemberHoldingTypeDetails() != null) {
                    cidBuilder.setSuperclass(superPtm
                            .getMemberHoldingTypeDetails());
                }
            }

            implementsList = clazz.getImplements();
            if (implementsList != null) {
                for (final ClassOrInterfaceType candidate : implementsList) {
                    final JavaType javaType = JavaParserUtils.getJavaTypeNow(
                            compilationUnitServices, candidate,
                            typeParameterNames);
                    cidBuilder.addImplementsType(javaType);
                }
            }

            annotationsList = typeDeclaration.getAnnotations();
            members = clazz.getMembers();
        }

        if (enumClazz != null) {
            final List<EnumConstantDeclaration> constants = enumClazz
                    .getEntries();
            if (constants != null) {
                for (final EnumConstantDeclaration enumConstants : constants) {
                    cidBuilder.addEnumConstant(new JavaSymbolName(enumConstants
                            .getName()));
                }
            }

            implementsList = enumClazz.getImplements();
            annotationsList = enumClazz.getAnnotations();
            members = enumClazz.getMembers();
        }

        if (annotationsList != null) {
            for (final AnnotationExpr candidate : annotationsList) {
                final AnnotationMetadata md = JavaParserAnnotationMetadataBuilder
                        .getInstance(candidate, compilationUnitServices)
                        .build();

                final CommentStructure commentStructure = new CommentStructure();
                JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                        commentStructure, candidate);
                md.setCommentStructure(commentStructure);

                cidBuilder.addAnnotation(md);
            }
        }

        if (members != null) {
            // Now we've finished declaring the type, we should introspect for
            // any inner types that can thus be referred to in other body
            // members
            // We defer this until now because it's illegal to refer to an inner
            // type in the signature of the enclosing type
            for (final BodyDeclaration bodyDeclaration : members) {
                if (bodyDeclaration instanceof TypeDeclaration) {
                    // Found a type
                    innerTypes.add((TypeDeclaration) bodyDeclaration);
                }
            }

            for (final BodyDeclaration member : members) {
                if (member instanceof FieldDeclaration) {
                    final FieldDeclaration castMember = (FieldDeclaration) member;
                    for (final VariableDeclarator var : castMember
                            .getVariables()) {
                        final FieldMetadata field = JavaParserFieldMetadataBuilder
                                .getInstance(declaredByMetadataId, castMember,
                                        var, compilationUnitServices,
                                        typeParameterNames).build();

                        final CommentStructure commentStructure = new CommentStructure();
                        JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                                commentStructure, member);
                        field.setCommentStructure(commentStructure);

                        cidBuilder.addField(field);
                    }
                }
                if (member instanceof MethodDeclaration) {
                    final MethodDeclaration castMember = (MethodDeclaration) member;
                    final MethodMetadata method = JavaParserMethodMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();

                    final CommentStructure commentStructure = new CommentStructure();
                    JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                            commentStructure, member);
                    method.setCommentStructure(commentStructure);

                    cidBuilder.addMethod(method);
                }
                if (member instanceof ConstructorDeclaration) {
                    final ConstructorDeclaration castMember = (ConstructorDeclaration) member;
                    final ConstructorMetadata constructor = JavaParserConstructorMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();

                    final CommentStructure commentStructure = new CommentStructure();
                    JavaParserCommentMetadataBuilder.updateCommentsToRoo(
                            commentStructure, member);
                    constructor.setCommentStructure(commentStructure);

                    cidBuilder.addConstructor(constructor);
                }
                if (member instanceof TypeDeclaration) {
                    final TypeDeclaration castMember = (TypeDeclaration) member;
                    final JavaType innerType = new JavaType(
                            castMember.getName(), name);
                    final String innerTypeMetadataId = PhysicalTypeIdentifier
                            .createIdentifier(innerType, PhysicalTypeIdentifier
                                    .getPath(declaredByMetadataId));
                    final ClassOrInterfaceTypeDetails cid = new JavaParserClassOrInterfaceTypeDetailsBuilder(
View Full Code Here

        final HashSet<String> imported = new HashSet<String>();
        final ArrayList<ImportDeclaration> imports = new ArrayList<ImportDeclaration>();
        for (final ImportDeclaration importDeclaration : compilationUnit
                .getImports()) {
            JavaPackage importPackage = null;
            JavaType importType = null;
            if (importDeclaration.isAsterisk()) {
                importPackage = new JavaPackage(importDeclaration.getName()
                        .toString());
            }
            else {
                importType = new JavaType(importDeclaration.getName()
                        .toString());
                importPackage = importType.getPackage();
            }

            if (importPackage.equals(cid.getName().getPackage())
                    && importDeclaration.isAsterisk()) {
                continue;
            }

            if (importPackage.equals(cid.getName().getPackage())
                    && importType != null
                    && importType.getEnclosingType() == null) {
                continue;
            }

            if (importType != null && importType.equals(cid.getName())) {
                continue;
            }

            if (!imported.contains(importDeclaration.getName().toString())) {
                imports.add(importDeclaration);
View Full Code Here

                    fileIdentifier.lastIndexOf(File.separator) + 1,
                    fileIdentifier.lastIndexOf("."));
            for (final TypeDeclaration typeDeclaration : compilationUnit
                    .getTypes()) {
                if (typeName.equals(typeDeclaration.getName())) {
                    return new JavaType(compilationUnit.getPackage().getName()
                            .getName()
                            + "." + typeDeclaration.getName());
                }
            }
            return null;
View Full Code Here

        else if (value instanceof CharAttributeValue) {
            attributeValue = "'"
                    + ((CharAttributeValue) value).getValue().toString() + "'";
        }
        else if (value instanceof ClassAttributeValue) {
            final JavaType clazz = ((ClassAttributeValue) value).getValue();
            if (resolver == null
                    || resolver
                            .isFullyQualifiedFormRequiredAfterAutoImport(clazz)) {
                attributeValue = clazz.getFullyQualifiedTypeName() + ".class";
            }
            else {
                attributeValue = clazz.getSimpleTypeName() + ".class";
            }
        }
        else if (value instanceof DoubleAttributeValue) {
            final DoubleAttributeValue dbl = (DoubleAttributeValue) value;
            if (dbl.isFloatingPrecisionOnly()) {
                attributeValue = dbl.getValue().toString() + "F";
            }
            else {
                attributeValue = dbl.getValue().toString() + "D";
            }
        }
        else if (value instanceof EnumAttributeValue) {
            final EnumDetails enumDetails = ((EnumAttributeValue) value)
                    .getValue();
            final JavaType clazz = enumDetails.getType();
            if (resolver == null
                    || resolver
                            .isFullyQualifiedFormRequiredAfterAutoImport(clazz)) {
                attributeValue = clazz.getFullyQualifiedTypeName() + "."
                        + enumDetails.getField().getSymbolName();
            }
            else {
                attributeValue = clazz.getSimpleTypeName() + "."
                        + enumDetails.getField().getSymbolName();
            }
        }
        else if (value instanceof IntegerAttributeValue) {
            attributeValue = ((IntegerAttributeValue) value).getValue()
                    .toString();
        }
        else if (value instanceof LongAttributeValue) {
            attributeValue = ((LongAttributeValue) value).getValue().toString()
                    + "L";
        }
        else if (value instanceof StringAttributeValue) {
            attributeValue = "\"" + ((StringAttributeValue) value).getValue()
                    + "\"";
        }
        else if (value instanceof NestedAnnotationAttributeValue) {
            final AnnotationMetadata annotationMetadata = ((NestedAnnotationAttributeValue) value)
                    .getValue();
            final StringBuilder data = new StringBuilder("@");
            final JavaType annotationType = annotationMetadata
                    .getAnnotationType();
            if (resolver == null
                    || resolver
                            .isFullyQualifiedFormRequiredAfterAutoImport(annotationType)) {
                data.append(annotationType.getFullyQualifiedTypeName());
            }
            else {
                data.append(annotationType.getSimpleTypeName());
            }
            if (!annotationMetadata.getAttributeNames().isEmpty()) {
                data.append("(");
                int i = 0;
                for (final JavaSymbolName attributeName : annotationMetadata
View Full Code Here

        // unique name (it's not really a fatal situation at the end of the day)
        final JavaSymbolName idField = governorTypeDetails
                .getUniqueFieldName(getIdentifierFieldName());

        // We need to create one
        final JavaType identifierType = getIdentifierType();

        final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>();
        final boolean hasIdClass = !(identifierType.isCoreType() || identifierType
                .equals(GAE_DATASTORE_KEY));
        final JavaType annotationType = hasIdClass ? EMBEDDED_ID : ID;
        annotations.add(new AnnotationMetadataBuilder(annotationType));

        // Encode keys as strings on GAE to support entity group hierarchies
        if (isGaeEnabled && identifierType.equals(JavaType.STRING)) {
            AnnotationMetadataBuilder extensionBuilder = new AnnotationMetadataBuilder(
View Full Code Here

        // unique name (it's not really a fatal situation at the end of the day)
        final JavaSymbolName verField = governorTypeDetails
                .getUniqueFieldName(versionField);

        // We're creating one
        JavaType versionType = annotationValues.getVersionType();
        String versionColumn = StringUtils.defaultIfEmpty(
                annotationValues.getVersionColumn(), verField.getSymbolName());
        if (isDatabaseDotComEnabled) {
            versionType = CALENDAR;
            versionColumn = "lastModifiedDate";
View Full Code Here

        // Lookup the parameters and their names
        if (constructorDeclaration.getParameters() != null) {
            for (final Parameter p : constructorDeclaration.getParameters()) {
                final Type pt = p.getType();
                final JavaType parameterType = JavaParserUtils.getJavaType(
                        compilationUnitServices, pt, fullTypeParameters);

                final List<AnnotationExpr> annotationsList = p.getAnnotations();
                final List<AnnotationMetadata> annotations = new ArrayList<AnnotationMetadata>();
                if (annotationsList != null) {
View Full Code Here

        if (NUMBER_PRIMITIVES.contains(value)) {
            return getNumberPrimitiveType(value);
        }

        if (LAST_USED_INDICATOR.equals(value)) {
            final JavaType result = lastUsed.getJavaType();
            if (result == null) {
                throw new IllegalStateException(
                        "Unknown type; please indicate the type as a command option (ie --xxxx)");
            }
            return result;
        }

        String topLevelPath;
        Pom module = projectOperations.getFocusedModule();

        if (value.contains(MODULE_PATH_SEPARATOR)) {
            final String moduleName = value.substring(0,
                    value.indexOf(MODULE_PATH_SEPARATOR));
            module = projectOperations.getPomFromModuleName(moduleName);
            topLevelPath = typeLocationService
                    .getTopLevelPackageForModule(module);
            value = value.substring(value.indexOf(MODULE_PATH_SEPARATOR) + 1,
                    value.length()).trim();
            if (StringUtils.contains(optionContext, UPDATE)) {
                projectOperations.setModule(module);
            }
        }
        else {
            topLevelPath = typeLocationService
                    .getTopLevelPackageForModule(projectOperations
                            .getFocusedModule());
        }

        if (value.equals(topLevelPath)) {
            return null;
        }

        String newValue = locateExisting(value, topLevelPath);
        if (newValue == null) {
            newValue = locateNew(value, topLevelPath);
        }

        if (StringUtils.isNotBlank(newValue)) {
            final String physicalTypeIdentifier = typeLocationService
                    .getPhysicalTypeIdentifier(new JavaType(newValue));
            if (StringUtils.isNotBlank(physicalTypeIdentifier)) {
                module = projectOperations
                        .getPomFromModuleName(PhysicalTypeIdentifier.getPath(
                                physicalTypeIdentifier).getModule());
            }
        }

        // If the user did not provide a java type name containing a dot, it's
        // taken as relative to the current package directory
        if (!newValue.contains(".")) {
            newValue = (lastUsed.getJavaPackage() == null ? lastUsed
                    .getTopLevelPackage().getFullyQualifiedPackageName()
                    : lastUsed.getJavaPackage().getFullyQualifiedPackageName())
                    + "." + newValue;
        }

        // Automatically capitalise the first letter of the last name segment
        // (i.e. capitalise the type name, but not the package)
        final int index = newValue.lastIndexOf(".");
        if (index > -1 && !newValue.endsWith(".")) {
            String typeName = newValue.substring(index + 1);
            typeName = StringUtils.capitalize(typeName);
            newValue = newValue.substring(0, index).toLowerCase() + "."
                    + typeName;
        }
        final JavaType result = new JavaType(newValue);
        if (StringUtils.contains(optionContext, UPDATE)) {
            lastUsed.setType(result, module);
        }
        return result;
    }
View Full Code Here

                }
                else {
                    newValue = topLevelPath + ".";
                }
                final String physicalTypeIdentifier = typeLocationService
                        .getPhysicalTypeIdentifier(new JavaType(newValue));
                if (physicalTypeIdentifier != null) {
                    topLevelPath = typeLocationService
                            .getTopLevelPackageForModule(projectOperations
                                    .getPomFromModuleName(PhysicalTypeIdentifier
                                            .getPath(physicalTypeIdentifier)
View Full Code Here

TOP

Related Classes of org.springframework.roo.model.JavaType

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.