private ObjectIntMap<String> generatePackageMetadata(List<ClassNode> classes, Set<String> classesRequiringName) throws IOException { PackageNode root = new PackageNode(null); for (ClassNode classNode : classes) { String className = classNode.getName(); if (!classesRequiringName.contains(className)) { continue; } int dotIndex = className.lastIndexOf('.'); if (dotIndex < 0) { continue; } addPackageName(root, className.substring(0, dotIndex)); } ObjectIntMap<String> indexes = new ObjectIntHashMap<>(); writePackageStructure(root, -1, "", indexes); writer.softNewLine(); return indexes; }
private void renderMethodBodies(ClassNode cls) throws RenderingException { debugEmitter.emitClass(cls.getName()); try { MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); if (clinit != null) { renderCallClinit(clinit, cls); } if (!cls.getModifiers().contains(ElementModifier.INTERFACE)) { for (MethodNode method : cls.getMethods()) { if (!method.getModifiers().contains(ElementModifier.STATIC)) { if (method.getReference().getName().equals("<init>")) { renderInitializer(cls.getName(), method); } } } } for (MethodNode method : cls.getMethods()) { renderBody(cls.getName(), method); } } catch (IOException e) { throw new RenderingException("IO error occurred", e); } debugEmitter.emitClass(null); }
public boolean render(List<ClassNode> classes) throws RenderingException { if (minifying) { try { renderRuntimeAliases(); } catch (IOException e) { throw new RenderingException(e); } } int index = 0; for (ClassNode cls : classes) { int start = writer.getOffset(); renderDeclaration(cls); renderMethodBodies(cls); appendClassSize(cls.getName(), writer.getOffset() - start); if (progressConsumer.apply(1000 * ++index / classes.size()) == TeaVMProgressFeedback.CANCEL) { return false; } } renderClassMetadata(classes); return true; }
debugEmitter.emitClass(cls.getName()); writer.appendClass(cls.getName()).append(",").ws(); if (classesRequiringName.contains(cls.getName())) { String className = cls.getName(); int dotIndex = className.lastIndexOf('.') + 1; String packageName = className.substring(0, dotIndex); writer.append(cls.getAccessLevel().ordinal()).append(',').ws(); MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); if (clinit != null) { writer.appendClassInit(cls.getName()); } else { writer.append('0'); collectMethodsToCopyFromInterfaces(classSource.get(cls.getName()), virtualMethods);
public void estimate(ClassNode cls) { consumer.consume(cls.getName()); if (cls.getParentName() != null) { consumer.consume(cls.getParentName()); consumer.consume(new FieldReference(cls.getName(), field.getName())); if (field.getModifiers().contains(ElementModifier.STATIC)) { consumer.consume(cls.getName()); MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); for (MethodNode method : cls.getMethods()) { consumer.consume(cls.getName()); consumer.consume(cls.getName()); if (cls.getParentName() != null) { consumer.consume(cls.getParentName());
private void renderDeclaration(ClassNode cls) throws RenderingException { String jsName = naming.getNameFor(cls.getName()); debugEmitter.addClass(jsName, cls.getName(), cls.getParentName()); try { writer.append("function " + jsName + "()").ws().append("{") value = getDefaultValue(field.getType()); FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); writer.append(thisAliased ? "a" : "this").append(".").appendField(fieldRef).ws() .append("=").ws().append(context.constantToString(value)).append(";").softNewLine(); if (cls.getName().equals("java.lang.Object")) { writer.append("this.$id$").ws().append('=').ws().append("0;").softNewLine(); value = getDefaultValue(field.getType()); FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); if (value instanceof String) { context.constantToString(value);
writer.append("var ").appendClass(cls.getName()).append("_$clinitCalled").ws().append("=").ws() .append("false;").softNewLine(); renderFunctionDeclaration(cls.getName(), naming.getNameForClassInit(cls.getName())); writer.append("()").ws() .append("{").softNewLine().indent(); .append("().pop();").softNewLine(); writer.outdent().append("}").ws(); writer.append("else if").ws().append("(").appendClass(cls.getName()).append("_$clinitCalled)").ws() .append("{").indent().softNewLine(); writer.append("return;").softNewLine(); writer.appendClass(cls.getName()).append("_$clinitCalled").ws().append('=').ws().append("true;") .softNewLine(); } else { writer.appendMethodBody(new MethodReference(cls.getName(), clinit.getDescriptor())) .append("();").softNewLine();
private void renderMethodBodies(ClassNode cls) throws RenderingException { debugEmitter.emitClass(cls.getName()); try { MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); if (clinit != null) { renderCallClinit(clinit, cls); } if (!cls.getModifiers().contains(ElementModifier.INTERFACE)) { for (MethodNode method : cls.getMethods()) { if (!method.getModifiers().contains(ElementModifier.STATIC)) { if (method.getReference().getName().equals("<init>")) { renderInitializer(method); } } } } for (MethodNode method : cls.getMethods()) { renderBody(method); } } catch (NamingException e) { throw new RenderingException("Error rendering class " + cls.getName() + ". See a cause for details", e); } catch (IOException e) { throw new RenderingException("IO error occurred", e); } debugEmitter.emitClass(null); }
private void renderEraseClinit(ClassNode cls) throws IOException { writer.appendClass(cls.getName()).append("_$callClinit").ws().append("=").ws() .append("function(){};").newLine(); }
public void estimate(ClassNode cls) { consumer.consume(cls.getName()); if (cls.getParentName() != null) { consumer.consume(cls.getParentName()); consumer.consume(new FieldReference(cls.getName(), field.getName())); if (field.getModifiers().contains(ElementModifier.STATIC)) { consumer.consume(cls.getName()); MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); for (MethodNode method : cls.getMethods()) { consumer.consume(cls.getName()); consumer.consume(cls.getName()); if (cls.getParentName() != null) { consumer.consume(cls.getParentName());
writer.appendClass(cls.getName()).append(",").ws(); writer.append("\"").append(RenderingUtil.escapeString(cls.getName())).append("\",").ws(); if (cls.getParentName() != null) { writer.appendClass(cls.getParentName()); MethodReader clinit = classSource.get(cls.getName()).getMethod( new MethodDescriptor("<clinit>", ValueType.VOID)); if (clinit != null) { writer.appendClass(cls.getName()).append("_$callClinit"); } else { writer.append('0'); collectMethodsToCopyFromInterfaces(classSource.get(cls.getName()), virtualMethods);
private void renderDeclaration(ClassNode cls) throws RenderingException { debugEmitter.addClass(cls.getName(), cls.getParentName()); try { writer.append("function ").appendClass(cls.getName()).append("()").ws().append("{") .indent().softNewLine(); boolean thisAliased = false; value = getDefaultValue(field.getType()); FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); writer.append(thisAliased ? "a" : "this").append(".").appendField(fieldRef).ws() .append("=").ws().append(context.constantToString(value)).append(";").softNewLine(); if (cls.getName().equals("java.lang.Object")) { writer.append("this.$id$").ws().append('=').ws().append("0;").softNewLine(); value = getDefaultValue(field.getType()); FieldReference fieldRef = new FieldReference(cls.getName(), field.getName()); if (value instanceof String) { context.constantToString(value); throw new RenderingException("Error rendering class " + cls.getName() + ". See cause for details", e); } catch (IOException e) { throw new RenderingException("IO error occurred", e);
writer.append("var ").appendClass(cls.getName()).append("_$clinitCalled").ws().append("=").ws() .append("false;").softNewLine(); writer.append("function ").appendClass(cls.getName()).append("_$callClinit()").ws() .append("{").softNewLine().indent(); .append("().pop();").softNewLine(); writer.outdent().append("}").ws(); writer.append("else if").ws().append("(").appendClass(cls.getName()).append("_$clinitCalled)").ws() .append("{").indent().softNewLine(); writer.append("return;").softNewLine(); writer.appendClass(cls.getName()).append("_$clinitCalled").ws().append('=').ws().append("true;") .softNewLine(); } else { writer.appendMethodBody(new MethodReference(cls.getName(), clinit.getDescriptor())) .append("();").softNewLine();