private void generateSet(GeneratorContext context, SourceWriter writer) throws IOException { String array = context.getParameterName(1); String item = context.getParameterName(3); writer.append("var type = " + array + ".constructor.$meta.item;").softNewLine(); boolean first = true; for (int i = 0; i < primitives.length; ++i) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, primitives[i].toLowerCase() + "Value", primitiveTypes[i]); ClassReader cls = context.getClassSource().get(methodRef.getClassName()); if (cls == null || cls.getMethod(methodRef.getDescriptor()) == null) { continue; } if (!first) { writer.append(" else "); } first = false; writer.append("if (type === $rt_" + primitives[i].toLowerCase() + "cls()) {").indent().softNewLine(); writer.append(item + " = ").appendMethodBody(methodRef).append("(" + item + ");").softNewLine(); writer.outdent().append("}"); } writer.softNewLine(); writer.append(array + ".data[" + context.getParameterName(2) + "] = " + item + ";").softNewLine(); }
private void generateLookup(GeneratorContext context, SourceWriter writer) throws IOException { String param = context.getParameterName(1); writer.append("switch ($rt_ustr(" + param + ")) {").softNewLine().indent(); for (String name : context.getClassSource().getClassNames()) { writer.append("case \"" + name + "\": ").appendClass(name).append(".$clinit(); ") .append("return ").appendClass(name).append(";").softNewLine(); } writer.append("default: return null;").softNewLine(); writer.outdent().append("}").softNewLine(); }
private void generatePrepareNewInstance(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$constructor$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader cls = context.getClassSource().get(clsName); MethodReader method = cls.getMethod(new MethodDescriptor("<init>", void.class)); if (method != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws() .appendMethodBody(method.getReference()).append(";").softNewLine(); } } }
@Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); AnnotationReader refAnnot = method.getAnnotations().get(MetadataProviderRef.class.getName()); methodRef = MethodReference.parse(refAnnot.getValue("value").getString()); MetadataGenerator generator = MetadataUtils.createMetadataGenerator(context.getClassLoader(), method, new CallLocation(methodRef), context.getDiagnostics()); if (generator == null) { return; } DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(), context.getClassLoader(), context.getProperties(), context); // Generate resource loader Resource resource = generator.generateMetadata(metadataContext, methodRef); writer.append("return "); ResourceWriterHelper.write(writer, resource); writer.append(';').softNewLine(); } }
private void generateGet(GeneratorContext context, SourceWriter writer) throws IOException { String array = context.getParameterName(1); writer.append("var item = " + array + ".data[" + context.getParameterName(2) + "];").softNewLine(); writer.append("var type = " + array + ".constructor.$meta.item;").softNewLine(); for (int i = 0; i < primitives.length; ++i) { String wrapper = "java.lang." + primitiveWrappers[i]; MethodReference methodRef = new MethodReference(wrapper, "valueOf", primitiveTypes[i], ValueType.object(wrapper)); ClassReader cls = context.getClassSource().get(methodRef.getClassName()); if (cls == null || cls.getMethod(methodRef.getDescriptor()) == null) { continue; } writer.append("if (type === $rt_" + primitives[i].toLowerCase() + "cls()) {").indent().softNewLine(); writer.append("return ").appendMethodBody(methodRef).append("(item);").softNewLine(); writer.outdent().append("} else "); } writer.append("{").indent().softNewLine(); writer.append("return item;").softNewLine(); writer.outdent().append("}").softNewLine(); }
@Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { MethodReader method = context.getClassSource().get(methodRef.getClassName()) .getMethod(methodRef.getDescriptor()); AnnotationReader annot = method.getAnnotations().get(JavaScriptBody.class.getName()); AnnotationValue javacall = annot.getValue("javacall"); if (javacall != null && javacall.getBoolean()) { GeneratorJsCallback callbackGen = new GeneratorJsCallback(context, context.getClassSource(), writer.getNaming()); body = callbackGen.parse(body);
@Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); AnnotationReader providerAnnot = method.getAnnotations().get(ClassScopedMetadataProvider.class.getName()); return; DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(), context.getClassLoader(), context.getProperties(), context); context.getClassSource().getClassNames(), methodRef); writer.append("var p").ws().append("=").ws().append("\"" + RenderingUtil.escapeString("$$res_" + writer.getNaming().getFullNameFor(methodRef)) + "\"").append(";").softNewLine();
if (context.getClassSource().getClassNames().contains(implName)) { writer.append("[").appendClass(implName).append(", ").appendMethodBody( new MethodReference(implName, new MethodDescriptor("<init>", ValueType.VOID)))
private void generateCreateFieldsForClass(GeneratorContext context, SourceWriter writer, String className) throws IOException { ReflectionDependencyListener reflection = context.getService(ReflectionDependencyListener.class); Set<String> accessibleFields = reflection.getAccessibleFields(className); ClassReader cls = context.getClassSource().get(className); if (cls == null) { return; } writer.appendClass(className).append(".$meta.fields").ws().append('=').ws().append('[').indent(); generateCreateMembers(writer, cls.getFields(), field -> { appendProperty(writer, "type", false, () -> writer.append(context.typeToClassString(field.getType()))); appendProperty(writer, "getter", false, () -> { if (accessibleFields != null && accessibleFields.contains(field.getName())) { renderGetter(writer, field); } else { writer.append("null"); } }); appendProperty(writer, "setter", false, () -> { if (accessibleFields != null && accessibleFields.contains(field.getName())) { renderSetter(writer, field); } else { writer.append("null"); } }); }); writer.outdent().append("];").softNewLine(); }
private void generateAnnotations(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$annotations$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader annotCls = context.getClassSource().get(clsName + "$$__annotations__$$"); if (annotCls != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws(); MethodReference ctor = new MethodReference(annotCls.getName(), "<init>", ValueType.VOID); writer.appendInit(ctor); writer.append("();").softNewLine(); } } MethodReference selfRef = new MethodReference(Platform.class, "getAnnotations", PlatformClass.class, Annotation[].class); writer.appendMethodBody(selfRef).ws().append("=").ws().append("function(cls)").ws().append("{").softNewLine() .indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("return cls[c].").appendMethod("getAnnotations", Annotation[].class).append("();").softNewLine(); writer.outdent().append("};").softNewLine(); writer.append("return ").appendMethodBody(selfRef).append("(").append(context.getParameterName(1)) .append(");").softNewLine(); } }
private void generateEnumConstants(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$enumConstants$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader cls = context.getClassSource().get(clsName); MethodReader method = cls.getMethod(new MethodDescriptor("values", ValueType.arrayOf(ValueType.object(clsName)))); if (method != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws(); writer.appendMethodBody(method.getReference()); writer.append(";").softNewLine(); } } MethodReference selfRef = new MethodReference(Platform.class, "getEnumConstants", PlatformClass.class, Enum[].class); writer.appendMethodBody(selfRef).ws().append("=").ws().append("function(cls)").ws().append("{").softNewLine() .indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("if").ws().append("(typeof cls[c]").ws().append("===").ws().append("\"function\")").ws() .append("{").indent().softNewLine(); writer.append("cls[c]").ws().append("=").ws().append("cls[c]();").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("return cls[c];").softNewLine(); writer.outdent().append("};").softNewLine(); writer.append("return ").appendMethodBody(selfRef).append("(").append(context.getParameterName(1)) .append(");").softNewLine(); }
writer.append("try").ws().append("{").indent().softNewLine(); writer.appendMethodBody(asyncRef).append('('); ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); int start = method.hasModifier(ElementModifier.STATIC) ? 1 : 0;
private void generateLookup(GeneratorContext context, SourceWriter writer) throws IOException { String param = context.getParameterName(1); writer.append("switch ($rt_ustr(" + param + ")) {").softNewLine().indent(); for (String name : context.getClassSource().getClassNames()) { writer.append("case \"" + name + "\": ").appendClass(name).append(".$clinit(); ") .append("return ").appendClass(name).append(";").softNewLine(); } writer.append("default: return null;").softNewLine(); writer.outdent().append("}").softNewLine(); }
private void generatePrepareNewInstance(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$constructor$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader cls = context.getClassSource().get(clsName); MethodReader method = cls.getMethod(new MethodDescriptor("<init>", void.class)); if (method != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws() .appendMethodBody(method.getReference()).append(";").softNewLine(); } } }
@Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); AnnotationReader refAnnot = method.getAnnotations().get(MetadataProviderRef.class.getName()); methodRef = MethodReference.parse(refAnnot.getValue("value").getString()); MetadataGenerator generator = MetadataUtils.createMetadataGenerator(context.getClassLoader(), method, new CallLocation(methodRef), context.getDiagnostics()); if (generator == null) { return; } DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(), context.getClassLoader(), context.getProperties(), context); // Generate resource loader Resource resource = generator.generateMetadata(metadataContext, methodRef); writer.append("return "); ResourceWriterHelper.write(writer, resource); writer.append(';').softNewLine(); } }
@Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); AnnotationReader providerAnnot = method.getAnnotations().get(ClassScopedMetadataProvider.class.getName()); return; DefaultMetadataGeneratorContext metadataContext = new DefaultMetadataGeneratorContext(context.getClassSource(), context.getClassLoader(), context.getProperties(), context);
private void generateEnumConstants(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$enumConstants$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader cls = context.getClassSource().get(clsName); MethodReader method = cls.getMethod(new MethodDescriptor("values", ValueType.arrayOf(ValueType.object(clsName)))); if (method != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws(); writer.appendMethodBody(method.getReference()); writer.append(";").softNewLine(); } } String selfName = writer.getNaming().getFullNameFor(new MethodReference(Platform.class, "getEnumConstants", PlatformClass.class, Enum[].class)); writer.append(selfName).ws().append("=").ws().append("function(cls)").ws().append("{").softNewLine().indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("return cls[c]();").softNewLine(); writer.outdent().append("};").softNewLine(); writer.append("return ").append(selfName).append("(").append(context.getParameterName(1)) .append(");").softNewLine(); }
private void generateAnnotations(GeneratorContext context, SourceWriter writer) throws IOException { writer.append("var c").ws().append("=").ws().append("'$$annotations$$';").softNewLine(); for (String clsName : context.getClassSource().getClassNames()) { ClassReader annotCls = context.getClassSource().get(clsName + "$$__annotations__$$"); if (annotCls != null) { writer.appendClass(clsName).append("[c]").ws().append("=").ws(); MethodReference ctor = new MethodReference(annotCls.getName(), "<init>", ValueType.VOID); writer.append(writer.getNaming().getNameForInit(ctor)); writer.append("();").softNewLine(); } } String selfName = writer.getNaming().getFullNameFor(new MethodReference(Platform.class, "getAnnotations", PlatformClass.class, Annotation[].class)); writer.append(selfName).ws().append("=").ws().append("function(cls)").ws().append("{").softNewLine().indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine(); writer.outdent().append("}").softNewLine(); writer.append("return cls[c].").appendMethod("getAnnotations", Annotation[].class).append("();").softNewLine(); writer.outdent().append("};").softNewLine(); writer.append("return ").append(selfName).append("(").append(context.getParameterName(1)) .append(");").softNewLine(); } }
writer.append("try").ws().append("{").indent().softNewLine(); writer.appendMethodBody(asyncRef).append('('); ClassReader cls = context.getClassSource().get(methodRef.getClassName()); MethodReader method = cls.getMethod(methodRef.getDescriptor()); int start = method.hasModifier(ElementModifier.STATIC) ? 1 : 0;