Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.1.0.M3
    • Fix Version/s: 1.1.0.RC1
    • Component/s: @ CORE
    • Labels:
      None

      Description

      when using JavaType with inner classes (e.g. as field type or method param) there are some issues.

      First the simple-name contains the $ from class.getName()

      I fixed that with

      simpleTypeName = fullyQualifiedTypeName.substring(offset+1).replace('$','.');

      in JavaType line 115.

      one issue that is still open is the handling of inner classes by the import resolver

      Thanks

        Activity

        Hide
        Michael Hunger added a comment -

        perhaps it would be possible to construct such a type not just from a string - all the parsing in JavaType is already very fragile but by doing.

        enclosing=new JavaType("com.foo.Enclosing");
        inner=new JavaType("com.foo.Enclosing.Inner",....,enclosing);
        i.e. explicitely providing the enclosing classes and using them as reference when doing:

        • getEnclosingClass()
        • getSimpleName()
        • imports
        • getFQN -> should that return a name with Enclosing$Inner or Enclosing.Inner ??? -> depends on usage in sourcecode or class file loading -> I'd rather go with the latter
        Show
        Michael Hunger added a comment - perhaps it would be possible to construct such a type not just from a string - all the parsing in JavaType is already very fragile but by doing. enclosing=new JavaType("com.foo.Enclosing"); inner=new JavaType("com.foo.Enclosing.Inner",....,enclosing); i.e. explicitely providing the enclosing classes and using them as reference when doing: getEnclosingClass() getSimpleName() imports getFQN -> should that return a name with Enclosing$Inner or Enclosing.Inner ??? -> depends on usage in sourcecode or class file loading -> I'd rather go with the latter
        Hide
        Michael Hunger added a comment -

        There are also issues with the MetadataRegistry and its triggers.
        (and JavaParser generated JavaTypes when reading inner class usage)

        e.g. for a class
        org.springframework.persistence.graph.Graph.Entity

        it returns a JavaType (annotations.getAnnotationType()) with:
        FQN: Graph.Entity
        simple Name: Entity
        package: ""

        Show
        Michael Hunger added a comment - There are also issues with the MetadataRegistry and its triggers. (and JavaParser generated JavaTypes when reading inner class usage) e.g. for a class org.springframework.persistence.graph.Graph.Entity it returns a JavaType (annotations.getAnnotationType()) with: FQN: Graph.Entity simple Name: Entity package: ""
        Hide
        Ben Alex added a comment -

        Michael, would you be able to provide a sample .java source file that Roo is unable to parse? Also if you had a chance to prepare a patch I'd be happy to apply it. Thanks.

        Show
        Ben Alex added a comment - Michael, would you be able to provide a sample .java source file that Roo is unable to parse? Also if you had a chance to prepare a patch I'd be happy to apply it. Thanks.
        Hide
        Michael Hunger added a comment -

        a sample source is simple:

        somewhere else
        @interface Graph {
        @interface Entity {}
        }

        @Graph.Entity // first problem
        class Person

        { Map.Entry entry; // second problem }

        another problem is also creating such JavaTypes with inner classes

        parsing is just one problem that occurs in the roo notification system
        the others are:
        creating and using such java-types to create CID or ITDs
        having them imported by the import-resolver (automatically)

        If you'd like to I can spend some time to provide some patches. Although I fear it won't be simple to fix the Java-Parser.

        Michael

        Show
        Michael Hunger added a comment - a sample source is simple: somewhere else @interface Graph { @interface Entity {} } @Graph.Entity // first problem class Person { Map.Entry entry; // second problem } another problem is also creating such JavaTypes with inner classes parsing is just one problem that occurs in the roo notification system the others are: creating and using such java-types to create CID or ITDs having them imported by the import-resolver (automatically) If you'd like to I can spend some time to provide some patches. Although I fear it won't be simple to fix the Java-Parser. Michael
        Hide
        Ben Alex added a comment -

        Michael, I am having trouble reproducing the problem. First of all I should say the inner type support isn't something I've ever aimed to make work completely in Roo. The only strict legal requirement is Roo can parse legal .java files. Support for creating .java source and ITD source that uses or refers to inner types is not on the roadmap for now. You can emit .java source code manually (see addon-gwt for another add-on doing this) if this represents a major inconvenience.

        Anyhow, here is my .java source:

        package com.foo;
        
        import java.util.Map;
        
        @Graph.Entity
        public class Hello {
        
            Map.Entry entry = null;
        
        }
        

        The annotation parses as I would expect:

        FQTN.......: com.foo.Graph.Entity
        Simple name: Entity
        Package....: com.foo
        

        Similarly the Map field parses as I would expect:

        FQTN.......: java.util.Map.Entry
        Simple name: Entry
        Package....: java.util
        

        Do you mind if I close this ticket?

        Show
        Ben Alex added a comment - Michael, I am having trouble reproducing the problem. First of all I should say the inner type support isn't something I've ever aimed to make work completely in Roo. The only strict legal requirement is Roo can parse legal .java files. Support for creating .java source and ITD source that uses or refers to inner types is not on the roadmap for now. You can emit .java source code manually (see addon-gwt for another add-on doing this) if this represents a major inconvenience. Anyhow, here is my .java source: package com.foo; import java.util.Map; @Graph.Entity public class Hello { Map.Entry entry = null ; } The annotation parses as I would expect: FQTN.......: com.foo.Graph.Entity Simple name: Entity Package....: com.foo Similarly the Map field parses as I would expect: FQTN.......: java.util.Map.Entry Simple name: Entry Package....: java.util Do you mind if I close this ticket?

          People

          • Assignee:
            Ben Alex
            Reporter:
            Michael Hunger
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: