private void addCssResourceMethod( final ClassStructureBuilder<ClassStructureBuilderAbstractMethodOption> componentTemplateResource, final String templateStyleSheetPath) { componentTemplateResource.publicMethod(CssResource.class, "getStyle").annotatedWith(new Source() { @Override public Class<? extends Annotation> annotationType() { return Source.class; } @Override public String[] value() { return new String[] { templateStyleSheetPath }; } }, new CssResource.NotStrict() { @Override public Class<? extends Annotation> annotationType() { return CssResource.NotStrict.class; } }).finish(); }
private void addCssResourceMethod( final ClassStructureBuilder<ClassStructureBuilderAbstractMethodOption> componentTemplateResource, final String templateStyleSheetPath) { componentTemplateResource.publicMethod(CssResource.class, "getStyle").annotatedWith(new Source() { @Override public Class<? extends Annotation> annotationType() { return Source.class; } @Override public String[] value() { return new String[] { templateStyleSheetPath }; } }, new CssResource.NotStrict() { @Override public Class<? extends Annotation> annotationType() { return CssResource.NotStrict.class; } }).finish(); }
componentTemplateResource.publicMethod(TextResource.class, "getContents").annotatedWith(new Source() {
componentTemplateResource.publicMethod(TextResource.class, "getContents").annotatedWith(new Source() {
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : constructor.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .annotatedWith(annotations) .parameters(methodDefParms) .modifiers(Modifier.Static, Modifier.JSNI) .body() ._(StringStatement.of(JSNIUtil.methodAccess(constructor))) .finish(); }
@Override public void makeConstructorAccessible(final ClassStructureBuilder<?> classBuilder, final MetaConstructor constructor) { final DefParameters methodDefParms = DefParameters.from(constructor); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : constructor.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } classBuilder.publicMethod(constructor.getReturnType(), PrivateAccessUtil.getPrivateMethodName(constructor)) .annotatedWith(annotations) .parameters(methodDefParms) .modifiers(Modifier.Static, Modifier.JSNI) .body() ._(StringStatement.of(JSNIUtil.methodAccess(constructor))) .finish(); }
@Override public void makeMethodAccessible(final ClassStructureBuilder<?> classBuilder, final MetaMethod method, final Modifier[] modifiers) { final MetaMethod erasedMethod = method.getDeclaringClass().getErased().getDeclaredMethod(method.getName(), getErasedParamterTypes(method)); final List<Parameter> wrapperDefParms = new ArrayList<Parameter>(); if (!erasedMethod.isStatic()) { wrapperDefParms.add(Parameter.of(erasedMethod.getDeclaringClass().getErased(), "instance")); } final List<Parameter> methodDefParms = DefParameters.from(erasedMethod).getParameters(); wrapperDefParms.addAll(methodDefParms); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : erasedMethod.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } if (erasedMethod.getReturnType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } classBuilder.publicMethod(erasedMethod.getReturnType(), PrivateAccessUtil.getPrivateMethodName(method)) .annotatedWith(annotations) .parameters(DefParameters.fromParameters(wrapperDefParms)) .modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.methodAccess(erasedMethod))) .finish(); }
@Override public void makeMethodAccessible(final ClassStructureBuilder<?> classBuilder, final MetaMethod method, final Modifier[] modifiers) { final MetaMethod erasedMethod = method.getDeclaringClass().getErased().getDeclaredMethod(method.getName(), getErasedParamterTypes(method)); final List<Parameter> wrapperDefParms = new ArrayList<Parameter>(); if (!erasedMethod.isStatic()) { wrapperDefParms.add(Parameter.of(erasedMethod.getDeclaringClass().getErased(), "instance")); } final List<Parameter> methodDefParms = DefParameters.from(erasedMethod).getParameters(); wrapperDefParms.addAll(methodDefParms); Annotation[] annotations = NO_ANNOTATIONS; for (MetaParameter p : erasedMethod.getParameters()) { if (p.getType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } } if (erasedMethod.getReturnType().getCanonicalName().equals("long")) { annotations = new Annotation[] { UNSAFE_NATIVE_LONG_ANNOTATION }; } classBuilder.publicMethod(erasedMethod.getReturnType(), PrivateAccessUtil.getPrivateMethodName(method)) .annotatedWith(annotations) .parameters(DefParameters.fromParameters(wrapperDefParms)) .modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.methodAccess(erasedMethod))) .finish(); }
/** * Create an inner interface for the given {@link MessageBundle} class and its corresponding JSON * resource. * * @param bundlePath * path to the message bundle */ private BuildMetaClass generateMessageBundleResourceInterface(final String bundlePath) { final ClassStructureBuilder<?> componentMessageBundleResource = ClassBuilder .define(getMessageBundleTypeName(bundlePath)).publicScope() .interfaceDefinition().implementsInterface(MessageBundle.class) .implementsInterface(ClientBundle.class).body() .publicMethod(TextResource.class, "getContents") .annotatedWith(new Source() { @Override public Class<? extends Annotation> annotationType() { return Source.class; } @Override public String[] value() { return new String[] { bundlePath }; } }).finish(); return componentMessageBundleResource.getClassDefinition(); }
/** * Create an inner interface for the given {@link MessageBundle} class and its corresponding JSON * resource. * * @param bundlePath * path to the message bundle */ private BuildMetaClass generateMessageBundleResourceInterface(final String bundlePath) { final ClassStructureBuilder<?> componentMessageBundleResource = ClassBuilder .define(getMessageBundleTypeName(bundlePath)).publicScope() .interfaceDefinition().implementsInterface(MessageBundle.class) .implementsInterface(ClientBundle.class).body() .publicMethod(TextResource.class, "getContents") .annotatedWith(new Source() { @Override public Class<? extends Annotation> annotationType() { return Source.class; } @Override public String[] value() { return new String[] { bundlePath }; } }).finish(); return componentMessageBundleResource.getClassDefinition(); }
@Override public void createWritableField(final MetaClass type, final ClassStructureBuilder<?> classBuilder, final MetaField field, final Modifier[] modifiers) { final MethodCommentBuilder<? extends ClassStructureBuilder<?>> methodBuilder = classBuilder.packageMethod(void.class, PrivateAccessUtil.getPrivateFieldAccessorName(field)); if (type.getCanonicalName().equals("long")) { methodBuilder.annotatedWith(UNSAFE_NATIVE_LONG_ANNOTATION); } if (!field.isStatic()) { methodBuilder .parameters(DefParameters.fromParameters(Parameter.of(field.getDeclaringClass().getErased(), "instance"), Parameter.of(type, "value"))); } else { methodBuilder .parameters(DefParameters.fromParameters(Parameter.of(type, "value"))); } methodBuilder.modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.fieldAccess(field) + " = value")) .finish(); }
@Override public void createWritableField(final MetaClass type, final ClassStructureBuilder<?> classBuilder, final MetaField field, final Modifier[] modifiers) { final MethodCommentBuilder<? extends ClassStructureBuilder<?>> methodBuilder = classBuilder.packageMethod(void.class, PrivateAccessUtil.getPrivateFieldAccessorName(field)); if (type.getCanonicalName().equals("long")) { methodBuilder.annotatedWith(UNSAFE_NATIVE_LONG_ANNOTATION); } if (!field.isStatic()) { methodBuilder .parameters(DefParameters.fromParameters(Parameter.of(field.getDeclaringClass().getErased(), "instance"), Parameter.of(type, "value"))); } else { methodBuilder .parameters(DefParameters.fromParameters(Parameter.of(type, "value"))); } methodBuilder.modifiers(appendJsni(modifiers)) .body() ._(StringStatement.of(JSNIUtil.fieldAccess(field) + " = value")) .finish(); }
private BlockBuilder<?> createProxyMethodDeclaration(final ClassStructureBuilder<?> proxyImpl, final MetaMethod method) { final MethodCommentBuilder<?> methodBuilder; if (method.isPublic()) { methodBuilder = proxyImpl.publicMethod(method.getReturnType().getErased(), method.getName(), getParametersForDeclaration(method)); } else if (method.isProtected()) { methodBuilder = proxyImpl.protectedMethod(method.getReturnType().getErased(), method.getName(), getParametersForDeclaration(method)); } else { final String methodType = (method.isProtected()) ? "private" : "package private"; throw new RuntimeException( "Cannot proxy " + methodType + " method from " + method.getDeclaringClassName()); } if (method.isPublic() || method.isProtected()) { return methodBuilder.annotatedWith(new Override() { @Override public Class<? extends Annotation> annotationType() { return Override.class; } }).throws_(method.getCheckedExceptions()).body(); } else { return methodBuilder.throws_(method.getCheckedExceptions()).body(); } }
.annotatedWith(OVERRIDE_ANNOTATION) .parameters(defParameters) .throws_(method.getCheckedExceptions()); .annotatedWith(OVERRIDE_ANNOTATION) .body() ._( .annotatedWith(OVERRIDE_ANNOTATION) .body() ._(
.annotatedWith(OVERRIDE_ANNOTATION) .parameters(defParameters) .throws_(method.getCheckedExceptions()); .annotatedWith(OVERRIDE_ANNOTATION) .body() ._( .annotatedWith(OVERRIDE_ANNOTATION) .body() ._(
@Test public void testMethodAnnotated() { final String cls = ClassBuilder.define("MyRunnable") .publicScope().implementsInterface(Runnable.class) .body() .publicMethod(void.class, "run") .annotatedWith(new SuppressWarnings() { @Override public String[] value() { return new String[]{"blah"}; } @Override public Class<? extends Annotation> annotationType() { return SuppressWarnings.class; } }).body() .append(Stmt.returnVoid()) .finish().toJavaString(); assertEquals("public class MyRunnable implements Runnable {\n" + " @SuppressWarnings(\"blah\") public void run() {\n" + " return;\n" + " }\n" + "}", cls); }
.publicMethod(boolean.class, "isEqual", Parameter.of(MC_annotationClass, "a1"), Parameter.of(MC_annotationClass, "a2")) .annotatedWith(new Override() { @Override public Class<? extends Annotation> annotationType() {