aboutsummaryrefslogtreecommitdiffstats
path: root/tests/src/org/aspectj/systemtest/ajc150/AnnotationBinding.java
blob: ab7940e73238da6b0027bdc93f4ebf4f9cc22969 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
/*******************************************************************************
 * Copyright (c) 2004 IBM 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-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);
			assertTrue("Should point to line 10 but doesnt: "+tgt,tgt.indexOf("|10|")!=-1);
	  	}
  }  
 
  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);
			assertTrue("Should point to line 10 but doesnt: "+tgt,tgt.indexOf("|10|")!=-1);
	  	}
  }  
  
  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);
			assertTrue("Should point to line 10 but doesnt: "+tgt,tgt.indexOf("|10|")!=-1);
	  	}
  }  
  
  public void testAnnotationBindingArgsVerifyError_pr92053() {
	runTest("AtArgs causes a VerifyError: Unable to pop operand off an empty stack");
  }  
 
}