yyang-talend / gwt-ent

Automatically exported from code.google.com/p/gwt-ent
0 stars 0 forks source link

The class member of extended generics type generates invalid TypeOracle_Visitor. #35

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

  The code below generate lexically invalid TypeOracle_Visitor.java .

  @Reflectable
  class A<B extends java.util.List> {
    B b;
  }
  class C<D extends java.util.List> extends A<D>{
    D d;
  }

What is the expected output? What do you see instead?

   Scanning for additional dependencies: generated://4663315228C030854442979D3F99FD1C/com/gwtent/reflection/client/TypeOracle_Visitor.java
      Adding '392' new generated units
         Validating newly compiled units
            [ERROR] Errors in 'generated://E8F0F7DB9CA04B34EE02CDA8A32CBA3E/xxxxxxxxx/web/client/A___Reflection.java'
               [ERROR] Line 49: B cannot be resolved
               [ERROR] Line 49: Syntax error on token "extends", . expected
               See snapshot: C:\DOCUME~1\HYAMAM~1\LOCALS~1\Temp\xxxxxxxxx.web.client.A___Reflection7042553645245114911.java
            [ERROR] Errors in 'generated://A6D4338DDE28FA3EE7262778BAECBAEE/xxxxxxxxx/web/client/C___Reflection.java'
               [ERROR] Line 48: D cannot be resolved
               [ERROR] Line 48: Syntax error on token "extends", . expected
               See snapshot: C:\DOCUME~1\HYAMAM~1\LOCALS~1\Temp\xxxxxxxxx.web.client.C___Reflection8760375983145239651.java
   [ERROR] Errors in 'generated://E8F0F7DB9CA04B34EE02CDA8A32CBA3E/xxxxxxxxx/web/client/A___Reflection.java'
      [ERROR] Line 49:  B cannot be resolved
      [ERROR] Line 49:  Syntax error on token "extends", . expected
   [ERROR] Errors in 'generated://A6D4338DDE28FA3EE7262778BAECBAEE/xxxxxxxxx/web/client/C___Reflection.java'
      [ERROR] Line 48:  D cannot be resolved
      [ERROR] Line 48:  Syntax error on token "extends", . expected
   [ERROR] Cannot proceed due to previous errors

What version of the product are you using? On what operating system?

  GWT ENT (svn trunk 20100907)
  GWT 2.1 RC1 privately patched

But you may have to use GWT 2.0 to compile the code as GWT 2.1 RC1 is still 
broken.

Please provide any additional information below.

  To avoid this problem, I had to rewrite the code like this.

  @Reflectable
  class A<B extends java.util.List> {
    java.util.List b;
  }
  class C<D extends java.util.List> extends A<D>{
    java.util.List d;
  }

Original issue reported on code.google.com by hyamamot...@gmail.com on 30 Oct 2010 at 1:59

GoogleCodeExporter commented 8 years ago
I'm with GWT 2.4 and had the same issue with a class with generics. Something 
like:

public class A<T> {
T value;
...
}

I get the same error, and if I look at the snapshot the generated A_Reflection 
class error is in method:

 public void setFieldValue(Object instance, String fieldName, Object value) {
      org.sgx.editor.client.editor.event.EditorValueChangeEvent content = (org.sgx.editor.client.editor.event.EditorValueChangeEvent)instance;
      if (fieldName.equals("src")) {
        content.src=(org.sgx.editor.client.editor.Editor)value;
      } else if (fieldName.equals("value")) {
        content.value=(T extends java.lang.Object)value;
      } else if (fieldName.equals("childEvent")) {
        content.childEvent=(org.sgx.editor.client.editor.event.EditorValueChangeEvent)value;
      } else     super.setFieldValue(instance, fieldName, value);
    }

(the line content.value=(T extends java.lang.Object)value; is incorrect. I 
think the correct would be content.value=(java.lang.Object)value)

If I declare the "value" attribute using no generics like the following 
everiting works ok:

public class A<T> {
Object value;
}

Original comment by sebastigurin on 8 Feb 2012 at 3:45

GoogleCodeExporter commented 8 years ago
Same error here with the following code :

public abstract class GwtController<M extends GwtModel,V extends 
GwtViewEntryPoint> {

    protected M model;

    protected V view;

    public void setModel(M model){
        this.model = model;
    }

    public void setView(V view ){
        this.view = view;
    }
}

The error in the console reads :

Errors in 
'generated://A1EED90A4A3755FBA1AF5A2A06300BBE/ro/sft/test/view/mvc/GwtController
___Reflection.java'
               See snapshot: C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\ro.sft.test.view.mvc.GwtController___Reflection1808921376227693314.java
            Ignored 1 unit with compilation errors in first pass.
Compile with -strict or with -logLevel set to TRACE or DEBUG to see all errors.
   [ERROR] Errors in 'generated://A1EED90A4A3755FBA1AF5A2A06300BBE/ro/sft/test/view/mvc/GwtController___Reflection.java'
      [ERROR] Line 71:  M cannot be resolved
      [ERROR] Line 71:  Syntax error on token "extends", . expected
      [ERROR] Line 73:  V cannot be resolved
      [ERROR] Line 73:  Syntax error on token "extends", . expected

and the generated output would be:

    public void setFieldValue(Object instance, String fieldName, Object value) {
      ro.sft.test.view.mvc.GwtController content = (ro.sft.test.view.mvc.GwtController)instance;
      if (fieldName.equals("model")) {
        content.model=(M extends ro.sft.test.view.mvc.GwtModel)value;
      } else if (fieldName.equals("view")) {
        content.view=(V extends ro.sft.test.view.mvc.GwtViewEntryPoint)value;
      } else     super.setFieldValue(instance, fieldName, value);
    }

Original comment by victor.b...@gmail.com on 21 Mar 2012 at 5:37

GoogleCodeExporter commented 8 years ago
OK, magic trick is to make the access modifier 'private'. No idea why- it seems 
also to cause the GWT compiler to go through !! 11 !! permutations, but at 
least you can get an object of type you hoped for. 

All I did is make the fields private ( from protected or default) and provide 
getters for the value :

@Reflectable(constructors = true)
public abstract class GwtController<M extends GwtModel,V extends 
GwtViewEntryPoint> {

    private M model;

    private V view;

    public void setModel(M model){
        this.model = model;
    }

    public void setView(V view ){
        this.view = view;
    }

    public M getModel(){
        return model;
    }

    public V getView(){
        return view;
    }
}

Original comment by victor.b...@gmail.com on 21 Mar 2012 at 5:54