Announcement Announcement Module
Collapse
No announcement yet.
Problem with auto-import JavaTypes Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with auto-import JavaTypes

    Hello,
    I'm working on a ITD generation from a Metadata and I'm having problems with generated code since it doesn't allow me to add import via ImportRegistrationResolver. I'm following WebScaffoldMetadata's way of generate methods.

    I think that the nex snippet should auto-import the used types
    Code:
    InvocableMemberBodyBuilder bodyBuilder = new InvocableMemberBodyBuilder();
    String entityNamePlural = javaTypeMetadataHolder.getPlural();
    List<JavaType> typeParams = new ArrayList<JavaType>();
    typeParams.add(formBackingType);
    JavaType javaUtilList = new JavaType("java.util.List", 0,
            DataType.TYPE, null, typeParams);
    bodyBuilder.appendFormalLine(javaUtilList
            .getNameIncludingTypeParameters(false,
                    builder.getImportRegistrationResolver())
            .concat(" ")
            .concat(entityNamePlural.toLowerCase())
            .concat(" = ")
            .concat(formBackingType.getNameIncludingTypeParameters(false,
                    builder.getImportRegistrationResolver()))
            .concat(".")
            .concat(javaTypeMetadataHolder.getPersistenceDetails()
                    .getFindAllMethod().getMethodName().getSymbolName()
                    .concat("();")));
    should generate something like:

    Code:
    import java.util.List;
    import my.package.FormBackingType;
    ...
      // first line inside a method body
      List<FormBackingType> formBakingTypes = FormBackingType.findAllFormBakingTypes();
    but the problem is that the imports are missed.

    I put some dirty logging stuff just trying to see what is happening with the builder.getImportRegistrationResolver().getRegiste redImports(). This is what i get in the ouput just before execute "itdTypeDetails = builder.build()" in my Metadata constructor:

    Code:
    1183331232 -  imports: [java.util.List, my.package.FormBackingType]
    -2027064160 -  imports: []
    1183331232 -  imports: [java.util.List, my.package.FormBackingType]
    -2027064160 -  imports: []
    ...
    the first item is the hasCode() of the Metadata instance and imports Array is just read registeredImports from builder.getImportRegistrationResolver().getRegiste redImports(). Looks like there are two versions of my Metadata one with the right imports and the other one without them.

    I'm missing something here? I'm using the wrong method for get type names and try to auto register the used types?

    Cheers
Working...
X