From 33d61412fbdef5f2ce6610c09a00c775d0735acc Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Fri, 25 Dec 2015 22:39:25 +0300 Subject: [PATCH] Reduce amount of generated JSO aliases --- .../org/teavm/jso/impl/JSAliasRenderer.java | 17 +++++++++++++++-- .../teavm/jso/impl/JSDependencyListener.java | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java index 9e5931e54..546df6b9a 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSAliasRenderer.java @@ -20,6 +20,8 @@ import java.util.Map; import org.teavm.codegen.SourceWriter; import org.teavm.javascript.RenderingContext; import org.teavm.jso.impl.JSDependencyListener.ExposedClass; +import org.teavm.model.ClassReader; +import org.teavm.model.ClassReaderSource; import org.teavm.model.MethodDescriptor; import org.teavm.vm.BuildTarget; import org.teavm.vm.spi.RendererListener; @@ -32,6 +34,7 @@ class JSAliasRenderer implements RendererListener { private static String variableChars = "abcdefghijklmnopqrstuvwxyz"; private JSDependencyListener dependencyListener; private SourceWriter writer; + private ClassReaderSource classSource; public JSAliasRenderer(JSDependencyListener dependencyListener) { this.dependencyListener = dependencyListener; @@ -40,6 +43,7 @@ class JSAliasRenderer implements RendererListener { @Override public void begin(RenderingContext context, BuildTarget buildTarget) throws IOException { writer = context.getWriter(); + classSource = context.getClassSource(); } @Override @@ -52,11 +56,20 @@ class JSAliasRenderer implements RendererListener { writer.append("var c;").softNewLine(); for (Map.Entry entry : dependencyListener.getExposedClasses().entrySet()) { ExposedClass cls = entry.getValue(); - if (cls.methods.isEmpty()) { + ClassReader classReader = classSource.get(entry.getKey()); + if (classReader == null || cls.methods.isEmpty()) { continue; } - writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;").softNewLine(); + boolean first = true; for (Map.Entry aliasEntry : cls.methods.entrySet()) { + if (classReader.getMethod(aliasEntry.getKey()) == null) { + continue; + } + if (first) { + writer.append("c").ws().append("=").ws().appendClass(entry.getKey()).append(".prototype;") + .softNewLine(); + first = false; + } if (isKeyword(aliasEntry.getValue())) { writer.append("c[\"").append(aliasEntry.getValue()).append("\"]"); } else { diff --git a/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java b/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java index 56c054e95..d32bdd7a2 100644 --- a/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java +++ b/jso/impl/src/main/java/org/teavm/jso/impl/JSDependencyListener.java @@ -101,7 +101,7 @@ class JSDependencyListener extends AbstractDependencyListener { private ExposedClass createExposedClass(String name) { ClassReader cls = classSource.get(name); ExposedClass exposedCls = new ExposedClass(); - if (cls == null) { + if (cls == null || cls.hasModifier(ElementModifier.INTERFACE)) { return exposedCls; } if (cls.getParent() != null && !cls.getParent().equals(cls.getName())) { @@ -146,7 +146,8 @@ class JSDependencyListener extends AbstractDependencyListener { if (addInterface(exposedCls, iface)) { added = true; for (MethodReader method : iface.getMethods()) { - if (method.hasModifier(ElementModifier.STATIC)) { + if (method.hasModifier(ElementModifier.STATIC) + || (method.getProgram() != null && method.getProgram().basicBlockCount() > 0)) { continue; } if (!exposedCls.inheritedMethods.containsKey(method.getDescriptor())) {