Browse Source

declaremixin: check signature of factory method

tags/pre268419
aclement 15 years ago
parent
commit
a717f689d5

+ 17
- 0
tests/features164/declareMixin/CaseJ.java View File

@@ -0,0 +1,17 @@
// TESTING: invalid return type for factory method
import org.aspectj.lang.annotation.*;

public class CaseJ {
public static void main(String[]argv) { }
}

aspect X {
@DeclareMixin("A")
public static void createImplementation1() {}

@DeclareMixin("A")
public static int createImplementation2(Object o) {return 2;}
}

interface I {}


+ 15
- 0
tests/features164/declareMixin/CaseK.java View File

@@ -0,0 +1,15 @@
// TESTING: too many arguments to the factory method
import org.aspectj.lang.annotation.*;

public class CaseK {
public static void main(String[]argv) { }
}

aspect X {
@DeclareMixin("A")
public static I createImplementation1(String s,long foo) {return null;}

}

interface I {}


+ 17
- 2
tests/src/org/aspectj/systemtest/ajc164/DeclareMixinTests.java View File

@@ -21,7 +21,13 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
* In many ways the design is similar to DeclareParents now - so we have to plug in at the same points, but the code generation for
* generating the delegate object and the choice of which interfaces (and methods within those) to mixin is different.
*
* <h4>Design and test considerations:</h4><br>
* <h4>Tested:</h4><br>
* <ul>
* <li>Factory method with void or primitive return value
* <li>Check the factory method has at most one parameter
* </ul>
*
* <h4>Still to test/explore:</h4><br>
* <ul>
* <li>model relationships
* <li>incremental compilation
@@ -31,7 +37,6 @@ import org.aspectj.testing.XMLBasedAjcTestCase;
* <li>Clashing with existing methods
* <li>varying parameter type on the factory method
* <li>See CaseF - what if mixin target is not assignable to the parameter type? create cast?
* <li>Check the factory method has at most one parameter
* </ul>
*
* @author Andy Clement
@@ -84,6 +89,16 @@ public class DeclareMixinTests extends org.aspectj.testing.XMLBasedAjcTestCase {
runTest("casei");
}

// invalid return type for factory method
public void testCaseJ() {
runTest("casej");
}

// too many arguments to the factory method
public void testCaseK() {
runTest("casek");
}

// --

public static Test suite() {

+ 13
- 0
tests/src/org/aspectj/systemtest/ajc164/declareMixin.xml View File

@@ -89,5 +89,18 @@
<message kind="error" text="Types listed in the 'interfaces'"/>
</compile>
</ajc-test>
<ajc-test dir="features164/declareMixin" title="casej">
<compile files="CaseJ.java" options="-1.5">
<message kind="error" text="createImplementation1"/>
<message kind="error" text="Method 'int X.createImplementation2(java.lang.Object)': factory methods "/>
</compile>
</ajc-test>
<ajc-test dir="features164/declareMixin" title="casek">
<compile files="CaseK.java" options="-1.5">
<message kind="error" text="factory methods for a mixin can take a maximum of one parameter"/>
</compile>
</ajc-test>
</suite>

Loading…
Cancel
Save