QDox
  1. QDox
  2. QDOX-150

Better handler of generics in Type

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.8
    • Fix Version/s: 1.9.1
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      Suppose a method like the following

        public <T extends RequestItem> List<RequestItem> myMethod(T request) throws Exception {
            return null;
          }
      

      Using Java reflection, you will have the correct parameter instead of generic:

      public java.util.List XXX.XXXClass.myMethod(java.util.Date) throws java.lang.Exception
      

      In QDOX, we have a generic ie T as parameter:

      javaMethod.getParameters()[0].getType().getJavaClass() = T instead of java.util.Date
      

        Activity

        Show
        Vincent Siveton added a comment - You could have a glance to [1] (searching QDOX-150 ) to see the workaround. [1] https://svn.apache.org/repos/asf/maven/plugins/trunk/maven-javadoc-plugin/src/main/java/org/apache/maven/plugin/javadoc/AbstractFixJavadocMojo.java
        Hide
        Robert Scholte added a comment -

        I can't see how you get from first code-sample to the second.
        Anyhow, I see you're using type.getValue() in the AbstractFixJAvadocMojo, but I suppose you mean type.getGenericValue().
        Does this answer your question?

        Show
        Robert Scholte added a comment - I can't see how you get from first code-sample to the second. Anyhow, I see you're using type.getValue() in the AbstractFixJAvadocMojo, but I suppose you mean type.getGenericValue(). Does this answer your question?
        Robert Scholte made changes -
        Field Original Value New Value
        Assignee Robert Scholte [ rfscholte ]
        Hide
        Vincent Siveton added a comment -

        Thanks Robert, yes I see it but It doesn't seems to work. Here is a small test case and the result:

        Looking the class: test.TestQDOX150
        Looking the method: myMethod
        javaMethod.getCallSignature()=myMethod(request)
        javaMethod.getDeclarationSignature( true )=public java.util.List myMethod(T request) throws java.lang.Exception
        param(type.getValue())=T
        param(type.getGenericValue())=T
        javaMethod.getReturns().getValue()=java.util.List
        javaMethod.getReturns().getGenericValue()=java.util.List<java.lang.StringBuffer>
        

        BTW IMHO the method getDeclarationSignature() should use generic to be consistent with java.lang.reflect.Method#toString()

        Show
        Vincent Siveton added a comment - Thanks Robert, yes I see it but It doesn't seems to work. Here is a small test case and the result: Looking the class: test.TestQDOX150 Looking the method: myMethod javaMethod.getCallSignature()=myMethod(request) javaMethod.getDeclarationSignature( true )=public java.util.List myMethod(T request) throws java.lang.Exception param(type.getValue())=T param(type.getGenericValue())=T javaMethod.getReturns().getValue()=java.util.List javaMethod.getReturns().getGenericValue()=java.util.List<java.lang.StringBuffer> BTW IMHO the method getDeclarationSignature() should use generic to be consistent with java.lang.reflect.Method#toString()
        Vincent Siveton made changes -
        Attachment TestQDOX150.java [ 40281 ]
        Hide
        Robert Scholte added a comment -

        JavaMethod has been extended with getTypeParameters(), which returns the TypeParameters (what a surprise, isn't it?). This gives you the opportunity to get the real Type.
        Don't know if this is enough to solve the problem.

        btw: the getDeclarationSignature() will remain like it is. QDOX-151 has been created to get a better toString() representation

        Show
        Robert Scholte added a comment - JavaMethod has been extended with getTypeParameters(), which returns the TypeParameters (what a surprise, isn't it?). This gives you the opportunity to get the real Type. Don't know if this is enough to solve the problem. btw: the getDeclarationSignature() will remain like it is. QDOX-151 has been created to get a better toString() representation
        Hide
        Vincent Siveton added a comment -

        I updated the test case to use the following:

                        for ( int k = 0; k < javaMethod.getTypeParameters().length; k++ )
                        {
                            TypeVariable type = javaMethod.getTypeParameters()[k];
        
                            System.out.println( "param(type.getValue())=" + type.getValue() );
                            System.out.println( "param(type.getGenericValue())=" + type.getGenericValue() );
                        }
        

        which gives:

        param(type.getValue())=
        param(type.getGenericValue())=<T extends java.lang.StringBuffer>
        

        The type.getValue() should be not null...

        IMHO from an API point of view, this new (undocumented) method is baffling for a dev. Which method is recommended to use: getParameters() or getTypeParameters()?

        Show
        Vincent Siveton added a comment - I updated the test case to use the following: for ( int k = 0; k < javaMethod.getTypeParameters().length; k++ ) { TypeVariable type = javaMethod.getTypeParameters()[k]; System.out.println( "param(type.getValue())=" + type.getValue() ); System.out.println( "param(type.getGenericValue())=" + type.getGenericValue() ); } which gives: param(type.getValue())= param(type.getGenericValue())=<T extends java.lang.StringBuffer> The type.getValue() should be not null... IMHO from an API point of view, this new (undocumented) method is baffling for a dev. Which method is recommended to use: getParameters() or getTypeParameters()?
        Hide
        Robert Scholte added a comment -

        talking about API's: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html

        JavaMethod has the goal to map the methodsignature from the sourcecode. And it would be nice if we could follow the java-api somehow.
        This case is kind of weird compared to the rest of the javasyntax, because it is replacing types.
        I'm thinking of introducing methods for JavaParameter called getResolvedValue() and getResolvedGenericValue(), which would probably return the values you're expecting.

        Show
        Robert Scholte added a comment - talking about API's: http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/Method.html JavaMethod has the goal to map the methodsignature from the sourcecode. And it would be nice if we could follow the java-api somehow. This case is kind of weird compared to the rest of the javasyntax, because it is replacing types. I'm thinking of introducing methods for JavaParameter called getResolvedValue() and getResolvedGenericValue(), which would probably return the values you're expecting.
        Hide
        Robert Scholte added a comment -

        comments in QDOX-68 confirm this features works right now, so changing state to resolved

        Show
        Robert Scholte added a comment - comments in QDOX-68 confirm this features works right now, so changing state to resolved
        Robert Scholte made changes -
        Fix Version/s 1.10 [ 15020 ]
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Robert Scholte made changes -
        Fix Version/s 1.9.1 [ 15252 ]
        Fix Version/s 1.10 [ 15020 ]
        Robert Scholte made changes -
        Fix Version/s 1.9.1 [ 15252 ]
        Fix Version/s 1.10 [ 15020 ]
        Paul Hammant made changes -
        Resolution Fixed [ 1 ]
        Status Resolved [ 5 ] Reopened [ 4 ]
        Paul Hammant made changes -
        Status Reopened [ 4 ] Closed [ 6 ]
        Resolution Fixed [ 1 ]
        Fix Version/s 1.9.1 [ 15252 ]
        Fix Version/s 1.10 [ 15020 ]

          People

          • Assignee:
            Robert Scholte
            Reporter:
            Vincent Siveton
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: