From 4dd9eaa1fd047405bb468d4357baa9501e4e96fb Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Thu, 13 Feb 2014 22:59:30 +0400 Subject: [PATCH] Adds a new dependency event that is emitted when dependency checker is about to start. Adds ability to examine classes from generators. --- .../main/java/org/teavm/dependency/DependencyChecker.java | 6 ++++++ .../main/java/org/teavm/dependency/DependencyListener.java | 2 ++ .../main/java/org/teavm/javascript/JavascriptBuilder.java | 1 + teavm-core/src/main/java/org/teavm/javascript/Renderer.java | 5 +++++ .../main/java/org/teavm/javascript/ni/GeneratorContext.java | 4 ++++ 5 files changed, 18 insertions(+) diff --git a/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java b/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java index 55e383df0..c9bd95ce1 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -89,6 +89,12 @@ public class DependencyChecker implements DependencyInformation { listeners.add(listener); } + public void startListeners() { + for (DependencyListener listener : listeners) { + listener.started(this); + } + } + public void addEntryPoint(MethodReference methodRef, String... argumentTypes) { ValueType[] parameters = methodRef.getDescriptor().getParameterTypes(); if (parameters.length != argumentTypes.length) { diff --git a/teavm-core/src/main/java/org/teavm/dependency/DependencyListener.java b/teavm-core/src/main/java/org/teavm/dependency/DependencyListener.java index 16b470ef2..8be4daf19 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyListener.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyListener.java @@ -23,6 +23,8 @@ import org.teavm.model.MethodReference; * @author Alexey Andreev */ public interface DependencyListener { + void started(DependencyChecker dependencyChecker); + void classAchieved(DependencyChecker dependencyChecker, String className); void methodAchieved(DependencyChecker dependencyChecker, MethodReference method); diff --git a/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java b/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java index 1ebf70274..2f3e4a757 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java +++ b/teavm-core/src/main/java/org/teavm/javascript/JavascriptBuilder.java @@ -112,6 +112,7 @@ public class JavascriptBuilder implements JavascriptBuilderHost { SourceWriterBuilder builder = new SourceWriterBuilder(naming); builder.setMinified(minifying); SourceWriter sourceWriter = builder.build(writer); + dependencyChecker.startListeners(); dependencyChecker.attachMethodGraph(new MethodReference("java.lang.Class", new MethodDescriptor("createNew", ValueType.object("java.lang.Class")))); dependencyChecker.attachMethodGraph(new MethodReference("java.lang.String", new MethodDescriptor("", diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index ba49534a5..bb8fdaa59 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -373,6 +373,11 @@ public class Renderer implements ExprVisitor, StatementVisitor { public String getParameterName(int index) { return variableName(index); } + + @Override + public ClassReaderSource getClassSource() { + return classSource; + } } @Override diff --git a/teavm-core/src/main/java/org/teavm/javascript/ni/GeneratorContext.java b/teavm-core/src/main/java/org/teavm/javascript/ni/GeneratorContext.java index bb08bf93e..fd856f0b5 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/ni/GeneratorContext.java +++ b/teavm-core/src/main/java/org/teavm/javascript/ni/GeneratorContext.java @@ -15,10 +15,14 @@ */ package org.teavm.javascript.ni; +import org.teavm.model.ClassReaderSource; + /** * * @author Alexey Andreev */ public interface GeneratorContext { String getParameterName(int index); + + ClassReaderSource getClassSource(); }