15
15
*/
16
16
package org.codehaus.groovy.eclipse.dsl.tests
17
17
18
+ import groovy.test.NotYetImplemented
18
19
import groovy.transform.ToString
19
20
import groovy.transform.TupleConstructor
20
21
@@ -90,21 +91,13 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
90
91
final String bindingToString
91
92
}
92
93
93
- private void doTestOfLastBindingSet (String cuContents , String pointcutText , BindingResult ... results ) {
94
- doTestOfLastBindingSet(' p' , cuContents, pointcutText, results)
95
- }
96
-
97
- private void doTestOfLastBindingSet (String pkg , String cuContents , String pointcutText , BindingResult ... results ) {
94
+ private void doTestOfLastBindingSet (String pkg = ' p' , String cuContents , String pointcutText , BindingResult ... results ) {
98
95
GroovyCompilationUnit unit = addGroovySource(cuContents, nextUnitName(), pkg)
99
96
BindingSet bindings = evaluateForBindings(unit, pointcutText)
100
97
assertAllBindings(bindings, results)
101
98
}
102
99
103
- private void doTestOfLastMatch (String cuContents , String pointcutText , String name ) {
104
- doTestOfLastMatch(' p' , cuContents, pointcutText, name)
105
- }
106
-
107
- private void doTestOfLastMatch (String pkg , String cuContents , String pointcutText , String name ) {
100
+ private void doTestOfLastMatch (String pkg = ' p' , String cuContents , String pointcutText , String name ) {
108
101
GroovyCompilationUnit unit = addGroovySource(cuContents, nextUnitName(), pkg)
109
102
Collection<?> match = evaluateForMatch(unit, pointcutText)
110
103
assertSingleBinding(match, name)
@@ -398,12 +391,12 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
398
391
399
392
@Test
400
393
void testPackageFolder1 () {
401
- doTestOfLastMatch(' p ' , ' 2' , ' packageFolder("p")' , ' p' )
394
+ doTestOfLastMatch(' 2' , ' packageFolder("p")' , ' p' )
402
395
}
403
396
404
397
@Test
405
398
void testPackageFolder2 () {
406
- doTestOfLastMatch(' p ' , ' 2' , ' packageFolder("invalid")' , null )
399
+ doTestOfLastMatch(' 2' , ' packageFolder("invalid")' , null )
407
400
}
408
401
409
402
@Test
@@ -421,37 +414,32 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
421
414
422
415
@Test
423
416
void testNamedBinding3 () {
424
- doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) | ' +
425
- ' bind( c : fileExtension("groovy") )' ,
417
+ doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) | bind( c : fileExtension("groovy") )' ,
426
418
new BindingResult (' b' , ' org.eclipse.jdt.groovy.core.groovyNature' ),
427
419
new BindingResult (' c' , ' src/p/TestUnit_[0-9a-f]{32}.groovy' ))
428
420
}
429
421
430
422
@Test
431
423
void testNamedBinding4 () {
432
- doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) & ' +
433
- ' bind( c : fileExtension("groovy") )' ,
424
+ doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) & bind( c : fileExtension("groovy") )' ,
434
425
new BindingResult (' b' , ' org.eclipse.jdt.groovy.core.groovyNature' ),
435
426
new BindingResult (' c' , ' src/p/TestUnit_[0-9a-f]{32}.groovy' ))
436
427
}
437
428
438
429
@Test
439
430
void testNamedBinding5 () {
440
- doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) | ' +
441
- ' bind( c : fileExtension("invalid") )' ,
431
+ doTestOfLastBindingSet(' 2' , ' bind( b : nature("org.eclipse.jdt.groovy.core.groovyNature") ) | bind( c : fileExtension("invalid") )' ,
442
432
new BindingResult (' b' , ' org.eclipse.jdt.groovy.core.groovyNature' ))
443
433
}
444
434
445
435
@Test
446
436
void testNamedBinding6 () {
447
- doTestOfLastBindingSet(' 2' , ' bind( b : nature("invalid") ) & ' +
448
- ' bind( c : fileExtension("groovy") )' )
437
+ doTestOfLastBindingSet(' 2' , ' bind( b : nature("invalid") ) & bind( c : fileExtension("groovy") )' )
449
438
}
450
439
451
440
@Test
452
- void testNamedBinding6a () {
453
- doTestOfLastBindingSet(' 2' , ' bind( b : nature("invalid") ) | ' +
454
- ' bind( c : fileExtension("groovy") )' ,
441
+ void testNamedBinding7 () {
442
+ doTestOfLastBindingSet(' 2' , ' bind( b : nature("invalid") ) | bind( c : fileExtension("groovy") )' ,
455
443
new BindingResult (' c' , ' src/p/TestUnit_[0-9a-f]{32}.groovy' ))
456
444
}
457
445
@@ -463,16 +451,13 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
463
451
464
452
@Test
465
453
void testTypesNamedBinding2 () {
466
- doTestOfLastBindingSet(' 2' , ' bind( b : currentType("java.lang.Integer") ) | ' +
467
- ' bind( c : fileExtension("invalid") )' ,
454
+ doTestOfLastBindingSet(' 2' , ' bind( b : currentType("java.lang.Integer") ) | bind( c : fileExtension("invalid") )' ,
468
455
new BindingResult (' b' , ' java.lang.Integer' ))
469
456
}
470
457
471
458
@Test
472
459
void testTypesNamedBinding3 () {
473
- doTestOfLastBindingSet(' 2' ,
474
- ' bind( b : currentType("java.lang.Integer") ) | ' +
475
- ' bind( c : fileExtension("groovy") )' ,
460
+ doTestOfLastBindingSet(' 2' , ' bind( b : currentType("java.lang.Integer") ) | bind( c : fileExtension("groovy") )' ,
476
461
new BindingResult (' b' , ' java.lang.Integer' ),
477
462
new BindingResult (' c' , ' src/p/TestUnit_[0-9a-f]{32}.groovy' ))
478
463
}
@@ -653,7 +638,7 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
653
638
}
654
639
655
640
@Test
656
- void testAnnotatedByBinding7Fail () {
641
+ void testAnnotatedByBinding7 () {
657
642
addGroovySource(' @Deprecated\n class Foo { \n def f }' , ' Foo' , ' p' )
658
643
doTestOfLastBindingSet(' Foo' , ' currentType( fields("g") & bind( b : annotatedBy("java.lang.Deprecated") ) )' )
659
644
}
@@ -684,6 +669,34 @@ final class PointcutEvaluationTests extends GroovyEclipseTestSuite {
684
669
new BindingResult (' b' , ' @java.lang.Deprecated, @java.lang.Deprecated' ))
685
670
}
686
671
672
+ @NotYetImplemented @Test
673
+ void testEnclosingFieldBinding () {
674
+ addGroovySource(' @interface Tag {\n Class<? extends Closure> value()\n }' , ' Tag' , ' p' )
675
+
676
+ doTestOfLastBindingSet(''' \
677
+ |class C {
678
+ | @Tag({ x })
679
+ | protected f
680
+ |}
681
+ |''' . stripMargin(),
682
+ ' inClosure() & bind(f: enclosingField(annotatedBy("p.Tag")))' ,
683
+ new BindingResult (' f' , ' p.C.f' ))
684
+ }
685
+
686
+ @Test
687
+ void testEnclosingMethodBinding () {
688
+ addGroovySource(' @interface Tag {\n Class<? extends Closure> value()\n }' , ' Tag' , ' p' )
689
+
690
+ doTestOfLastBindingSet(''' \
691
+ |class C {
692
+ | @Tag({ x })
693
+ | void m() {}
694
+ |}
695
+ |''' . stripMargin(),
696
+ ' inClosure() & bind(m: enclosingMethod(annotatedBy("p.Tag")))' ,
697
+ new BindingResult (' m' , ' p.C.m' ))
698
+ }
699
+
687
700
@Test
688
701
void testNestedCalls1 () {
689
702
doTestOfLastBindingSet(''' \
0 commit comments