123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406 |
- /*******************************************************************************
- * Copyright (c) 2004 IBM
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andy Clement - initial API and implementation
- *******************************************************************************/
- package org.aspectj.systemtest.ajc150;
-
- import java.io.File;
- import java.util.List;
-
- import junit.framework.Test;
-
- import org.aspectj.asm.AsmManager;
- import org.aspectj.asm.IHierarchy;
- import org.aspectj.asm.IProgramElement;
- import org.aspectj.asm.internal.Relationship;
- import org.aspectj.testing.XMLBasedAjcTestCase;
-
- public class AnnotationBinding extends XMLBasedAjcTestCase {
-
- public static Test suite() {
- return XMLBasedAjcTestCase.loadSuite(AnnotationBinding.class);
- }
-
- protected File getSpecFile() {
- return new File("../tests/src/org/aspectj/systemtest/ajc150/ajc150.xml");
- }
-
- ///////////////////////////////////// @ANNOTATION and CALL
-
- // Very simple annotation binding for 'call() && @annotation()'
- public void testCallAnnotationBinding1() {
- runTest("call annotation binding 1");
- }
-
- // 'call() && @annotation()' when the called method has multiple arguments
- public void testCallAnnotationBinding2() {
- runTest("call annotation binding 2");
- }
-
- // 'call() && @annotation()' when the called method takes primitive arguments (YUCK!)
- public void testCallAnnotationBinding3() {
- runTest("call annotation binding 3");
- }
-
- // 'call() && @annotation()' when runtime type will exhibit different annotation (due to interface implementing)
- public void testCallAnnotationBinding4() {
- runTest("call annotation binding 4");
- }
-
- // 'call() && @annotation()' when target doesnt have an annotation !
- public void testCallAnnotationBinding5() {
- runTest("call annotation binding 5");
- }
-
- // 'call() && @annotation()' when runtime type will exhibit different annotation (due to subclassing)
- public void testCallAnnotationBinding6() {
- runTest("call annotation binding 6");
- }
-
- // 'call() && @annotation()' using named pointcut
- public void testCallAnnotationBinding7() {
- runTest("call annotation binding 7");
- }
-
- ///////////////////////////////////// @TARGET
-
- // 'call() && @target()'
- public void testAtTargetAnnotationBinding1() {
- runTest("@target annotation binding 1");
- }
-
- // 'call() && @target() && @target'
- public void testAtTargetAnnotationBinding2() {
- runTest("@target annotation binding 2");
- }
-
- // 'call() && @target()' - using a type hierarchy where some levels are missing annotations
- public void testAtTargetAnnotationBinding3() {
- runTest("@target annotation binding 3");
- }
-
- // 'call() && @target()' - using a type hierarchy where some levels are missing annotations
- // but the annotation is inherited
- public void testAtTargetAnnotationBinding4() {
- runTest("@target annotation binding 4");
- }
-
- // @target() with an annotation in a package
- public void testAtTargetAnnotationBinding5() {
- runTest("@target annotation binding 5");
- }
-
-
- ///////////////////////////////////// @THIS
-
- // 'call() && @this()'
- public void testAtThisAnnotationBinding1() {
- runTest("@this annotation binding 1");
- }
-
- // 'call() && @this() && @this'
- public void testAtThisAnnotationBinding2() {
- runTest("@this annotation binding 2");
- }
-
- // 'call() && @this()' - using a type hierarchy where some levels are missing annotations
- public void testAtThisAnnotationBinding3() {
- runTest("@this annotation binding 3");
- }
-
- // 'call() && @this()' - using a type hierarchy where some levels are missing annotations
- // but the annotation is inherited
- public void testAtThisAnnotationBinding4() {
- runTest("@this annotation binding 4");
- }
-
- // '@this() and @target()' used together
- public void testAtThisAtTargetAnnotationBinding() {
- runTest("@this annotation binding 5");
- }
-
- ///////////////////////////////////// @ARGS
-
- // complex case when there are 3 parameters
- public void testAtArgs1() {
- runTest("@args annotation binding 1");
- }
-
- // simple case when there is only one parameter
- public void testAtArgs2() {
- runTest("@args annotation binding 2");
- }
-
- // simple case when there is only one parameter and no binding
- public void testAtArgs3() {
- runTest("@args annotation binding 3");
- }
-
- // complex case binding different annotation kinds
- public void testAtArgs4() {
- runTest("@args annotation binding 4");
- }
-
- // check @args and execution()
- public void testAtArgs5() {
- runTest("@args annotation binding 5");
- }
-
-
- ///////////////////////////////////// @ANNOTATION and EXECUTION
-
- // 'execution() && @annotation()'
- public void testExecutionAnnotationBinding1() {
- runTest("execution and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and SET
-
- // 'set() && @annotation()'
- public void testFieldAnnotationBinding1() {
- runTest("set and @annotation");
- }
-
- // 'get() && @annotation()'
- public void testFieldAnnotationBinding2() {
- runTest("get and @annotation");
- }
-
- // 'get() && @annotation()' when using array fields
- public void testFieldAnnotationBinding3() {
- runTest("get and @annotation with arrays");
- }
-
- ///////////////////////////////////// @ANNOTATION and CTOR-CALL
-
- // 'ctor-call(new) && @annotation()'
- public void testCtorCallAnnotationBinding1() {
- runTest("cons call and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and CTOR-CALL
-
- // 'ctor-execution() && @annotation()'
- public void testCtorExecAnnotationBinding1() {
- runTest("cons exe and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and STATICINITIALIZATION
-
- // 'staticinitialization() && @annotation()'
- public void testStaticInitAnnotationBinding1() {
- runTest("staticinit and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and PREINITIALIZATION
-
- // 'preinitialization() && @annotation()'
- public void testPreInitAnnotationBinding1() {
- runTest("preinit and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and INITIALIZATION
-
- // 'initialization() && @annotation()'
- public void testInitAnnotationBinding1() {
- runTest("init and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and ADVICEEXECUTION
-
- // 'adviceexecution() && @annotation()'
- public void testAdviceExecAnnotationBinding1() {
- runTest("adviceexecution and @annotation");
- }
-
- ///////////////////////////////////// @ANNOTATION and HANDLER
-
- // 'handler() && @annotation()'
- public void testHandlerAnnotationBinding1() {
- runTest("handler and @annotation");
- }
-
- ///////////////////////////////////// @WITHIN
-
- // '@within()'
- public void testWithinBinding1() {
- runTest("@within");
- }
-
- //'@within()' but multiple types around (some annotated)
- public void testWithinBinding2() {
- runTest("@within - multiple types");
- }
-
- ///////////////////////////////////// @WITHINCODE
-
- // '@withincode() && call(* println(..))'
- public void testWithinCodeBinding1() {
- runTest("@withincode() and call(* println(..))");
- }
-
-
- ///////////////////////////////////// @ANNOTATION complex tests
-
- // Using package names for the types (including the annotation) - NO BINDING
- public void testPackageNamedTypesNoBinding() {
- runTest("packages and no binding");
- }
-
- // Using package names for the types (including the annotation) - INCLUDES BINDING
- public void testPackageNamedTypesWithBinding() {
- runTest("packages and binding");
- }
-
- // declare parents: @Color * implements Serializable
- public void testDeclareParentsWithAnnotatedAnyPattern() {
- runTest("annotated any pattern");
- }
-
- // Should error (in a nice way!) on usage of an annotation that isnt imported
- public void testAnnotationUsedButNotImported() {
- runTest("annotation not imported");
- }
-
- // Binding with calls/executions of static methods
- public void testCallsAndExecutionsOfStaticMethods() {
- runTest("binding with static methods");
- }
-
- /////////////////////////////////////////////////////////////////////////////////
- // annotation binding with ITDs
-
- public void testAnnotationBindingAndITDs1() {
- runTest("simple binding annotation values where itd method is annotated");
- }
-
- public void testAnnotationBindingAndITDs2() {
- runTest("simple binding annotation values where itd field is annotated");
- }
-
- public void testAnnotationBindingAndITDs3() {
- runTest("simple binding annotation values where itd ctor is annotated");
- }
-
- public void testAnnotationBindingAndITDs4() {
- runTest("simple binding annotation values where itd method is annotated via declare");
- }
-
- public void testAnnotationBindingAndITDs5() {
- runTest("simple binding annotation values where itd field is annotated via declare");
- }
-
- public void testAnnotationBindingAndITDs6() {
- runTest("simple binding annotation values where itd field is annotated multiple times via declare");
- }
-
- public void testAnnotationBindingAndITDs7() {
- runTest("simple binding annotation values where itd ctor is annotated via declare");
- }
-
- public void testAnnotationBindingAndITDs4_asmtest() {
- //AsmManager.setReporting("c:/debug.txt",true,true,true,true);
- runTest("simple binding annotation values where itd method is annotated via declare");
-
- if (getCurrentTest().canRunOnThisVM()) {
- IHierarchy top = AsmManager.getDefault().getHierarchy();
-
- IProgramElement ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
- "declare @method: int A.m() : @Fruit(\"orange\")");
- assertTrue("Couldn't find 'declare @method' element in the tree",ipe!=null);
-
- List l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_METHOD,
- "declare @method: int A.n() : @Fruit(\"banana\")");
- assertTrue("Couldn't find 'declare @method element in the tree",ipe!=null);
-
- l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- Relationship rel = (Relationship)l.get(0);
- assertTrue("Should have 1 target but has "+rel.getTargets().size(),rel.getTargets().size()==1);
- String tgt = (String)rel.getTargets().get(0);
- int lineNumber = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(tgt);
- assertTrue("Should point to line 10 but doesnt: "+lineNumber,lineNumber == 10);
- }
- }
-
- public void testAnnotationBindingAndITDs5_asmtest() {
- // AsmManager.setReporting("c:/debug.txt",true,true,true,true);
- runTest("simple binding annotation values where itd field is annotated via declare");
-
- if (getCurrentTest().canRunOnThisVM()) {
- IHierarchy top = AsmManager.getDefault().getHierarchy();
-
- IProgramElement ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD,
- "declare @field: int A.i : @Fruit(\"orange\")");
- assertTrue("Couldn't find 'declare @type' element in the tree",ipe!=null);
-
- List l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_FIELD,
- "declare @field: java.lang.String A.j : @Fruit(\"banana\")");
- assertTrue("Couldn't find 'declare @field element in the tree",ipe!=null);
-
- l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- Relationship rel = (Relationship)l.get(0);
- assertTrue("Should have 1 target but has "+rel.getTargets().size(),rel.getTargets().size()==1);
- String tgt = (String)rel.getTargets().get(0);
- int lineNumber = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(tgt);
- assertTrue("Should point to line 10 but doesnt: "+lineNumber,lineNumber == 10);
-
- }
- }
-
- public void testAnnotationBindingAndITDs7_asmtest() {
- // AsmManager.setReporting("c:/debug.txt",true,true,true,true);
- runTest("simple binding annotation values where itd ctor is annotated via declare");
-
- if (getCurrentTest().canRunOnThisVM()) {
- IHierarchy top = AsmManager.getDefault().getHierarchy();
-
- IProgramElement ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,
- "declare @constructor: A.new(java.lang.String) : @Fruit(\"pear\")");
- assertTrue("Couldn't find 'declare @constructor' element in the tree",ipe!=null);
-
- List l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- ipe = top.findElementForLabel(top.getRoot(),
- IProgramElement.Kind.DECLARE_ANNOTATION_AT_CONSTRUCTOR,
- "declare @constructor: A.new(int) : @Fruit(\"orange\")");
- assertTrue("Couldn't find 'declare @constructor element in the tree",ipe!=null);
-
- l = AsmManager.getDefault().getRelationshipMap().get(ipe);
- assertTrue("Should have a relationship but does not ",l.size()>0);
-
- Relationship rel = (Relationship)l.get(0);
- assertTrue("Should have 1 target but has "+rel.getTargets().size(),rel.getTargets().size()==1);
- String tgt = (String)rel.getTargets().get(0);
- int lineNumber = AsmManager.getDefault().getHandleProvider().getLineNumberForHandle(tgt);
- assertTrue("Should point to line 10 but doesnt: "+lineNumber,lineNumber == 10);
-
- }
- }
-
- public void testAnnotationBindingArgsVerifyError_pr92053() {
- runTest("AtArgs causes a VerifyError: Unable to pop operand off an empty stack");
- }
-
- }
|