Class CustomComponentHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic List<CustomComponentAddMethodInfo> addInfoFromComponentInfo(ComponentInfo componentInfo, Class<?> componentType, List<CustomComponentAddMethodInfo> methods) Enriches API methods from an already located component source, including preview sources.static List<CustomComponentAddMethodInfo> addInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) Updates add/replace flags based on its usagestatic List<CustomComponentAddMethodInfo> addInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, List<ExistingCall> existingCalls) As above, told the calls rather than reading them, so a non-Java source can answer for itself.static List<ExistingCall> callsInJavaSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) Every call this component's Java source makes, among the names asked about.static List<ExistingCall> callsInKotlinSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) Every call this component's Kotlin source makes, among the names asked about.static CustomComponentApiSelectionextractFromRequest(tools.jackson.databind.JsonNode data) CallsextractFromRequest(JsonNode, String)withcustomComponentApiSelectionkeystatic CustomComponentApiSelectionextractFromRequest(tools.jackson.databind.JsonNode data, String key) ExtractCustomComponentApiSelectionfrom the data witht the given key if present.filterMethodBasedOnDraggedComponentHierarchy(List<JavaReflectionUtil.ComponentAddableMethod> methods, List<String> draggedElementClassHierarchy) Filters the method in the custom component based on the dragged element hierarchy. e.g. when you drop an Image onto Custom Component, the listed methods should be in the hierarchy of Image.static CustomComponentResponseDatagenerateResponse(com.vaadin.flow.server.VaadinSession vaadinSession, Map<com.vaadin.flow.component.Component, ComponentTypeAndSourceLocation> allComponents, List<com.vaadin.flow.component.Component> componentsInProject) Generates the response that is used in the UIgetClassHierarchyOfJavaClassNameOrReactTagFromRequest(tools.jackson.databind.JsonNode data) Returns the hierarchy of dropped element onto a custom component.static booleanisDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, tools.jackson.databind.JsonNode data, int uiId, int nodeId) Checks if the given component is drilled down.static booleanisDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, tools.jackson.databind.JsonNode data, tools.jackson.databind.JsonNode component) Checks if the given component is drilled down
-
Method Details
-
generateResponse
public static CustomComponentResponseData generateResponse(com.vaadin.flow.server.VaadinSession vaadinSession, Map<com.vaadin.flow.component.Component, ComponentTypeAndSourceLocation> allComponents, List<com.vaadin.flow.component.Component> componentsInProject) Generates the response that is used in the UI- Parameters:
allComponents- Component and source location of all components that are found in the UIcomponentsInProject- Components that have source in the project.- Returns:
- response that contains required metadata for the custom component feature
-
isDrilledDownComponent
public static boolean isDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, tools.jackson.databind.JsonNode data, tools.jackson.databind.JsonNode component) Checks if the given component is drilled down- Parameters:
vaadinSession- Vaadin session to access componentdata- Sent data from client. It requiresACTIVE_CLASS_JSON_KEYandACTIVE_NODE_ID_JSON_KEYcomponent- JSON data that contains uiId and nodeId- Returns:
- true if drilled down component, false otherwise
-
isDrilledDownComponent
public static boolean isDrilledDownComponent(com.vaadin.flow.server.VaadinSession vaadinSession, tools.jackson.databind.JsonNode data, int uiId, int nodeId) Checks if the given component is drilled down.- Parameters:
vaadinSession- Vaadin session to access componentdata- Sent data from client. It requiresACTIVE_CLASS_JSON_KEYandACTIVE_NODE_ID_JSON_KEYuiId- uiIdnodeId- nodeId of the given component- Returns:
- true if drilled down component, false otherwise
-
getClassHierarchyOfJavaClassNameOrReactTagFromRequest
public static List<String> getClassHierarchyOfJavaClassNameOrReactTagFromRequest(tools.jackson.databind.JsonNode data) Returns the hierarchy of dropped element onto a custom component. Extracts the relevant parts from the data object.- Parameters:
data- should contain eitherjavaClassNameorreactTagto find relevant Java Class- Returns:
- list of
- Throws:
CopilotException- when something goes wrong with looking for class hierarchy
-
filterMethodBasedOnDraggedComponentHierarchy
public static List<JavaReflectionUtil.ComponentAddableMethod> filterMethodBasedOnDraggedComponentHierarchy(List<JavaReflectionUtil.ComponentAddableMethod> methods, List<String> draggedElementClassHierarchy) Filters the method in the custom component based on the dragged element hierarchy. e.g. when you drop an Image onto Custom Component, the listed methods should be in the hierarchy of Image. Methods that gets Button or any other component as parameter should be filtered out.- Parameters:
methods- List of methods that acceptComponentas parameter.draggedElementClassHierarchy- Hierarchy of dragged component. Strongly related togetClassHierarchyOfJavaClassNameOrReactTagFromRequest(JsonNode)- Returns:
- List of filtered components
-
addInfoFromComponentSource
public static List<CustomComponentAddMethodInfo> addInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) throws IOException Updates add/replace flags based on its usage- Parameters:
componentTypeAndSourceLocation- Component type and source locationmethods- Methods belonging to the given component- Returns:
- methods enriched with source information. Methods that represent distinct containers are returned once per existing call.
- Throws:
IOException
-
callsInJavaSource
public static List<ExistingCall> callsInJavaSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) throws IOException Every call this component's Java source makes, among the names asked about.Split out so the assembly below can run for any language: it is reflection and quirks apart from this one step, which is the only part that needs a parser. #9828.
Takes the same arguments as
callsInKotlinSource(com.vaadin.copilot.rewriter.ComponentTypeAndSourceLocation, java.util.List<com.vaadin.copilot.customcomponent.CustomComponentAddMethodInfo>, com.vaadin.copilot.ComponentSourceFinder)and answers the same question, so the caller picks between them on language alone and neither has to be read to know what it wants. Raised in review of #9868.- Parameters:
componentTypeAndSourceLocation- the component the dialog was opened onmethods- the candidate methods, from reflection; only calls to these are returned, which is all the assembly ever looks atsourceFinder- how to reach the component's siblings, needed to tell apart several components created on one line- Returns:
- the calls, in source order
- Throws:
IOException- if the source cannot be read
-
addInfoFromComponentInfo
public static List<CustomComponentAddMethodInfo> addInfoFromComponentInfo(ComponentInfo componentInfo, Class<?> componentType, List<CustomComponentAddMethodInfo> methods) Enriches API methods from an already located component source, including preview sources. -
callsInKotlinSource
public static List<ExistingCall> callsInKotlinSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, ComponentSourceFinder sourceFinder) throws IOException Every call this component's Kotlin source makes, among the names asked about.The mirror of
callsInJavaSource(com.vaadin.copilot.rewriter.ComponentTypeAndSourceLocation, java.util.List<com.vaadin.copilot.customcomponent.CustomComponentAddMethodInfo>, com.vaadin.copilot.ComponentSourceFinder). Reading only, so it builds its own provider as the Java side does rather than needing the write-mode one. Without it the dialog's query went through JavaParser on a.ktfile and threw, so dropping onto a component in a Kotlin view failed instead of opening the dialog. #9828.- Parameters:
componentTypeAndSourceLocation- the component the dialog was opened onmethods- the candidate methods, from reflection; only calls to these are returned, because that is how the Kotlin locator is askedsourceFinder- how to reach the component's siblings, needed to tell apart several components created on one line- Returns:
- the calls, grouped by the name they were asked under
- Throws:
IOException- if the source cannot be read
-
addInfoFromComponentSource
public static List<CustomComponentAddMethodInfo> addInfoFromComponentSource(ComponentTypeAndSourceLocation componentTypeAndSourceLocation, List<CustomComponentAddMethodInfo> methods, List<ExistingCall> existingCalls) As above, told the calls rather than reading them, so a non-Java source can answer for itself.- Parameters:
componentTypeAndSourceLocation- the component the dialog was opened onmethods- the candidate methods, from reflectionexistingCalls- the calls its source already makes- Returns:
- the methods, marked with what the source shows
-
extractFromRequest
CallsextractFromRequest(JsonNode, String)withcustomComponentApiSelectionkey- Parameters:
data- sent from the Client- Returns:
- Null if customComponentApiSelection is not present in the JSON or not an object or unable to parse
-
extractFromRequest
public static CustomComponentApiSelection extractFromRequest(tools.jackson.databind.JsonNode data, String key) ExtractCustomComponentApiSelectionfrom the data witht the given key if present.- Parameters:
data- sent from the clientkey- JSON key to get the value- Returns:
- CustomComponentApiSelection if present, or null if customComponentApiSelection is not present in the JSON or not an object or unable to parse
-