Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaSymbolName


                .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();
View Full Code Here


            return parent.getIdentifierAccessor();
        }

        // Locate the identifier field, and compute the name of the accessor
        // that will be produced
        JavaSymbolName requiredAccessorName = BeanInfoUtils
                .getAccessorMethodName(identifierField);

        // See if the user provided the field
        if (!getId().equals(identifierField.getDeclaredByMetadataId())) {
            // Locate an existing accessor
            final MethodMetadata method = entityMemberDetails.getMethod(
                    requiredAccessorName, new ArrayList<JavaType>());
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required accessor name
                // unique
                requiredAccessorName = new JavaSymbolName(
                        requiredAccessorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public accessor for
        // it
View Full Code Here

            return getIdentifierField(embeddedIdFields, EMBEDDED_ID);
        }

        // Ensure there isn't already a field called "id"; if so, compute a
        // 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(
                    DATANUCLEUS_JPA_EXTENSION);
            extensionBuilder.addStringAttribute("vendorName", "datanucleus");
            extensionBuilder.addStringAttribute("key", "gae.encoded-pk");
            extensionBuilder.addStringAttribute("value", "true");
            annotations.add(extensionBuilder);
        }

        // Compute the column name, as required
        if (!hasIdClass) {
            if (!"".equals(annotationValues.getSequenceName())) {
                String generationType = isGaeEnabled || isDatabaseDotComEnabled ? "IDENTITY"
                        : "AUTO";

                // ROO-746: Use @GeneratedValue(strategy = GenerationType.TABLE)
                // If the root of the governor declares @Inheritance(strategy =
                // InheritanceType.TABLE_PER_CLASS)
                if ("AUTO".equals(generationType)) {
                    AnnotationMetadata inheritance = governorTypeDetails
                            .getAnnotation(INHERITANCE);
                    if (inheritance == null) {
                        inheritance = getInheritanceAnnotation();
                    }
                    if (inheritance != null) {
                        final AnnotationAttributeValue<?> value = inheritance
                                .getAttribute(new JavaSymbolName("strategy"));
                        if (value instanceof EnumAttributeValue) {
                            final EnumAttributeValue enumAttributeValue = (EnumAttributeValue) value;
                            final EnumDetails details = enumAttributeValue
                                    .getValue();
                            if (details != null
                                    && details.getType().equals(
                                            INHERITANCE_TYPE)) {
                                if ("TABLE_PER_CLASS".equals(details.getField()
                                        .getSymbolName())) {
                                    generationType = "TABLE";
                                }
                            }
                        }
                    }
                }

                final AnnotationMetadataBuilder generatedValueBuilder = new AnnotationMetadataBuilder(
                        GENERATED_VALUE);
                generatedValueBuilder.addEnumAttribute("strategy",
                        new EnumDetails(GENERATION_TYPE, new JavaSymbolName(
                                generationType)));

                if (StringUtils.isNotBlank(annotationValues.getSequenceName())
                        && !(isGaeEnabled || isDatabaseDotComEnabled)) {
                    final String sequenceKey = StringUtils
                            .uncapitalize(destination.getSimpleTypeName())
                            + "Gen";
                    generatedValueBuilder.addStringAttribute("generator",
                            sequenceKey);
                    final AnnotationMetadataBuilder sequenceGeneratorBuilder = new AnnotationMetadataBuilder(
                            SEQUENCE_GENERATOR);
                    sequenceGeneratorBuilder.addStringAttribute("name",
                            sequenceKey);
                    sequenceGeneratorBuilder.addStringAttribute("sequenceName",
                            annotationValues.getSequenceName());
                    annotations.add(sequenceGeneratorBuilder);
                }
                annotations.add(generatedValueBuilder);
            }

            final String identifierColumn = StringUtils
                    .stripToEmpty(getIdentifierColumn());
            String columnName = idField.getSymbolName();
            if (StringUtils.isNotBlank(identifierColumn)) {
                // User has specified an alternate column name
                columnName = identifierColumn;
            }
View Full Code Here

            return parent.getIdentifierMutator();
        }

        // Locate the identifier field, and compute the name of the accessor
        // that will be produced
        JavaSymbolName requiredMutatorName = BeanInfoUtils
                .getMutatorMethodName(identifierField);

        final List<JavaType> parameterTypes = Arrays.asList(identifierField
                .getFieldType());
        final List<JavaSymbolName> parameterNames = Arrays
                .asList(new JavaSymbolName("id"));

        // See if the user provided the field
        if (!getId().equals(identifierField.getDeclaredByMetadataId())) {
            // Locate an existing mutator
            final MethodMetadata method = entityMemberDetails.getMethod(
                    requiredMutatorName, parameterTypes);
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required mutator name unique
                requiredMutatorName = new JavaSymbolName(
                        requiredMutatorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public mutator for it
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
View Full Code Here

        }
        if (StringUtils.isNotBlank(annotationValues.getInheritanceType())) {
            final AnnotationMetadataBuilder inheritanceBuilder = new AnnotationMetadataBuilder(
                    INHERITANCE);
            inheritanceBuilder.addEnumAttribute("strategy",
                    new EnumDetails(INHERITANCE_TYPE, new JavaSymbolName(
                            annotationValues.getInheritanceType())));
            return inheritanceBuilder.build();
        }
        return null;
    }
View Full Code Here

                return parent.getVersionAccessor();
            }
        }

        // Compute the name of the accessor that will be produced
        JavaSymbolName requiredAccessorName = BeanInfoUtils
                .getAccessorMethodName(versionField);

        // See if the user provided the field
        if (!getId().equals(versionField.getDeclaredByMetadataId())) {
            // Locate an existing accessor
            final MethodMetadata method = entityMemberDetails.getMethod(
                    requiredAccessorName, new ArrayList<JavaType>(), getId());
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required accessor name
                // unique
                requiredAccessorName = new JavaSymbolName(
                        requiredAccessorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public accessor for
        // it
View Full Code Here

            final Class<?> requiredType, final String optionContext) {
        if (StringUtils.isBlank(value)) {
            return null;
        }

        return new JavaSymbolName(value);
    }
View Full Code Here

            return null;
        }

        // Ensure there isn't already a field called "version"; if so, compute a
        // 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

            // for it
            return null;
        }

        // Compute the name of the mutator that will be produced
        JavaSymbolName requiredMutatorName = BeanInfoUtils
                .getMutatorMethodName(versionField);

        final List<JavaType> parameterTypes = Arrays.asList(versionField
                .getFieldType());
        final List<JavaSymbolName> parameterNames = Arrays
                .asList(new JavaSymbolName("version"));

        // See if the user provided the field
        if (!getId().equals(versionField.getDeclaredByMetadataId())) {
            // Locate an existing mutator
            final MethodMetadata method = entityMemberDetails.getMethod(
                    requiredMutatorName, parameterTypes, getId());
            if (method != null) {
                if (Modifier.isPublic(method.getModifier())) {
                    // Method exists and is public so return it
                    return new MethodMetadataBuilder(method);
                }

                // Method is not public so make the required mutator name unique
                requiredMutatorName = new JavaSymbolName(
                        requiredMutatorName.getSymbolName() + "_");
            }
        }

        // We declared the field in this ITD, so produce a public mutator for it
        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
View Full Code Here

        fullTypeParameters.addAll(typeParameterNames);
        final List<TypeParameter> params = constructorDeclaration
                .getTypeParameters();
        if (params != null) {
            for (final TypeParameter candidate : params) {
                final JavaSymbolName currentTypeParam = new JavaSymbolName(
                        candidate.getName());
                fullTypeParameters.add(currentTypeParam);
            }
        }

        // Get the body
        body = constructorDeclaration.getBlock().toString();
        body = StringUtils.replace(body, "{", "", 1);
        body = body.substring(0, body.lastIndexOf("}"));

        // 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) {
                    for (final AnnotationExpr candidate : annotationsList) {
                        final JavaParserAnnotationMetadataBuilder md = JavaParserAnnotationMetadataBuilder
                                .getInstance(candidate, compilationUnitServices);
                        annotations.add(md.build());
                    }
                }

                parameterTypes.add(new AnnotatedJavaType(parameterType,
                        annotations));
                parameterNames.add(new JavaSymbolName(p.getId().getName()));
            }
        }

        if (constructorDeclaration.getAnnotations() != null) {
            for (final AnnotationExpr annotation : constructorDeclaration
View Full Code Here

TOP

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

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.