use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method createCollectionEnumeration.
/**
* Create a field for a List or Set of a enumeration
*
* @param parentCid
* @param fieldType
* @param fieldName
* @param permitReservedWords
* @param sizeMin
* @param sizeMax
* @param comment
* @param notNull
* @param isList
*/
private void createCollectionEnumeration(final ClassOrInterfaceTypeDetails parentCid, JavaType fieldType, JavaSymbolName fieldName, boolean permitReservedWords, Integer sizeMin, Integer sizeMax, String comment, boolean notNull, boolean isList) {
SetField parentFieldDetails;
if (isList) {
parentFieldDetails = new SetField(parentCid.getDeclaredByMetadataId(), new JavaType(LIST.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), fieldName, fieldType, null, null, false);
} else {
parentFieldDetails = new ListField(parentCid.getDeclaredByMetadataId(), new JavaType(SET.getFullyQualifiedTypeName(), 0, DataType.TYPE, null, Arrays.asList(fieldType)), fieldName, fieldType, null, null, false);
}
parentFieldDetails.setNotNull(notNull);
if (comment != null) {
parentFieldDetails.setComment(comment);
}
if (sizeMin != null) {
parentFieldDetails.setSizeMin(sizeMin);
}
if (sizeMax != null) {
parentFieldDetails.setSizeMax(sizeMax);
}
// Handle enumeration Set
insertField(parentFieldDetails, permitReservedWords, false, true);
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class JpaFieldCreatorProvider method createChildEntityFactory.
/**
* Creates the Factory class of the child entity of relationship, only if parent entity has JPA unit tests.
*
* @param childType
* @param parentType
*/
private void createChildEntityFactory(JavaType childType, JavaType parentType) {
// Find current JPA unit tests
Set<JavaType> unitTestTypes = typeLocationService.findTypesWithAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
for (JavaType unitTestType : unitTestTypes) {
// Get the annotation @RooJpaUnitTest
ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(unitTestType);
AnnotationMetadata rooUnitTestAnnotation = cid.getAnnotation(RooJavaType.ROO_JPA_UNIT_TEST);
// Check if parent entity has JPA unit test class
AnnotationAttributeValue<Object> targetClass = rooUnitTestAnnotation.getAttribute("targetClass");
Validate.notNull(targetClass, String.format("'targetClass' attribute can't be found for annotation @RooJpaUnitTest in class %s", unitTestType.getSimpleTypeName()));
if (parentType.equals(targetClass.getValue())) {
if (jpaEntityFactoryLocator.getFirstJpaEntityFactoryForEntity(childType) == null) {
// Create factory class for child entity if doesn't exist
dataOnDemandCreatorProvider.createEntityFactory(childType);
}
break;
}
}
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class IdentifierMetadata method getParameterizedConstructor.
/**
* Locates the parameterised constructor consisting of the id fields for
* this class.
*
* @param fields
* @return the constructor, never null.
*/
private ConstructorMetadataBuilder getParameterizedConstructor(final List<FieldMetadataBuilder> fields) {
// Search for an existing constructor
final List<JavaType> parameterTypes = new ArrayList<JavaType>();
for (final FieldMetadataBuilder field : fields) {
parameterTypes.add(field.getFieldType());
}
final ConstructorMetadata result = governorTypeDetails.getDeclaredConstructor(parameterTypes);
if (result != null) {
// Found an existing parameterised constructor on this class
publicNoArgConstructor = true;
return null;
}
final List<JavaSymbolName> parameterNames = new ArrayList<JavaSymbolName>();
final InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
bodyBuilder.appendFormalLine("super();");
for (final FieldMetadataBuilder field : fields) {
final String fieldName = field.getFieldName().getSymbolName();
bodyBuilder.appendFormalLine("this." + fieldName + " = " + fieldName + ";");
parameterNames.add(field.getFieldName());
}
// Create the constructor
final ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
constructorBuilder.setModifier(Modifier.PUBLIC);
constructorBuilder.setParameterTypes(AnnotatedJavaType.convertFromJavaTypes(parameterTypes));
constructorBuilder.setParameterNames(parameterNames);
constructorBuilder.setBodyBuilder(bodyBuilder);
return constructorBuilder;
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class IdentifierMetadata method getMutators.
/**
* 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;
}
use of org.springframework.roo.model.JavaType in project spring-roo by spring-projects.
the class JpaTestCreator method createUnitTest.
@Override
public void createUnitTest(final JavaType entity) {
Validate.notNull(entity, "Class to produce an unit test class for is required");
// Check if provided JavaType is a Repository
ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(entity);
Validate.notNull(cid.getAnnotation(RooJavaType.ROO_JPA_ENTITY), "Type must be a Roo JPA Entity type.");
// Create JPA DataOnDemand artifacts
List<DataOnDemandCreatorProvider> dodCreators = getValidDataOnDemandCreatorsForType(entity);
for (DataOnDemandCreatorProvider dodCreator : dodCreators) {
dodCreator.createDataOnDemand(entity);
}
final JavaType name = new JavaType(entity + "Test", entity.getModule());
final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, Path.SRC_TEST_JAVA.getModulePathId(entity.getModule()));
if (metadataService.get(declaredByMetadataId) != null) {
// The file already exists
return;
}
// Add @RooUnitTest to source file
AnnotationMetadataBuilder rooUnitTestAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_UNIT_TEST);
rooUnitTestAnnotation.addClassAttribute("targetClass", entity);
final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.CLASS);
cidBuilder.addAnnotation(rooUnitTestAnnotation);
typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build());
}
Aggregations