|
1 | 1 | package com.vaadin.flow.server.frontend.scanner; |
2 | 2 |
|
| 3 | +import java.io.InputStream; |
| 4 | +import java.lang.reflect.AnnotatedElement; |
| 5 | +import java.net.URL; |
3 | 6 | import java.util.ArrayList; |
4 | 7 | import java.util.Arrays; |
5 | 8 | import java.util.HashSet; |
6 | 9 | import java.util.List; |
7 | 10 | import java.util.Set; |
| 11 | +import java.util.function.Supplier; |
8 | 12 |
|
9 | 13 | import org.junit.Test; |
| 14 | +import org.objectweb.asm.ClassReader; |
10 | 15 |
|
| 16 | +import com.vaadin.flow.component.Component; |
11 | 17 | import com.vaadin.flow.component.dependency.JsModule; |
12 | 18 | import com.vaadin.flow.router.Route; |
13 | 19 | import com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder; |
| 20 | +import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.SearchFieldComponentDefinitionCreator; |
| 21 | +import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.UISearchLayout; |
| 22 | +import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.UISearchLayout.SearchLayoutComponentDefinitionCreator; |
14 | 23 | import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.BridgeClass; |
15 | 24 | import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.Component0; |
16 | 25 | import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.Component1; |
@@ -242,4 +251,68 @@ public void should_visitServices() { |
242 | 251 | DepsTests.assertImportsExcludingUI(deps.getModules(), |
243 | 252 | "dynamic-component.js", "dynamic-layout.js"); |
244 | 253 | } |
| 254 | + |
| 255 | + @Test |
| 256 | + public void should_visitMethodAnnotations() { |
| 257 | + FrontendDependencies deps = getFrontendDependencies( |
| 258 | + MethodAnnotationRoute.class); |
| 259 | + DepsTests.assertImportsExcludingUI(deps.getModules(), |
| 260 | + "./search-layout.js", "./search-field.js"); |
| 261 | + } |
| 262 | + |
| 263 | + @Route |
| 264 | + public static class MethodAnnotationRoute { |
| 265 | + private MyPmo myPmo; |
| 266 | + } |
| 267 | + |
| 268 | + @UISearchLayout |
| 269 | + public static class MyPmo { |
| 270 | + |
| 271 | + @UISearchField() |
| 272 | + public String getText() { |
| 273 | + return "value to be displayed"; |
| 274 | + } |
| 275 | + } |
| 276 | + |
| 277 | + public interface ComponentDefinitionCreator<T> { |
| 278 | + |
| 279 | + } |
| 280 | + |
| 281 | + public @interface LinkTo { |
| 282 | + Class<?> value(); |
| 283 | + } |
| 284 | + |
| 285 | + @LinkTo(SearchFieldComponentDefinitionCreator.class) |
| 286 | + public @interface UISearchField { |
| 287 | + class SearchFieldComponentDefinitionCreator |
| 288 | + implements ComponentDefinitionCreator<UISearchField> { |
| 289 | + public Supplier<Component> create(UISearchField annotation, |
| 290 | + AnnotatedElement annotatedElement) { |
| 291 | + return () -> new SearchField(); |
| 292 | + } |
| 293 | + } |
| 294 | + |
| 295 | + @LinkTo(SearchLayoutComponentDefinitionCreator.class) |
| 296 | + public @interface UISearchLayout { |
| 297 | + class SearchLayoutComponentDefinitionCreator |
| 298 | + implements ComponentDefinitionCreator<UISearchLayout> { |
| 299 | + public Supplier<Component> create(UISearchLayout annotation, |
| 300 | + AnnotatedElement annotatedElement) { |
| 301 | + return () -> new SearchLayout(); |
| 302 | + } |
| 303 | + } |
| 304 | + } |
| 305 | + |
| 306 | + @JsModule("./search-layout.js") |
| 307 | + public static class SearchLayout extends Component { |
| 308 | + |
| 309 | + } |
| 310 | + |
| 311 | + @JsModule("./search-field.js") |
| 312 | + public static class SearchField extends Component { |
| 313 | + |
| 314 | + } |
| 315 | + |
| 316 | + } |
| 317 | + |
245 | 318 | } |
0 commit comments