Skip to content

Commit

Permalink
fix: Scan method annotations (#16937)
Browse files Browse the repository at this point in the history
Fixes #16925
  • Loading branch information
Artur- authored Jun 2, 2023
1 parent d2c9916 commit 21afecd
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public FrontendMethodVisitor() {
super(Opcodes.ASM9);
}

@Override
public AnnotationVisitor visitAnnotation(String descriptor,
boolean visible) {
addSignatureToClasses(classInfo.children, descriptor);
return annotationVisitor;
}

// We are interested in the new instances created inside the method
@Override
public void visitTypeInsn(int opcode, String type) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.vaadin.flow.server.frontend.scanner;

import java.io.InputStream;
import java.lang.reflect.AnnotatedElement;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Supplier;

import org.junit.Test;
import org.objectweb.asm.ClassReader;

import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.server.frontend.scanner.ClassFinder.DefaultClassFinder;
import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.SearchFieldComponentDefinitionCreator;
import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.UISearchLayout;
import com.vaadin.flow.server.frontend.scanner.ScannerDependenciesTest.UISearchField.UISearchLayout.SearchLayoutComponentDefinitionCreator;
import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.BridgeClass;
import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.Component0;
import com.vaadin.flow.server.frontend.scanner.ScannerTestComponents.Component1;
Expand Down Expand Up @@ -242,4 +251,68 @@ public void should_visitServices() {
DepsTests.assertImportsExcludingUI(deps.getModules(),
"dynamic-component.js", "dynamic-layout.js");
}

@Test
public void should_visitMethodAnnotations() {
FrontendDependencies deps = getFrontendDependencies(
MethodAnnotationRoute.class);
DepsTests.assertImportsExcludingUI(deps.getModules(),
"./search-layout.js", "./search-field.js");
}

@Route
public static class MethodAnnotationRoute {
private MyPmo myPmo;
}

@UISearchLayout
public static class MyPmo {

@UISearchField()
public String getText() {
return "value to be displayed";
}
}

public interface ComponentDefinitionCreator<T> {

}

public @interface LinkTo {
Class<?> value();
}

@LinkTo(SearchFieldComponentDefinitionCreator.class)
public @interface UISearchField {
class SearchFieldComponentDefinitionCreator
implements ComponentDefinitionCreator<UISearchField> {
public Supplier<Component> create(UISearchField annotation,
AnnotatedElement annotatedElement) {
return () -> new SearchField();
}
}

@LinkTo(SearchLayoutComponentDefinitionCreator.class)
public @interface UISearchLayout {
class SearchLayoutComponentDefinitionCreator
implements ComponentDefinitionCreator<UISearchLayout> {
public Supplier<Component> create(UISearchLayout annotation,
AnnotatedElement annotatedElement) {
return () -> new SearchLayout();
}
}
}

@JsModule("./search-layout.js")
public static class SearchLayout extends Component {

}

@JsModule("./search-field.js")
public static class SearchField extends Component {

}

}

}

0 comments on commit 21afecd

Please sign in to comment.