Skip to content

Commit ebfc92b

Browse files
committed
Only expose JsInterop methods to Vue.js
Before, all the methods that were at least package-protected where visible in JS. This could cause confusion when reading the Component class, as well as exposing some unwanted methods.
1 parent 279f810 commit ebfc92b

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

src/main/java/com/axellience/vuegwt/jsr69/component/ComponentGenerationUtil.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ public static TypeName resolveVariableTypeName(VariableElement variableElement,
150150
*/
151151
public static boolean isMethodVisibleInTemplate(ExecutableElement method)
152152
{
153-
return !hasAnnotation(method, Computed.class)
153+
return isMethodVisibleInJS(method)
154+
&& !hasAnnotation(method, Computed.class)
154155
&& !hasAnnotation(method, Watch.class)
155156
&& !hasAnnotation(method, PropValidator.class)
156157
&& !hasAnnotation(method, PropDefault.class)
157158
&& !method.getModifiers().contains(Modifier.STATIC)
158-
&& !method.getModifiers().contains(Modifier.PRIVATE)
159-
&& !method.getModifiers().contains(Modifier.ABSTRACT);
159+
&& !method.getModifiers().contains(Modifier.PRIVATE);
160160
}
161161

162162
/**
@@ -166,13 +166,13 @@ public static boolean isMethodVisibleInTemplate(ExecutableElement method)
166166
*/
167167
public static boolean isMethodVisibleInTemplate(JMethod method)
168168
{
169-
return !hasAnnotation(method, Computed.class)
169+
return isMethodVisibleInJS(method)
170+
&& !hasAnnotation(method, Computed.class)
170171
&& !hasAnnotation(method, Watch.class)
171172
&& !hasAnnotation(method, PropValidator.class)
172173
&& !hasAnnotation(method, PropDefault.class)
173174
&& !method.isStatic()
174-
&& !method.isPrivate()
175-
&& !method.isAbstract();
175+
&& !method.isPrivate();
176176
}
177177

178178
/**
@@ -217,6 +217,20 @@ public static boolean isFieldVisibleInJS(JField field)
217217
|| hasAnnotation(field, JsProperty.class);
218218
}
219219

220+
/**
221+
* Return weather a given method is visible in JS (JsInterop).
222+
* It will be the case if it's public and it's class/interface has the {@link JsType}
223+
* annotation, or
224+
* if it has the {@link JsMethod} annotation.
225+
* @param method The method to check
226+
* @return true if it is visible (JsInterop), false otherwise
227+
*/
228+
public static boolean isMethodVisibleInJS(JMethod method)
229+
{
230+
return (hasAnnotation(method.getEnclosingType(), JsType.class) && method.isPublic())
231+
|| hasAnnotation(method, JsMethod.class);
232+
}
233+
220234
/**
221235
* Return the {@link TypeElement} of the parent {@link VueComponent} of a given {@link
222236
* VueComponent}.

src/main/java/com/axellience/vuegwt/jsr69/component/ComponentJsTypeGenerator.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ public void generate(TypeElement component)
102102
processPropValidators(component, optionsBuilder, componentJsTypeBuilder);
103103
processPropDefaultValues(component, optionsBuilder, componentJsTypeBuilder);
104104
processHooks(component, optionsBuilder, hookMethodsFromInterfaces);
105-
processTemplateMethods(component,
106-
optionsBuilder,
107-
componentJsTypeBuilder,
108-
hookMethodsFromInterfaces);
105+
processTemplateMethods(component, optionsBuilder, hookMethodsFromInterfaces);
109106
processRenderFunction(component, optionsBuilder, componentJsTypeBuilder);
110107
createCreatedHook(component, optionsBuilder, componentJsTypeBuilder, dependenciesBuilder);
111108

@@ -291,17 +288,15 @@ private void processComputed(TypeElement component, MethodSpec.Builder optionsBu
291288
}
292289

293290
/**
294-
* Process template methods for our {@link VueComponent} class. Make them visible to JS by
295-
* wrapping them if necessary.
291+
* Process template methods for our {@link VueComponent} class.
296292
* @param component {@link VueComponent} to process
297293
* @param optionsBuilder A {@link MethodSpec.Builder} for the method that creates the
298294
* {@link VueComponentOptions}
299-
* @param componentJsTypeBuilder Builder for the JsType class
300295
* @param hookMethodsFromInterfaces Hook methods from the interface the {@link VueComponent}
301296
* implements
302297
*/
303298
private void processTemplateMethods(TypeElement component, MethodSpec.Builder optionsBuilder,
304-
Builder componentJsTypeBuilder, Set<ExecutableElement> hookMethodsFromInterfaces)
299+
Set<ExecutableElement> hookMethodsFromInterfaces)
305300
{
306301
List<ExecutableElement> templateMethods = ElementFilter
307302
.methodsIn(component.getEnclosedElements())
@@ -310,13 +305,6 @@ private void processTemplateMethods(TypeElement component, MethodSpec.Builder op
310305
.filter(method -> !isHookMethod(component, method, hookMethodsFromInterfaces))
311306
.collect(Collectors.toList());
312307

313-
// Make methods visible in JS
314-
templateMethods
315-
.stream()
316-
.filter(method -> !isMethodVisibleInJS(method))
317-
.map(this::createProxyJsTypeMethod)
318-
.forEach(componentJsTypeBuilder::addMethod);
319-
320308
// Declare methods in the component
321309
String methodNamesParameters = templateMethods
322310
.stream()

0 commit comments

Comments
 (0)