public void setSuperclass(final ClassOrInterfaceTypeDetails superclass) { setSuperclass(new ClassOrInterfaceTypeDetailsBuilder(superclass)); }
public final boolean addInnerType(final ClassOrInterfaceTypeDetailsBuilder innerType) { /* * There was originally a check to see if the declaredMIDs matched, but * this doesn't really make much sense. We need to come up with a better * model for inner types. I thought about adding an enclosingType * attribute but this prototype just felt like a hack. In the short term * I have just disabled the MID comparison as I think this is fairly * reasonable until this is given some more time. JTT - 24/08/11 */ if (innerType == null) { return false; } onAddInnerType(innerType); return declaredInnerTypes.add(innerType); }
private void init(final ClassOrInterfaceTypeDetails existing) { name = existing.getName(); physicalTypeCategory = existing.getPhysicalTypeCategory(); if (existing.getSuperclass() != null) { superclass = new ClassOrInterfaceTypeDetailsBuilder(existing.getSuperclass()); } enumConstants.addAll(existing.getEnumConstants()); registeredImports.clear(); registeredImports.addAll(existing.getRegisteredImports()); }
@Override public void createInterface(final JavaType name, final LogicalPath path, final boolean permitReservedWords) { if (!permitReservedWords) { ReservedWords.verifyReservedWordsNotPresent(name); } final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, path); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, name, PhysicalTypeCategory.INTERFACE); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
@Override public void createEnum(final JavaType name, final LogicalPath path, final boolean permitReservedWords) { if (!permitReservedWords) { ReservedWords.verifyReservedWordsNotPresent(name); } final String physicalTypeId = PhysicalTypeIdentifier.createIdentifier(name, path); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(physicalTypeId, Modifier.PUBLIC, name, PhysicalTypeCategory.ENUMERATION); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); }
private void init(final MemberHoldingTypeDetails existing) { for (final ConstructorMetadata element : existing.getDeclaredConstructors()) { declaredConstructors.add(new ConstructorMetadataBuilder(element)); } for (final FieldMetadata element : existing.getDeclaredFields()) { declaredFields.add(new FieldMetadataBuilder(element)); } for (final MethodMetadata element : existing.getDeclaredMethods()) { declaredMethods.add(new MethodMetadataBuilder(element)); } for (final ClassOrInterfaceTypeDetails element : existing.getDeclaredInnerTypes()) { declaredInnerTypes.add(new ClassOrInterfaceTypeDetailsBuilder(element)); } for (final InitializerMetadata element : existing.getDeclaredInitializers()) { declaredInitializers.add(new InitializerMetadataBuilder(element)); } extendsTypes.addAll(existing.getExtendsTypes()); implementsTypes.addAll(existing.getImplementsTypes()); }
public void addEnumConstant(final String physicalTypeIdentifier, final JavaSymbolName constantName) { Validate.notBlank(physicalTypeIdentifier, "Type identifier not provided"); Validate.notNull(constantName, "Constant name required"); // Obtain the physical type and itd mutable details final PhysicalTypeMetadata ptm = (PhysicalTypeMetadata) metadataService.get(physicalTypeIdentifier); Validate.notNull(ptm, "Java source code unavailable for type %s", PhysicalTypeIdentifier.getFriendlyName(physicalTypeIdentifier)); final PhysicalTypeDetails ptd = ptm.getMemberHoldingTypeDetails(); Validate.notNull(ptd, "Java source code details unavailable for type %s", PhysicalTypeIdentifier.getFriendlyName(physicalTypeIdentifier)); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder((ClassOrInterfaceTypeDetails) ptd); // Ensure it's an enum Validate.isTrue(cidBuilder.getPhysicalTypeCategory() == PhysicalTypeCategory.ENUMERATION, "%s is not an enum", PhysicalTypeIdentifier.getFriendlyName(physicalTypeIdentifier)); cidBuilder.addEnumConstant(constantName); createOrUpdateTypeOnDisk(cidBuilder.build()); }
/** * This method adds new WebMVCThymeleafUIConfiguration.java class inside .config * package of generated project * * @param module */ private void addWebMVCThymeleafUIConfiguration(Pom module) { // Obtain the class annotated with @RooWebMvcConfiguration Set<ClassOrInterfaceTypeDetails> webMvcConfigurationSet = getTypeLocationService().findClassesOrInterfaceDetailsWithAnnotation( RooJavaType.ROO_WEB_MVC_CONFIGURATION); if (webMvcConfigurationSet == null || webMvcConfigurationSet.isEmpty()) { throw new IllegalStateException(String.format( "ERROR: Can't found configuration class annotated with @%s.", RooJavaType.ROO_WEB_MVC_CONFIGURATION)); } ClassOrInterfaceTypeDetails webMvcConfiguration = webMvcConfigurationSet.iterator().next(); // Prevent to include the @RooWebMvcThymeleafUIConfiguration more than once if (webMvcConfiguration.getAnnotation(RooJavaType.ROO_WEB_MVC_THYMELEAF_UI_CONFIGURATION) == null) { AnnotationMetadataBuilder thymeleaftConfigurationAnnotation = new AnnotationMetadataBuilder(RooJavaType.ROO_WEB_MVC_THYMELEAF_UI_CONFIGURATION); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(webMvcConfiguration);; cidBuilder.addAnnotation(thymeleaftConfigurationAnnotation); cidBuilder.addImplementsType(SpringJavaType.APPLICATION_CONTEXT_AWARE); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); } }
/** * This operation annotates a controller with the THYMELEAF annotation * * @param controller JavaType with the controller to be annotated. */ @Override public void annotate(JavaType controller) { Validate.notNull(controller, "ERROR: You must provide a valid controller"); ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller); // Check if provided controller exists on current project Validate.notNull(controllerDetails, "ERROR: You must provide an existing controller"); // Check if provided controller has been annotated with @RooController Validate.notNull(controllerDetails.getAnnotation(RooJavaType.ROO_CONTROLLER), "ERROR: You must provide a controller annotated with @RooController"); // Add Thymeleaf annotation ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(controllerDetails); typeBuilder.addAnnotation(new AnnotationMetadataBuilder(getAnnotation())); // Write changes on provided controller getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build()); }
@Override public void updateEmbeddableToIdentifier(final JavaType identifierType, final String identifierField, final String identifierColumn) { Validate.notNull(identifierType, "Identifier type required"); // Get details from existing JavaType ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(getTypeLocationService().getTypeDetails( identifierType)); // Create @RooIdentifier with getters and setters AnnotationMetadataBuilder rooIdentifier = new AnnotationMetadataBuilder(ROO_IDENTIFIER); rooIdentifier.addBooleanAttribute("settersByDefault", true); final List<AnnotationMetadataBuilder> identifierAnnotations = Arrays.asList(new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder( ROO_EQUALS), rooIdentifier); cidBuilder.setAnnotations(identifierAnnotations); // Set implement Serializable List<JavaType> implementTypes = new ArrayList<JavaType>(); implementTypes.add(JdkJavaType.SERIALIZABLE); cidBuilder.setImplementsTypes(implementTypes); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); }
/** * This operation annotates a controller with the JSON annotation * * @param controller JavaType with the controller to be annotated. */ @Override public void annotate(JavaType controller) { Validate.notNull(controller, "ERROR: You must provide a valid controller"); ClassOrInterfaceTypeDetails controllerDetails = getTypeLocationService().getTypeDetails(controller); // Check if provided controller exists on current project Validate.notNull(controllerDetails, "ERROR: You must provide an existing controller"); // Check if provided controller has been annotated with @RooController Validate.notNull(controllerDetails.getAnnotation(RooJavaType.ROO_CONTROLLER), "ERROR: You must provide a controller annotated with @RooController"); // Add JSON annotation ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(controllerDetails); typeBuilder.addAnnotation(new AnnotationMetadataBuilder(getAnnotation())); // Write changes on provided controller getTypeManagementService().createOrUpdateTypeOnDisk(typeBuilder.build()); }
@Override public void newEmbeddableClass(final JavaType name, final boolean serializable) { Validate.notNull(name, "Embeddable name required"); final String declaredByMetadataId = PhysicalTypeIdentifier.createIdentifier(name, getPathResolver().getFocusedPath(Path.SRC_MAIN_JAVA)); final List<AnnotationMetadataBuilder> annotations = new ArrayList<AnnotationMetadataBuilder>(Arrays.asList(new AnnotationMetadataBuilder( ROO_JAVA_BEAN), new AnnotationMetadataBuilder(ROO_TO_STRING), new AnnotationMetadataBuilder(EMBEDDABLE))); if (serializable) { annotations.add(new AnnotationMetadataBuilder(ROO_SERIALIZABLE)); } final int modifier = Modifier.PUBLIC; final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, modifier, name, PhysicalTypeCategory.CLASS); cidBuilder.setAnnotations(annotations); getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); getProjectOperations().addDependency(name.getModule(), new Dependency("org.springframework.boot", "spring-boot-starter-data-jpa", null)); }
if (applicationClass.getAnnotation(SpringJavaType.ENABLE_CACHING) == null) { ClassOrInterfaceTypeDetailsBuilder builder = new ClassOrInterfaceTypeDetailsBuilder(applicationClass); builder.addAnnotation(new AnnotationMetadataBuilder(SpringJavaType.ENABLE_CACHING)); getTypeManagementService().createOrUpdateTypeOnDisk(builder.build());
if (metadataService.get(declaredByMetadataId) != null) { return new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId).getName(); new ClassOrInterfaceTypeDetailsBuilder(declaredByMetadataId, Modifier.PUBLIC, dodConfigurationClass, PhysicalTypeCategory.CLASS); cidBuilder.addAnnotation(new AnnotationMetadataBuilder(
/** * Returns the additions that the caller needs to make in order to invoke * the given method * * @param callerMID the caller's metadata ID (required) * @param method the method being called (required) * @param repositoryType the type of repository being called * @param parameterNames the parameter names used by the caller * @return a non-<code>null</code> set of additions */ private MemberTypeAdditions getMethodAdditions(final String callerMID, final RepositoryJpaLayerMethod method, final JavaType repositoryType, final List<MethodParameter> parameters) { // Create a builder to hold the repository field to be copied into the // caller final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(callerMID); final AnnotationMetadataBuilder autowiredAnnotation = new AnnotationMetadataBuilder(AUTOWIRED); final String repositoryFieldName = StringUtils.uncapitalize(repositoryType.getSimpleTypeName()); cidBuilder.addField(new FieldMetadataBuilder(callerMID, 0, Arrays.asList(autowiredAnnotation), new JavaSymbolName(repositoryFieldName), repositoryType)); // Create the additions to invoke the given method on this field final String methodCall = repositoryFieldName + "." + method.getCall(parameters); return new MemberTypeAdditions(cidBuilder, method.getName(), methodCall, false, parameters); }
PhysicalTypeIdentifier.getFriendlyName(field.getDeclaredByMetadataId())); final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder((ClassOrInterfaceTypeDetails) ptd);
@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()); }
public void addEqualsAndHashCodeMethods(final JavaType javaType, final boolean appendSuper, final Set<String> excludeFields) { // Add @RooEquals annotation to class if not yet present final ClassOrInterfaceTypeDetails cid = typeLocationService.getTypeDetails(javaType); if (cid == null || cid.getTypeAnnotation(ROO_EQUALS) != null) { return; } final AnnotationMetadataBuilder annotationBuilder = new AnnotationMetadataBuilder(ROO_EQUALS); if (appendSuper) { annotationBuilder.addBooleanAttribute("appendSuper", appendSuper); } if (!CollectionUtils.isEmpty(excludeFields)) { final List<StringAttributeValue> attributes = new ArrayList<StringAttributeValue>(); for (final String excludeField : excludeFields) { attributes.add(new StringAttributeValue(new JavaSymbolName("value"), excludeField)); } annotationBuilder.addAttribute(new ArrayAttributeValue<StringAttributeValue>( new JavaSymbolName("excludeFields"), attributes)); } final ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(cid); cidBuilder.addAnnotation(annotationBuilder.build()); typeManagementService.createOrUpdateTypeOnDisk(cidBuilder.build()); } }
getPathResolver().getPath(domainModelModuleIdentifier)); final ClassOrInterfaceTypeDetailsBuilder typeBuilder = new ClassOrInterfaceTypeDetailsBuilder(mid, PUBLIC, domainModelModule, PhysicalTypeCategory.CLASS);
@Override public void addJpaAuditToEntity(JavaType entity, String createdDateColumn, String modifiedDateColumn, String createdByColumn, String modifiedByColumn) { // Getting entity details ClassOrInterfaceTypeDetails entityDetails = getTypeLocationService().getTypeDetails(entity); ClassOrInterfaceTypeDetailsBuilder cidBuilder = new ClassOrInterfaceTypeDetailsBuilder(entityDetails); // Add audit fields cidBuilder.addField(getCreatedDateField(entityDetails, createdDateColumn)); cidBuilder.addField(getModifiedDateField(entityDetails, modifiedDateColumn)); cidBuilder.addField(getCreatedByField(entityDetails, createdByColumn)); cidBuilder.addField(getModifiedByField(entityDetails, modifiedByColumn)); // Add @RooJpaAudit annotation if needed if (entityDetails.getAnnotation(RooJavaType.ROO_JPA_AUDIT) == null) { cidBuilder.addAnnotation(new AnnotationMetadataBuilder(RooJavaType.ROO_JPA_AUDIT).build()); } // Write changes on disk getTypeManagementService().createOrUpdateTypeOnDisk(cidBuilder.build()); }