Kaynağa Gözat

genericitds: the possibilities are endless.

tags/V1_5_0M3
aclement 19 yıl önce
ebeveyn
işleme
9566ac2e6d

+ 6
- 6
tests/java5/generics/itds/GenericMethodITD3.aj Dosyayı Görüntüle

@@ -5,16 +5,16 @@ class Base { }
public class GenericMethodITD3 {

public static void main(String[] argv) {
List<A> as = new ArrayList<A>();
List<B> bs = new ArrayList<B>();
Base.simple(as,bs);
List<A> as1 = new ArrayList<A>();
List<A> as2 = new ArrayList<A>();
new Base().simple(as1,as2); // ok, both List<A>
}

class A {}
class B extends A {}
}

class A {}
class B extends A {}

aspect X {
<E> void Base.simple(List<E> one,List<? extends E> two) {}
<E> void Base.simple(List<E> one,List<E> two) {}
}

+ 20
- 0
tests/java5/generics/itds/GenericMethodITD4.aj Dosyayı Görüntüle

@@ -0,0 +1,20 @@
import java.util.*;

class Base { }

public class GenericMethodITD4 {

public static void main(String[] argv) {
List<A> as = new ArrayList<A>();
List<B> bs = new ArrayList<B>();
new Base().simple(as,bs);
}

class A {}
class B extends A {}
}


aspect X {
<A,B> void Base.simple(List<A> one,List<B> two) {}
}

+ 20
- 0
tests/java5/generics/itds/GenericMethodITD5.aj Dosyayı Görüntüle

@@ -0,0 +1,20 @@
import java.util.*;

class Base { }

public class GenericMethodITD5 {

public static void main(String[] argv) {
List<A> as = new ArrayList<A>();
List<B> bs = new ArrayList<B>();
new Base().simple(as,bs);// error, first is List<A>, second is List<B>
}

}

class A {}
class B extends A {}

aspect X {
<E> void Base.simple(List<E> one,List<E> two) {}
}

+ 19
- 0
tests/java5/generics/itds/GenericMethodITD6.aj Dosyayı Görüntüle

@@ -0,0 +1,19 @@
import java.util.*;

class Base { }

public class GenericMethodITD6 {

public static void main(String[] argv) {
List<Double> as = new ArrayList<Double>();
new Base().simple(as); // ok, Double extends Number
}
}

class Super {}

class A extends Super {}

aspect X {
<E extends Number> void Base.simple(List<? extends E> list) {}
}

+ 20
- 0
tests/java5/generics/itds/ParameterizedMethodITD3.aj Dosyayı Görüntüle

@@ -0,0 +1,20 @@
import java.util.*;

class Base { }

public class ParameterizedMethodITD3 {

public static void main(String[] argv) {
List<B> bs = new ArrayList<B>();
new Base().simple(bs); // error: B is not a super type of A
}
}

class A {}

class B extends A {}


aspect X {
void Base.simple(List<? super A> list) {}
}

+ 20
- 0
tests/java5/generics/itds/ParameterizedMethodITD4.aj Dosyayı Görüntüle

@@ -0,0 +1,20 @@
import java.util.*;

class Base { }

public class ParameterizedMethodITD4 {

public static void main(String[] argv) {
List<A> as = new ArrayList<A>();
new Base().simple(as); // ok, A is a supertype of B
}
}

class A {}

class B extends A {}


aspect X {
void Base.simple(List<? super B> list) {}
}

+ 13
- 5
tests/src/org/aspectj/systemtest/ajc150/GenericsTests.java Dosyayı Görüntüle

@@ -167,14 +167,22 @@ public class GenericsTests extends XMLBasedAjcTestCase {
}
// non static
// public void testNonStaticGenericCtorITD1() {runTest("generic ctor itd - 1");}

public void testGenericMethodITD1() {runTest("generic method itd - 1");}
public void testGenericMethodITD2() {runTest("generic method itd - 2");}
public void testGenericMethodITD1() {runTest("generic method itd - 1");} // <E> ... (List<? extends E>)
public void testGenericMethodITD2() {runTest("generic method itd - 2");} // <E extends Number> ... (List<? extends E>) called incorrectly
public void testGenericMethodITD3() {runTest("generic method itd - 3");} // <E> ... (List<E>,List<E>)
public void testGenericMethodITD4() {runTest("generic method itd - 4");} // <A,B> ... (List<A>,List<B>)
public void testGenericMethodITD5() {runTest("generic method itd - 5");} // <E> ... (List<E>,List<E>) called incorrectly
public void testGenericMethodITD6() {runTest("generic method itd - 6");} // <E extends Number> ... (List<? extends E>)

public void testParameterizedMethodITD1() {runTest("parameterized method itd - 1");}
public void testParameterizedMethodITD2() {runTest("parameterized method itd - 2");}
public void testParameterizedMethodITD1() {runTest("parameterized method itd - 1");} // (List<? extends Super>)
public void testParameterizedMethodITD2() {runTest("parameterized method itd - 2");} // (List<? extends Number>) called incorrectly
public void testParameterizedMethodITD3() {runTest("parameterized method itd - 3");} // (List<? super A>) called incorrectly
public void testParameterizedMethodITD4() {runTest("parameterized method itd - 4");} // (List<? super B>)

// public void testNonStaticGenericCtorITD1() {runTest("generic ctor itd - 1");}
// public void testGenericITFSharingTypeVariable() {
// runTest("generic intertype field declaration, sharing type variable");
// }

+ 33
- 0
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml Dosyayı Görüntüle

@@ -2402,6 +2402,18 @@
</compile>
</ajc-test>


<ajc-test dir="java5/generics/itds" title="parameterized method itd - 3">
<compile files="ParameterizedMethodITD3.aj" options="-1.5">
<message kind="error" line="9" text="The method simple(List&lt;? super A&gt;) in the type X is not applicable for the arguments (List&lt;B&gt;)"/>
</compile>
</ajc-test>

<ajc-test dir="java5/generics/itds" title="parameterized method itd - 4">
<compile files="ParameterizedMethodITD4.aj" options="-1.5"/>
<run class="ParameterizedMethodITD4"/>
</ajc-test>

<ajc-test dir="java5/generics/itds" title="generic method itd - 1">
<compile files="GenericMethodITD1.aj" options="-1.5"/>
<run class="GenericMethodITD1"/>
@@ -2413,7 +2425,28 @@
<message kind="error" line="9" text="Bound mismatch: The generic method simple(List&lt;? extends E&gt;) of type X is not applicable for the arguments (List&lt;? extends A&gt;) since the type A is not a valid substitute for the bounded parameter &lt;E extends Number&gt;"/>
</compile>
</ajc-test>
<ajc-test dir="java5/generics/itds" title="generic method itd - 3">
<compile files="GenericMethodITD3.aj" options="-1.5"/>
<run class="GenericMethodITD3"/>
</ajc-test>
<ajc-test dir="java5/generics/itds" title="generic method itd - 4">
<compile files="GenericMethodITD4.aj" options="-1.5"/>
<run class="GenericMethodITD4"/>
</ajc-test>

<ajc-test dir="java5/generics/itds" title="generic method itd - 5">
<compile files="GenericMethodITD5.aj" options="-1.5">
<message kind="error" line="10" text="The method simple(List&lt;E&gt;, List&lt;E&gt;) in the type X is not applicable for the arguments (List&lt;A&gt;, List&lt;B&gt;)"/>
</compile>
</ajc-test>
<ajc-test dir="java5/generics/itds" title="generic method itd - 6">
<compile files="GenericMethodITD6.aj" options="-1.5"/>
<run class="GenericMethodITD6"/>
</ajc-test>
<ajc-test dir="java5/generics/itds" title="non static generic method itd - 2">
<compile files="NonstaticGenericCtorITD2.aj" options="-1.5"/>
<run class="NonstaticGenericCtorITD2"/>

Loading…
İptal
Kaydet