/** * Indicates if the presented method compiles with the JavaBean conventions * around mutator methods (public, "set", 1 arg etc). * * @param method to evaluate (required) * @return true if the presented method is a mutator, otherwise false */ public static boolean isMutatorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return method.getMethodName().getSymbolName().startsWith("set") && method.getParameterTypes().size() == 1 && Modifier.isPublic(method.getModifier()); }
/** * Indicates if the presented method compiles with the JavaBean conventions * around accessor methods (public, "set" or "is", 0 args etc). * * @param method to evaluate (required) * @return true if the presented method is an accessor, otherwise false */ public static boolean isAccessorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return (method.getMethodName().getSymbolName().startsWith("get") || method.getMethodName() .getSymbolName().startsWith("is")) && method.getParameterTypes().isEmpty() && Modifier.isPublic(method.getModifier()); }
/** * Locates the accessor methods. * <p> * If {@link #getFieldBuilders()} returns fields created by this ITD, public * accessors will automatically be produced in the declaring class. * * @param fields * @return the accessors (never returns null) */ private List<MethodMetadataBuilder> getAccessors(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; }
/** * Locates the mutator methods. * <p> * If {@link #getFieldBuilders()} returns fields created by this ITD, public * mutators will automatically be produced in the declaring class. * * @param fields * @return the mutators (never returns null) */ private List<MethodMetadataBuilder> getMutators(final List<FieldMetadataBuilder> fields) { final List<MethodMetadataBuilder> mutators = new ArrayList<MethodMetadataBuilder>(); // Compute the names of the mutators that will be produced for (final FieldMetadataBuilder field : fields) { final JavaSymbolName requiredMutatorName = BeanInfoUtils.getMutatorMethodName(field.getFieldName()); final JavaType parameterType = field.getFieldType(); final MethodMetadata mutator = getGovernorMethod(requiredMutatorName, parameterType); if (mutator == null) { mutators.add(getMutatorMethod(field.getFieldName(), field.getFieldType())); } else { Validate.isTrue(Modifier.isPublic(mutator.getModifier()), "User provided field but failed to provide a public '%s(%s)' method in '%s'", requiredMutatorName.getSymbolName(), field.getFieldName().getSymbolName(), destination.getFullyQualifiedTypeName()); mutators.add(new MethodMetadataBuilder(mutator)); } } return mutators; }
if (method.getModifier() != 0) append(Modifier.toString(method.getModifier())); append(" ");
d.setModifiers(JavaParserUtils.getJavaParserModifier(method.getModifier())); d.setName(method.getMethodName().getSymbolName()); d.setType(returnType); if (!Modifier.isAbstract(method.getModifier()) && !PhysicalTypeCategory.INTERFACE.equals(compilationUnitServices .getPhysicalTypeCategory())) {
appendIndent(); append("declare @method: "); append(Modifier.toString(methodDetails.getMethodMetadata().getModifier())); append(" "); append(methodDetails.getMethodMetadata().getReturnType()
/** * This method generates new method instance using an existing * methodMetadata * * @param declaredByMetadataId * @param method * * @return */ private MethodMetadata getNewMethod(String declaredByMetadataId, MethodMetadata method) { // Create bodyBuilder InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine(method.getBody()); // Use the MethodMetadataBuilder for easy creation of MethodMetadata // based on existing method MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(declaredByMetadataId, method.getModifier(), method.getMethodName(), method.getReturnType(), method.getParameterTypes(), method.getParameterNames(), bodyBuilder); methodBuilder.setAnnotations(method.getAnnotations()); // ROO-3834: Including default comment structure during push-in methodBuilder.setCommentStructure(method.getCommentStructure()); return methodBuilder.build(); }
/** * Indicates if the presented method compiles with the JavaBean conventions * around mutator methods (public, "set", 1 arg etc). * * @param method to evaluate (required) * @return true if the presented method is a mutator, otherwise false */ public static boolean isMutatorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return method.getMethodName().getSymbolName().startsWith("set") && method.getParameterTypes().size() == 1 && Modifier.isPublic(method.getModifier()); }
/** * Indicates if the presented method compiles with the JavaBean conventions * around accessor methods (public, "set" or "is", 0 args etc). * * @param method to evaluate (required) * @return true if the presented method is an accessor, otherwise false */ public static boolean isAccessorMethod(final MethodMetadata method) { Validate.notNull(method, "Method is required"); return (method.getMethodName().getSymbolName().startsWith("get") || method.getMethodName() .getSymbolName().startsWith("is")) && method.getParameterTypes().isEmpty() && Modifier.isPublic(method.getModifier()); }
/** * @return all public mutator methods defined by the class and all superclasses, sorted alphabetically (never null, but may be empty) */ public List<MethodMetadata> getPublicMutators() { // We keep these in a TreeMap so the methods are output in alphabetic order /** key: string based method name, value: MethodMetadata */ TreeMap<String, MethodMetadata> map = new TreeMap<String, MethodMetadata>(); for (MemberHoldingTypeDetails holder : memberHoldingTypeDetails) { for (MethodMetadata method : holder.getDeclaredMethods()) { String mutatorName = method.getMethodName().getSymbolName(); if (Modifier.isPublic(method.getModifier()) && method.getParameterTypes().size() == 1 && mutatorName.startsWith("set")) { // We've got a public, single parameter, set method map.put(mutatorName, method); } } } return new ArrayList<MethodMetadata>(map.values()); }
/** * @param sortByAccessorName indicated to sort the returned accessors by getter name * @return all public accessor methods defined by the class and all superclasses (never null, but may be empty) */ public List<MethodMetadata> getPublicAccessors(boolean sortByAccessorName) { // We keep these in a TreeMap so the methods are output in alphabetic order /** key: string based method name, value: MethodMetadata */ TreeMap<String, MethodMetadata> map = new TreeMap<String, MethodMetadata>(); List<MethodMetadata> sortedByDetectionOrder = new ArrayList<MethodMetadata>(); for (MemberHoldingTypeDetails holder : memberHoldingTypeDetails) { for (MethodMetadata method : holder.getDeclaredMethods()) { String accessorName = method.getMethodName().getSymbolName(); if (Modifier.isPublic(method.getModifier()) && method.getParameterTypes().size() == 0 && (accessorName.startsWith("get") || accessorName.startsWith("is"))) { // We've got a public, no parameter, get|is method if (sortByAccessorName) { map.put(accessorName, method); } else { sortedByDetectionOrder.add(method); } } } } if (sortByAccessorName) { return new ArrayList<MethodMetadata>(map.values()); } return sortedByDetectionOrder; }
/** * Locates the accessor methods. * <p> * If {@link #getFieldBuilders()} returns fields created by this ITD, public * accessors will automatically be produced in the declaring class. * * @param fields * @return the accessors (never returns null) */ private List<MethodMetadataBuilder> getAccessors(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; }
/** * Locates the mutator methods. * <p> * If {@link #getFieldBuilders()} returns fields created by this ITD, public * mutators will automatically be produced in the declaring class. * * @param fields * @return the mutators (never returns null) */ private List<MethodMetadataBuilder> getMutators(final List<FieldMetadataBuilder> fields) { final List<MethodMetadataBuilder> mutators = new ArrayList<MethodMetadataBuilder>(); // Compute the names of the mutators that will be produced for (final FieldMetadataBuilder field : fields) { final JavaSymbolName requiredMutatorName = BeanInfoUtils.getMutatorMethodName(field.getFieldName()); final JavaType parameterType = field.getFieldType(); final MethodMetadata mutator = getGovernorMethod(requiredMutatorName, parameterType); if (mutator == null) { mutators.add(getMutatorMethod(field.getFieldName(), field.getFieldType())); } else { Validate.isTrue(Modifier.isPublic(mutator.getModifier()), "User provided field but failed to provide a public '%s(%s)' method in '%s'", requiredMutatorName.getSymbolName(), field.getFieldName().getSymbolName(), destination.getFullyQualifiedTypeName()); mutators.add(new MethodMetadataBuilder(mutator)); } } return mutators; }
.appendFormalLine(javaParserMethodMetadata.getBody()); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( targetId, javaParserMethodMetadata.getModifier(), javaParserMethodMetadata.getMethodName(), javaParserMethodMetadata.getReturnType(),
MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( methodMetadata.getDeclaredByMetadataId(), methodMetadata.getModifier(), methodMetadata.getMethodName(), methodMetadata.getReturnType(), annotatedGvNIXWebParameterList, methodMetadata.getParameterNames(), bodyBuilder);
bodyBuilder.appendFormalLine(method.getBody()); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( targetId, method.getModifier(), method.getMethodName(), method.getReturnType(), method.getParameterTypes(), method.getParameterNames(), bodyBuilder);
/** * {@inheritDoc} */ public void loadFaultMethodDeclaration(String declaredByMetadataId, WSCompilationUnit compilationUnitServices, List<MethodMetadata> methodMetadataList, MethodDeclaration methodDeclaration) { MethodMetadata tmpMethodMetadata; tmpMethodMetadata = JavaParserMethodMetadataBuilder.getInstance( declaredByMetadataId, methodDeclaration, compilationUnitServices, new HashSet<JavaSymbolName>()).build(); InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder(); bodyBuilder.appendFormalLine(tmpMethodMetadata.getBody()); MethodMetadataBuilder methodMetadataBuilder = new MethodMetadataBuilder( declaredByMetadataId, tmpMethodMetadata.getModifier(), tmpMethodMetadata.getMethodName(), tmpMethodMetadata.getReturnType(), tmpMethodMetadata.getParameterTypes(), tmpMethodMetadata.getParameterNames(), bodyBuilder); for (AnnotationMetadata annotationMetadata : tmpMethodMetadata .getAnnotations()) { methodMetadataBuilder.addAnnotation(annotationMetadata); } for (JavaType myJavaType : tmpMethodMetadata.getThrowsTypes()) { methodMetadataBuilder.addThrowsType(myJavaType); } methodMetadataList.add(methodMetadataBuilder.build()); }
interfaceTmpMethodMetadata.getModifier(), interfaceTmpMethodMetadata.getMethodName(), interfaceTmpMethodMetadata.getReturnType(),
appendIndent(); append("declare @method: "); append(Modifier.toString(methodDetails.getMethodMetadata().getModifier())); append(" "); append(methodDetails.getMethodMetadata().getReturnType()