@Override protected void onAddField(final FieldMetadataBuilder md) { Validate.isTrue(governor.getDeclaredField(md.getFieldName()) == null, "Field '%s' already defined in target type '%s' (ITD target '%s')", md.getFieldName(), governor.getName().getFullyQualifiedTypeName(), aspect.getFullyQualifiedTypeName()); Validate.isTrue(build().getDeclaredField(md.getFieldName()) == null, "Field '%s' already defined in ITD (ITD target '%s')", md.getFieldName(), aspect.getFullyQualifiedTypeName()); }
/** * 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; }
/** * 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; }
bodyBuilder.appendFormalLine("super();"); for (final FieldMetadataBuilder field : fields) { final String fieldName = field.getFieldName().getSymbolName(); bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";"); parameterNames.add(field.getFieldName());
public void addDataToField(final FieldMetadata replacement, final CustomData customData) { // If the MIDs don't match then the proposed can't be a replacement if (!replacement.getDeclaredByMetadataId().equals(getDeclaredByMetadataId())) { return; } for (final FieldMetadataBuilder existingField : getDeclaredFields()) { if (existingField.getFieldName().equals(replacement.getFieldName())) { for (final Object key : customData.keySet()) { existingField.putCustomData(key, customData.get(key)); } break; } } }
getConstantForMethodName(methodName).getFieldName()); bodyBuilder.indent();
public FieldMetadata build() { DefaultFieldMetadata md = new DefaultFieldMetadata(getCustomData().build(), getDeclaredByMetadataId(), getModifier(), buildAnnotations(), getFieldName(), getFieldType(), getFieldInitializer()); md.setCommentStructure(getCommentStructure()); return md; }
.getFieldName()); getLoggerField().getFieldName(), getEndPointField(endPoint).getFieldName() .getSymbolNameCapitalisedFirstLetter(), getEndPointField(endPoint).getFieldName());
/** * Ensures that the governor has provided field. You could indicates if * is necessary to generate the accessor and the mutator methods for this new field manually. * * @param FieldMetadataBuilder the field to include(required) * @since 2.0 */ protected final void ensureGovernorHasField(final FieldMetadataBuilder fieldMetadata, boolean includeAccessor, boolean includeMutator) { if (governorTypeDetails.getField(fieldMetadata.getFieldName()) == null) { builder.addField(fieldMetadata); } if (includeAccessor) { MethodMetadata accessorMethod = getAccessorMethod(fieldMetadata.build()); if (accessorMethod != null && governorTypeDetails.getMethod(accessorMethod.getMethodName()) == null) { builder.addMethod(accessorMethod); } } if (includeMutator) { MethodMetadata mutatorMethod = getMutatorMethod(fieldMetadata.build()); if (mutatorMethod != null && governorTypeDetails.getMethod(mutatorMethod.getMethodName()) == null) { builder.addMethod(mutatorMethod); } } }
for (final FieldMetadataBuilder targetField : targetBuilder.getDeclaredFields()) { if (targetField.getFieldType().equals(field.getFieldType()) && targetField.getFieldName().equals(field.getFieldName())) { if (!governorTypeDetails.declaresField(field.getFieldName())) { targetBuilder.addField(field);
@Override protected void onAddField(final FieldMetadataBuilder md) { Validate.isTrue(governor.getDeclaredField(md.getFieldName()) == null, "Field '%s' already defined in target type '%s' (ITD target '%s')", md.getFieldName(), governor.getName().getFullyQualifiedTypeName(), aspect.getFullyQualifiedTypeName()); Validate.isTrue(build().getDeclaredField(md.getFieldName()) == null, "Field '%s' already defined in ITD (ITD target '%s')", md.getFieldName(), aspect.getFullyQualifiedTypeName()); }
/** * Indicates whether the ITD being built has a field of the given name * * @param fieldName * @return true if the field exists in the builder, otherwise false */ private boolean hasFieldInItd(final JavaSymbolName fieldName) { for (final FieldMetadataBuilder declaredField : builder .getDeclaredFields()) { if (declaredField.getFieldName().equals(fieldName)) { return true; } } return false; }
/** * 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; }
/** * 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; }
public void addDataToField(final FieldMetadata replacement, final CustomData customData) { // If the MIDs don't match then the proposed can't be a replacement if (!replacement.getDeclaredByMetadataId().equals(getDeclaredByMetadataId())) { return; } for (final FieldMetadataBuilder existingField : getDeclaredFields()) { if (existingField.getFieldName().equals(replacement.getFieldName())) { for (final Object key : customData.keySet()) { existingField.putCustomData(key, customData.get(key)); } break; } } }
bodyBuilder.appendFormalLine("super();"); for (final FieldMetadataBuilder field : fields) { final String fieldName = field.getFieldName().getSymbolName(); bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";"); parameterNames.add(field.getFieldName());
public FieldMetadata build() { DefaultFieldMetadata md = new DefaultFieldMetadata(getCustomData().build(), getDeclaredByMetadataId(), getModifier(), buildAnnotations(), getFieldName(), getFieldType(), getFieldInitializer()); md.setCommentStructure(getCommentStructure()); return md; }
private void addToBuilder(final FieldMetadataBuilder fieldBuilder) { final JavaSymbolName fieldName = fieldBuilder.getFieldName(); if (hasField(fieldName, fieldBuilder.buildAnnotations()) || hasFieldInItd(fieldName)) { return; } builder.addField(fieldBuilder); // Check for an existing accessor in the governor final JavaType fieldType = fieldBuilder.getFieldType(); builder.addMethod(getAccessorMethod(fieldName, fieldType)); // Check for an existing mutator in the governor builder.addMethod(getMutatorMethod(fieldName, fieldType)); }
excludeFieldsInToStringAnnotation(fieldBuilder.getFieldName() .getSymbolName());
/** * Ensures that the governor has provided field. You could indicates if * is necessary to generate the accessor and the mutator methods for this new field manually. * * @param FieldMetadataBuilder the field to include(required) * @since 2.0 */ protected final void ensureGovernorHasField(final FieldMetadataBuilder fieldMetadata, boolean includeAccessor, boolean includeMutator) { if (governorTypeDetails.getField(fieldMetadata.getFieldName()) == null) { builder.addField(fieldMetadata); } if (includeAccessor) { MethodMetadata accessorMethod = getAccessorMethod(fieldMetadata.build()); if (accessorMethod != null && governorTypeDetails.getMethod(accessorMethod.getMethodName()) == null) { builder.addMethod(accessorMethod); } } if (includeMutator) { MethodMetadata mutatorMethod = getMutatorMethod(fieldMetadata.build()); if (mutatorMethod != null && governorTypeDetails.getMethod(mutatorMethod.getMethodName()) == null) { builder.addMethod(mutatorMethod); } } }