Class JsStringFallbacks
JsStringFallback interfaces of the application, so that the browser
runs a function from the bundle instead of compiling the string.
The build checks the marked interfaces with collectFallbacks(java.util.Collection<java.lang.Class<?>>) and
lists their names in Constants.JS_STRING_FALLBACKS_FILE. The list is
read the first time a service matches a string, which only happens in the
modes that report string JavaScript.
A string matches what is declared for it when the text is the same, and for a
call or a function also the number of parameters: the same identity that
JsCall.functionId(String, int, boolean),
JsCall.snippetFunctionId(String, List, int, boolean) and
BundledEventData.getFunctionId(String) give the function in the
bundle.
For internal use only. May be renamed or removed in a future release.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA method that stands in for strings, with theJsStringFallbackinterface it is called through.static final recordWhat theJsStringFallbackinterfaces of an application declare. -
Method Summary
Modifier and TypeMethodDescriptionstatic JsStringFallbacks.FallbackscollectFallbacks(Collection<Class<?>> definitionTypes) Checks the fallback interfaces and collects what they declare.static @Nullable JsCallfindDeclaredCall(String expression, @Nullable Object[] parameters) Finds the declared call that stands in for anexecuteJscall with a string expression, in the service of the current request.static @Nullable JsCallfindDeclaredFunction(String body, @Nullable Object[] captures) Finds the declared call of a method returning aJsFunctionthat stands in for a function created from a string body, in the service of the current request.static StringfunctionId(Class<?> definitionType, Method method) Gets the identifier of the function that the given method of the given definition registers in the generated bundle.static booleanisDeclaredEventData(String eventData) Checks whether the application declared an event data value, so that the bundle has a function for it, in the service of the current request.static booleanisDeclaredFilter(String filter) Checks whether the application declared a filter, so that the bundle has a function for it, in the service of the current request.static booleanisStringFallbackCall(Class<?> definitionType, Method method) Checks whether the given method of the given definition runs JavaScript in place of anexecuteJsstring, which is the case for a method that does not return a snippet of aJsStringFallbackinterface, whether the interface declares the method or inherits it.static voidreloadFallbacks(VaadinService service) Reads the list again for a service, after a class change updated it while the application runs.stringFallbackBody(String expression, int parameterCount) Gets the body of the generated function for a method thatstands in for a string call.
-
Method Details
-
collectFallbacks
Checks the fallback interfaces and collects what they declare.- Parameters:
definitionTypes- the interfaces marked withJsStringFallback, notnull- Returns:
- what the interfaces declare, not
null - Throws:
IllegalArgumentException- if a type is not aJsDefinition, declares something that no string can match, or two methods declare the same JavaScript with the same parameter count
-
findDeclaredCall
Finds the declared call that stands in for anexecuteJscall with a string expression, in the service of the current request.- Parameters:
expression- the JavaScript the string call sends, notnullparameters- the parameters of the string call, notnull- Returns:
- the declared call to send instead, or
nullif the application declared nothing for the string, or the mode does not report string JavaScript
-
findDeclaredFunction
Finds the declared call of a method returning aJsFunctionthat stands in for a function created from a string body, in the service of the current request.- Parameters:
body- the body of the function, notnullcaptures- the values the function captures, notnull- Returns:
- the call to create the declared function with, or
nullif the application declared nothing for the body, or the mode does not report string JavaScript
-
isDeclaredFilter
Checks whether the application declared a filter, so that the bundle has a function for it, in the service of the current request.- Parameters:
filter- the filter, notnull- Returns:
trueif the filter is declared and the mode reports string JavaScript
-
isDeclaredEventData
Checks whether the application declared an event data value, so that the bundle has a function for it, in the service of the current request.- Parameters:
eventData- the event data value, possibly mapped to an element, notnull- Returns:
trueif the value is declared and the mode reports string JavaScript
-
reloadFallbacks
Reads the list again for a service, after a class change updated it while the application runs.- Parameters:
service- the service, notnull
-
isStringFallbackCall
Checks whether the given method of the given definition runs JavaScript in place of anexecuteJsstring, which is the case for a method that does not return a snippet of aJsStringFallbackinterface, whether the interface declares the method or inherits it.Such a method is generated so that its JavaScript sees what the string would see:
Element.executeJs(String, Object...)gives the element to the string as one more parameter after the arguments, so a string can use$0as the element when it has no arguments. Since it is generated differently, its function has an identifier of its own, seefunctionId(Class, Method).- Parameters:
definitionType- the definition the method is called through, notnullmethod- a method of the definition annotated withJsExpression, notnull- Returns:
trueif the method stands in for a string call
-
functionId
Gets the identifier of the function that the given method of the given definition registers in the generated bundle.This is
JsCall.functionId(Method), except for a method thatstands in for a string call: it is generated differently, so it has an identifier of its own and never replaces the function of another definition that declares the same JavaScript, such as an interface it inherits the method from.- Parameters:
definitionType- the definition the method is called through, notnullmethod- a method of the definition annotated withJsExpression, notnull- Returns:
- the function identifier, not
null
-
stringFallbackBody
Gets the body of the generated function for a method thatstands in for a string call. It runs the declared JavaScript the wayElement.executeJs(String, Object...)runs the string: in a function whosethisis the element and which sees the element as the parameter after the arguments.- Parameters:
expression- the declared JavaScript, notnullparameterCount- the number of parameters of the method- Returns:
- the lines of the function body, not
null
-