Menu

IntersectionType and TypeReference

Developers
2011-06-24
2012-10-08
  • Andrea Poli

    Andrea Poli - 2011-06-24

    Hi, I tried to create a TypeReference of an IntersectionType using
    recoder.kit.TypeKit and I received the following exception:

    java.lang.IllegalArgumentException: foo.A & foo.B & foo.C is not a valid java identifier
    

    where foo.A, foo.B and foo.C are the three classes the IntersectionType is
    composed of.
    This is the type relation: fooA > foo.B > foo.C where X > Y means X is super
    class of Y.
    I decided to take foo.A as type and then to create a type reference related to
    foo.A.
    I'd like to know if this is right.

    Thanks a lot :-)

     
  • Tobias Gutzmann

    Tobias Gutzmann - 2011-06-26

    Hej,

    An Intersection type where a class is a superclass of another one should not
    occur... Can you provide a minimal example where this is the case anyway?
    Because it appears to be a bug then.

    In general, intersection type cannot be defined explicitly; they are defined
    implicitly, e.g.:
    A a; // let A implement both I1 and I2
    B b; // let B implement both I1 and I2 as well

    (expr ? a : b).foo();
    now, there is an intersection type I1 & I2. foo can be defined by either of
    the two interfaces.
    If you, e.g., want to refactor (expr ? a : b) into a variable:
    temp = expr ? a : b;
    temp.foo();

    you need to choose the right static type for temp. You may use
    recoder.kit.transformation.java5to4.Util.getRequiredContextType(SourceInfo,
    Expression)

    Take care: The method will probably be moved in an upcoming release. It's also
    not 100% tested yet, though it works fine for a lot of projects, including
    javac and all the things you get when downloading the complete JDK source:
    http://download.java.net/jdk6/source/

    Hope this helps.
    /Tobias

     

Log in to post a comment.