Announcement Announcement Module
Collapse
No announcement yet.
Constructor ITD Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Constructor ITD

    Hi,

    is there some way how to create constructor in ITD?

    I am creating methods like this
    Code:
    // Specify the desired method name
    JavaSymbolName methodName = new JavaSymbolName(methodName);
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    bodyBuilder.appendFormalLine("// method body text");
    // Use the MethodMetadataBuilder for easy creation of MethodMetadata
    MethodMetadataBuilder methodBuilder = new MethodMetadataBuilder(getId(), PUBLIC, methodName, JavaType.VOID_PRIMITIVE, bodyBuilder);
    methodBuilder.build(); // Build and return a MethodMetadata instance
    But what should I use instead of JavaType.VOID_PRIMITIVE ?

    Thanks for hints

  • #2
    You should use ConstructorMetadataBuilder instead of MethodMetadataBuilder.

    Regards,
    Stefan.

    Comment


    • #3
      Hi, thanks

      for completeness

      Code:
      private ConstructorMetadata getConstructorMethod(String constructorName) {
              
              // Check if a constructor with the same signature already exists in the target type
              final ConstructorMetadata constructor = defaultConstructorExists(constructorName);
              if (constructor != null) {
                  // If it already exists, just return the method and omit its generation via the ITD
                  return constructor;
              }
              
              // Create the method body
              InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
              // TODO create instance of dataTableLazyModel field
              bodyBuilder.appendFormalLine("// TODO create instance of dataTableLazyModel field");
              
              ConstructorMetadataBuilder constructorBuilder = new ConstructorMetadataBuilder(getId());
              constructorBuilder.setBodyBuilder(bodyBuilder);
              
              return constructorBuilder.build(); // Build and return a ConstructorMetadata instance
      	}
      
      private ConstructorMetadata defaultConstructorExists(String name) {
          	for(ConstructorMetadata constructor : governorTypeDetails.getDeclaredConstructors()) {
          		if (constructor.getClass().getName().equals(name)) {
      				return constructor;
      			}
          	}
          	return null;
          }

      Comment


      • #4
        On a related note, my colleague raised https://jira.springsource.org/browse/ROO-266 may moons ago, which I actually completed a few weeks ago.
        Alan

        Comment

        Working...
        X