Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaType


        final JavaSymbolName methodName = getFromJsonArrayMethodName();
        if (methodName == null) {
            return null;
        }

        final JavaType parameterType = JavaType.STRING;
        if (governorHasMethod(methodName, parameterType)) {
            return null;
        }

        final String list = LIST.getNameIncludingTypeParameters(false,
                builder.getImportRegistrationResolver());
        final String arrayList = ARRAY_LIST.getNameIncludingTypeParameters(
                false, builder.getImportRegistrationResolver());
        final String bean = destination.getSimpleTypeName();

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        final String deserializer = JSON_DESERIALIZER
                .getNameIncludingTypeParameters(false,
                        builder.getImportRegistrationResolver());
        bodyBuilder.appendFormalLine("return new " + deserializer + "<" + list
                + "<" + bean + ">>()");
        if (annotationValues.isIso8601Dates()) {
            bodyBuilder
                    .appendFormalLine(".use(java.util.Date.class, "
                            + "new flexjson.transformer.DateTransformer(\"yyyy-MM-dd\"))");
        }
        bodyBuilder.appendFormalLine(".use(\"values\", " + bean
                + ".class).deserialize(json);");

        final List<JavaSymbolName> parameterNames = Arrays
                .asList(new JavaSymbolName("json"));

        final JavaType collection = new JavaType(
                COLLECTION.getFullyQualifiedTypeName(), 0, DataType.TYPE, null,
                Arrays.asList(destination));

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC | Modifier.STATIC, methodName,
View Full Code Here


        final JavaSymbolName methodName = getFromJsonMethodName();
        if (methodName == null) {
            return null;
        }

        final JavaType parameterType = JavaType.STRING;
        if (governorHasMethod(methodName, parameterType)) {
            return null;
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
View Full Code Here

        final JavaSymbolName methodName = getToJsonArrayMethodName();
        if (methodName == null) {
            return null;
        }

        final JavaType parameterType = new JavaType(Collection.class.getName(),
                0, DataType.TYPE, null, Arrays.asList(destination));

        // See if the type itself declared the method
        if (governorHasMethod(methodName, parameterType)) {
            return null;
View Full Code Here

    }

    @Override
    protected String getGovernorPhysicalTypeIdentifier(
            final String metadataIdentificationString) {
        final JavaType javaType = getType(metadataIdentificationString);
        final LogicalPath path = PhysicalTypeIdentifierNamingUtils.getPath(
                PROVIDES_TYPE_STRING, metadataIdentificationString);
        return PhysicalTypeIdentifier.createIdentifier(javaType, path);
    }
View Full Code Here

     *
     * @param metadataIdentificationString
     * @return <code>null</code> if there isn't one
     */
    private Identifier getIdentifier(final String metadataIdentificationString) {
        final JavaType entity = getType(metadataIdentificationString);
        final List<Identifier> identifiers = getIdentifiersForType(entity);
        if (CollectionUtils.isEmpty(identifiers)) {
            return null;
        }
        // We have potential identifier information from an IdentifierService.
        // We only use this identifier information if the user did NOT provide
        // ANY identifier-related attributes on @RooJpaEntity....
        Validate.isTrue(
                identifiers.size() == 1,
                "Identifier service indicates %d fields illegally for the entity '%s' (should only be one identifier field given this is an entity, not an Identifier class)",
                identifiers.size(), entity.getSimpleTypeName());
        return identifiers.iterator().next();
    }
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, UNSUPPORTED_MESSAGE_PREFIX
                + " (" + typeDeclaration.getClass().getSimpleName() + " for "
                + 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
        Validate.isTrue(compilationUnitPackage.equals(name.getPackage()),
                "Compilation unit package '" + compilationUnitPackage
                        + "' unexpected for type '" + name.getPackage() + "'");

        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();
                final ImportMetadataBuilder newImport = new ImportMetadataBuilder(
                        declaredByMetadataId, 0, typePackage, type,
                        importDeclaration.isStatic(),
                        importDeclaration.isAsterisk());
                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();
                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();
                        cidBuilder.addField(field);
                    }
                }
                if (member instanceof MethodDeclaration) {
                    final MethodDeclaration castMember = (MethodDeclaration) member;
                    final MethodMetadata method = JavaParserMethodMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();
                    cidBuilder.addMethod(method);
                }
                if (member instanceof ConstructorDeclaration) {
                    final ConstructorDeclaration castMember = (ConstructorDeclaration) member;
                    final ConstructorMetadata constructor = JavaParserConstructorMetadataBuilder
                            .getInstance(declaredByMetadataId, castMember,
                                    compilationUnitServices, typeParameterNames)
                            .build();
                    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

     * entity.
     */
    private void setUpMockRepository() {
        final ClassOrInterfaceTypeDetails mockRepositoryDetails = mock(ClassOrInterfaceTypeDetails.class);
        final FieldMetadata mockFieldMetadata = mock(FieldMetadata.class);
        final JavaType mockRepositoryType = mock(JavaType.class);
        when(mockRepositoryType.getSimpleTypeName()).thenReturn("ClinicRepo");
        when(mockIdType.getFullyQualifiedTypeName()).thenReturn(
                Long.class.getName());
        when(mockRepositoryDetails.getName()).thenReturn(mockRepositoryType);
        when(mockFieldMetadata.getFieldType()).thenReturn(mockIdType);
        when(mockRepositoryLocator.getRepositories(mockTargetEntity))
View Full Code Here

    public void addFieldAnnotation(
            final DeclaredFieldAnnotationDetails declaredFieldAnnotationDetails) {
        if (declaredFieldAnnotationDetails == null) {
            return;
        }
        final JavaType declaredBy = PhysicalTypeIdentifier
                .getJavaType(declaredFieldAnnotationDetails.getField()
                        .getDeclaredByMetadataId());
        final boolean hasAnnotation = MemberFindingUtils.getAnnotationOfType(
                declaredFieldAnnotationDetails.getField().getAnnotations(),
                declaredFieldAnnotationDetails.getFieldAnnotation()
                        .getAnnotationType()) != null;
        if (!declaredFieldAnnotationDetails.isRemoveAnnotation()) {
            Validate.isTrue(
                    !hasAnnotation,
                    "Field annotation '@%s' is already present on the target field '%s.%s' (ITD target '%s')",
                    declaredFieldAnnotationDetails.getFieldAnnotation()
                            .getAnnotationType().getSimpleTypeName(),
                    declaredBy.getFullyQualifiedTypeName(),
                    declaredFieldAnnotationDetails.getField().getFieldName()
                            .getSymbolName(),
                    aspect.getFullyQualifiedTypeName());
        }
        else {
            Validate.isTrue(
                    hasAnnotation,
                    "Field annotation '@%s' cannot be removed as it is not present on the target field '%s.%s' (ITD target '%s')",
                    declaredFieldAnnotationDetails.getFieldAnnotation()
                            .getAnnotationType().getSimpleTypeName(),
                    declaredBy.getFullyQualifiedTypeName(),
                    declaredFieldAnnotationDetails.getField().getFieldName()
                            .getSymbolName(),
                    aspect.getFullyQualifiedTypeName());
        }
        fieldAnnotations.add(declaredFieldAnnotationDetails);
View Full Code Here

    public void addMethodAnnotation(
            final DeclaredMethodAnnotationDetails declaredMethodAnnotationDetails) {
        if (declaredMethodAnnotationDetails == null) {
            return;
        }
        final JavaType declaredBy = PhysicalTypeIdentifier
                .getJavaType(declaredMethodAnnotationDetails
                        .getMethodMetadata().getDeclaredByMetadataId());
        final boolean hasAnnotation = MemberFindingUtils.getAnnotationOfType(
                declaredMethodAnnotationDetails.getMethodMetadata()
                        .getAnnotations(), declaredMethodAnnotationDetails
                        .getMethodAnnotation().getAnnotationType()) != null;
        Validate.isTrue(
                !hasAnnotation,
                "Method annotation '@%s' is already present on the target field '%s.%s' (ITD target '%s')",
                declaredMethodAnnotationDetails.getMethodAnnotation()
                        .getAnnotationType().getSimpleTypeName(),
                declaredBy.getFullyQualifiedTypeName(),
                declaredMethodAnnotationDetails.getMethodMetadata()
                        .getMethodName().getSymbolName(),
                aspect.getFullyQualifiedTypeName());
        methodAnnotations.add(declaredMethodAnnotationDetails);
    }
View Full Code Here

        // Lookup the parameters and their names
        if (methodDeclaration.getParameters() != null) {
            for (final Parameter p : methodDeclaration.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) {
                    for (final AnnotationExpr candidate : annotationsList) {
                        final AnnotationMetadata annotationMetadata = JavaParserAnnotationMetadataBuilder
                                .getInstance(candidate, compilationUnitServices)
                                .build();
                        annotations.add(annotationMetadata);
                    }
                }
                final AnnotatedJavaType param = new AnnotatedJavaType(
                        parameterType, annotations);
                param.setVarArgs(p.isVarArgs());
                parameterTypes.add(param);
                parameterNames.add(new JavaSymbolName(p.getId().getName()));
            }
        }

        if (methodDeclaration.getThrows() != null) {
            for (final NameExpr throwsType : methodDeclaration.getThrows()) {
                final JavaType throwing = JavaParserUtils
                        .getJavaType(compilationUnitServices, throwsType,
                                fullTypeParameters);
                throwsTypes.add(throwing);
            }
        }
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.