Package org.springframework.roo.model

Examples of org.springframework.roo.model.JavaSymbolName


     * @return the mutator method name
     */
    public static JavaSymbolName getMutatorMethodName(
            final JavaSymbolName fieldName) {
        Validate.notNull(fieldName, "Field name required");
        return new JavaSymbolName("set"
                + StringUtils.capitalize(fieldName.getSymbolName()));
    }
View Full Code Here


    public static JavaSymbolName getPropertyNameForJavaBeanMethod(
            final MethodMetadata method) {
        Validate.notNull(method, "Method is required");
        final String name = method.getMethodName().getSymbolName();
        if (name.startsWith("set") || name.startsWith("get")) {
            return new JavaSymbolName(name.substring(3));
        }
        if (name.startsWith("is")) {
            return new JavaSymbolName(name.substring(2));
        }
        throw new IllegalStateException("Method name '" + name
                + "' does not observe JavaBean method naming conventions");
    }
View Full Code Here

    }

    public JavaSymbolName getUniqueFieldName(final String proposedName) {
        Validate.notBlank(proposedName, "Proposed field name is required");
        String candidateName = proposedName;
        while (getField(new JavaSymbolName(candidateName)) != null) {
            // The proposed field name is taken; differentiate it
            candidateName += "_";
        }
        // We've derived a unique name
        return new JavaSymbolName(candidateName);
    }
View Full Code Here

                destination.getSimpleTypeName()));
    }

    private MethodMetadataBuilder getToJsonArrayMethod(boolean includeParams) {
        // Compute the relevant method name
        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;
        }

        final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
        parameterNames.add(new JavaSymbolName("collection"));

        final List<AnnotatedJavaType> parameterTypes = AnnotatedJavaType
                .convertFromJavaTypes(parameterType);

        if (includeParams) {
            parameterTypes.add(new AnnotatedJavaType(JavaType.STRING_ARRAY));
            parameterNames.add(new JavaSymbolName("fields"));
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        final String serializer = JSON_SERIALIZER
                .getNameIncludingTypeParameters(false,
View Full Code Here

    public JavaSymbolName getToJsonArrayMethodName() {
        final String methodLabel = annotationValues.getToJsonArrayMethod();
        if (StringUtils.isBlank(methodLabel)) {
            return null;
        }
        return new JavaSymbolName(methodLabel);
    }
View Full Code Here

        return new JavaSymbolName(methodLabel);
    }

    private MethodMetadataBuilder getToJsonMethod(boolean includeParams) {
        // Compute the relevant method name
        final JavaSymbolName methodName = getToJsonMethodName();
        if (methodName == null) {
            return null;
        }

        // See if the type itself declared the method
        if (governorHasMethod(methodName)) {
            return null;
        }

        final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
        final String serializer = JSON_SERIALIZER
                .getNameIncludingTypeParameters(false,
                        builder.getImportRegistrationResolver());
        final String root = annotationValues.getRootName() != null
                && annotationValues.getRootName().length() > 0 ? ".rootName(\""
                + annotationValues.getRootName() + "\")" : "";
        bodyBuilder.appendFormalLine("return new "
                + serializer
                + "()"
                + root);
        if (annotationValues.isIso8601Dates()) {
            bodyBuilder
                    .appendFormalLine(".transform("
                    + "new flexjson.transformer.DateTransformer"
                    + "(\"yyyy-MM-dd\"), java.util.Date.class)");
        }
        bodyBuilder.appendFormalLine(
                (!includeParams ? "" : ".include(fields)")
                + ".exclude(\"*.class\")"
                + (annotationValues.isDeepSerialize() ? ".deepSerialize(this)"
                        : ".serialize(this)") + ";");

        List<AnnotatedJavaType> parameterTypes = new ArrayList<AnnotatedJavaType>();
        List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();

        if (includeParams) {
            parameterTypes.add(new AnnotatedJavaType(JavaType.STRING_ARRAY));
            parameterNames.add(new JavaSymbolName("fields"));
        }

        final MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(
                getId(), Modifier.PUBLIC, methodName, STRING, parameterTypes,
                parameterNames, bodyBuilder);
View Full Code Here

    public JavaSymbolName getToJsonMethodName() {
        final String methodLabel = annotationValues.getToJsonMethod();
        if (StringUtils.isBlank(methodLabel)) {
            return null;
        }
        return new JavaSymbolName(methodLabel);
    }
View Full Code Here

                .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

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

        // Compute the return type
        final Type rt = methodDeclaration.getType();
        returnType = JavaParserUtils.getJavaType(compilationUnitServices, rt,
                fullTypeParameters);

        // Compute the method name
        methodName = new JavaSymbolName(methodDeclaration.getName());

        // Get the body
        body = methodDeclaration.getBody() == null ? null : methodDeclaration
                .getBody().toString();
        if (body != null) {
            body = StringUtils.replace(body, "{", "", 1);
            body = body.substring(0, body.lastIndexOf("}"));
        }

        // 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()) {
View Full Code Here

            final List<FieldMetadataBuilder> fields) {
        final List<MethodMetadataBuilder> accessors = new ArrayList<MethodMetadataBuilder>();

        // Compute the names of the accessors that will be produced
        for (final FieldMetadataBuilder field : fields) {
            final JavaSymbolName requiredAccessorName = BeanInfoUtils
                    .getAccessorMethodName(field.getFieldName(),
                            field.getFieldType());
            final MethodMetadata accessor = getGovernorMethod(requiredAccessorName);
            if (accessor == null) {
                accessors.add(getAccessorMethod(field.getFieldName(),
                        field.getFieldType()));
            }
            else {
                Validate.isTrue(
                        Modifier.isPublic(accessor.getModifier()),
                        "User provided field but failed to provide a public '%s()' method in '%s'",
                        requiredAccessorName.getSymbolName(),
                        destination.getFullyQualifiedTypeName());
                accessors.add(new MethodMetadataBuilder(accessor));
            }
        }
        return accessors;
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.