1
1
/*
2
- * Copyright 2009-2020 the original author or authors.
2
+ * Copyright 2009-2021 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
15
15
*/
16
16
package org .eclipse .jdt .core .groovy .tests .builder ;
17
17
18
+ import static org .eclipse .jdt .groovy .core .tests .GroovyBundle .isAtLeastGroovy ;
18
19
import static org .junit .Assert .assertEquals ;
20
+ import static org .junit .Assume .assumeTrue ;
19
21
20
22
import java .util .Arrays ;
21
23
@@ -67,12 +69,12 @@ public void testStaticTypeCheckingDSL1() throws Exception {
67
69
" storeType(var, robotClass)\n " +
68
70
" handled = true\n " +
69
71
" }\n " +
70
- "}" );
72
+ "}\n " );
71
73
env .addGroovyClass (projPath .append ("src" ), "Robot" ,
72
74
"@groovy.transform.TypeChecked(extensions = 'RobotMove.groovy')\n " +
73
75
"void operate() {\n " +
74
76
" robot.move \" left\" \n " +
75
- "}" );
77
+ "}\n " );
76
78
//@formatter:on
77
79
78
80
env .fullBuild (projPath );
@@ -97,7 +99,7 @@ public void testStaticTypeCheckingDSL2() throws Exception {
97
99
" storeType(var, robotClass)\n " +
98
100
" handled = true\n " +
99
101
" }\n " +
100
- "}" );
102
+ "}\n " );
101
103
env .addGroovyClass (projPath .append ("src" ), "RobotScript" ,
102
104
"import groovy.transform.TypeChecked\n " +
103
105
"class Robot {\n " +
@@ -107,11 +109,52 @@ public void testStaticTypeCheckingDSL2() throws Exception {
107
109
"@TypeChecked(extensions = 'RobotMove.groovy')\n " +
108
110
"void operate() {\n " +
109
111
" robot.move \" left\" \n " +
110
- "}" );
112
+ "}\n " );
111
113
//@formatter:on
112
114
113
115
env .fullBuild (projPath );
114
116
Problem [] problems = env .getProblemsFor (projPath );
115
117
assertEquals ("Should have found no problems in:\n " + Arrays .toString (problems ), 0 , problems .length );
116
118
}
119
+
120
+ @ Test // GROOVY-6328
121
+ public void testStaticTypeCheckingDSL3 () throws Exception { assumeTrue (isAtLeastGroovy (40 ));
122
+ Activator .getInstancePreferences ().putBoolean (Activator .GROOVY_SCRIPT_FILTERS_ENABLED , true );
123
+ Activator .getInstancePreferences ().put (Activator .GROOVY_SCRIPT_FILTERS , "src/*Checker.groovy,y" );
124
+
125
+ IPath projPath = createGenericProject ();
126
+ //@formatter:off
127
+ env .addGroovyClass (projPath .append ("src" ), "TypeChecker" ,
128
+ "onMethodSelection { expr, node ->\n " +
129
+ " context.enclosingBinaryExpression.putNodeMetaData('notified', true)\n " +
130
+ "}\n " );
131
+ //@formatter:on
132
+
133
+ for (String methods : new String [] {"" , "void setS(String s) {this.s = s}" }) {
134
+ env .addGroovyClass (projPath .append ("src" ), "TestScript" ,
135
+ "import static org.codehaus.groovy.control.CompilePhase.INSTRUCTION_SELECTION\n " +
136
+ "class C {\n " +
137
+ " String s\n " +
138
+ " " + methods + "\n " +
139
+ "}\n " +
140
+ "C make(@DelegatesTo(value=C.class, strategy=Closure.DELEGATE_FIRST) Closure closure) {\n " +
141
+ " new C().tap(closure)\n " +
142
+ "}\n " +
143
+ "@groovy.transform.ASTTest(phase=INSTRUCTION_SELECTION, value={\n " +
144
+ " def assignment = lookup.call('here')[0].expression\n " +
145
+ " assert assignment.getNodeMetaData('notified')\n " +
146
+ "})\n " +
147
+ "@groovy.transform.TypeChecked(extensions='TypeChecker.groovy')\n " +
148
+ "void test() {\n " +
149
+ " def c = make {\n " +
150
+ " here: s = 'foo'\n " + // expecting onMethodSelection for setter
151
+ " }\n " +
152
+ "}\n " );
153
+ //@formatter:on
154
+
155
+ env .fullBuild (projPath );
156
+ Problem [] problems = env .getProblemsFor (projPath );
157
+ assertEquals ("Should have found no problems in:\n " + Arrays .toString (problems ), 0 , problems .length );
158
+ }
159
+ }
117
160
}
0 commit comments