15
15
*/
16
16
package com .vaadin .flow .server .frontend .scanner ;
17
17
18
+ import java .util .LinkedHashSet ;
18
19
import java .util .Set ;
19
20
20
21
import org .objectweb .asm .AnnotationVisitor ;
36
37
* A class visitor for Flow components.
37
38
* <p>
38
39
* For internal use only. May be renamed or removed in a future release.
39
- * <p>
40
- * For internal use only. May be renamed or removed in a future release.
41
40
*
42
41
* @since 2.0
43
42
*/
@@ -60,6 +59,50 @@ final class FrontendClassVisitor extends ClassVisitor {
60
59
private final AnnotationVisitor jScriptVisitor ;
61
60
private ClassInfo classInfo ;
62
61
62
+ private static final class JSAnnotationVisitor
63
+ extends RepeatedAnnotationVisitor {
64
+
65
+ boolean currentDevOnly = false ;
66
+ private String currentModule ;
67
+
68
+ private LinkedHashSet <String > target ;
69
+ private LinkedHashSet <String > targetDevelopmentOnly ;
70
+
71
+ public JSAnnotationVisitor (LinkedHashSet <String > target ,
72
+ LinkedHashSet <String > targetDevelopmentOnly ) {
73
+ this .target = target ;
74
+ this .targetDevelopmentOnly = targetDevelopmentOnly ;
75
+ }
76
+
77
+ @ Override
78
+ public void visit (String name , Object value ) {
79
+ if (name .equals ("developmentOnly" )) {
80
+ Boolean developmentOnly = (Boolean ) value ;
81
+ if (developmentOnly != null && developmentOnly ) {
82
+ currentDevOnly = true ;
83
+ }
84
+ } else if (name .equals ("value" )) {
85
+ currentModule = value .toString ();
86
+ }
87
+ }
88
+
89
+ @ Override
90
+ public void visitEnd () {
91
+ super .visitEnd ();
92
+ if (currentModule != null ) {
93
+ // This visitor is called also for the $Container annotation
94
+ if (currentDevOnly ) {
95
+ targetDevelopmentOnly .add (currentModule );
96
+ } else {
97
+ target .add (currentModule );
98
+ }
99
+ }
100
+ currentModule = null ;
101
+ currentDevOnly = false ;
102
+ }
103
+
104
+ }
105
+
63
106
private final class FrontendMethodVisitor extends MethodVisitor {
64
107
public FrontendMethodVisitor () {
65
108
super (Opcodes .ASM9 );
@@ -177,19 +220,11 @@ public void visit(String name, Object value) {
177
220
}
178
221
};
179
222
// Visitor for @JsModule annotations
180
- jsModuleVisitor = new RepeatedAnnotationVisitor () {
181
- @ Override
182
- public void visit (String name , Object value ) {
183
- classInfo .modules .add (value .toString ());
184
- }
185
- };
223
+ jsModuleVisitor = new JSAnnotationVisitor (classInfo .modules ,
224
+ classInfo .modulesDevelopmentOnly );
186
225
// Visitor for @JavaScript annotations
187
- jScriptVisitor = new RepeatedAnnotationVisitor () {
188
- @ Override
189
- public void visit (String name , Object value ) {
190
- classInfo .scripts .add (value .toString ());
191
- }
192
- };
226
+ jScriptVisitor = new JSAnnotationVisitor (classInfo .scripts ,
227
+ classInfo .scriptsDevelopmentOnly );
193
228
// Visitor all other annotations
194
229
annotationVisitor = new RepeatedAnnotationVisitor () {
195
230
@ Override
0 commit comments