From e35f9b54b5382e7f70378f6aa164b074b9cf69b2 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sun, 16 Mar 2014 01:54:47 +0400 Subject: [PATCH] Moves JCL report generator into separate package. Adds hack that allows to obtain JavaCompiler (but yet it won't compile). --- teavm-classlib/pom.xml | 2 +- .../org/teavm/classlib/impl/JCLPlugin.java | 2 + .../org/teavm/classlib/impl/JavacSupport.java | 53 +++++++++++++++++++ .../classlib/impl/{ => report}/JCLClass.java | 2 +- .../impl/{ => report}/JCLClassType.java | 2 +- .../{ => report}/JCLComparisonBuilder.java | 2 +- .../{ => report}/JCLComparisonVisitor.java | 2 +- .../classlib/impl/{ => report}/JCLItem.java | 2 +- .../impl/{ => report}/JCLItemType.java | 2 +- .../impl/{ => report}/JCLPackage.java | 2 +- .../classlib/impl/{ => report}/JCLStatus.java | 2 +- .../impl/{ => report}/JCLVisibility.java | 2 +- .../teavm/dependency/DependencyChecker.java | 8 ++- 13 files changed, 72 insertions(+), 11 deletions(-) create mode 100644 teavm-classlib/src/main/java/org/teavm/classlib/impl/JavacSupport.java rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLClass.java (96%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLClassType.java (94%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLComparisonBuilder.java (99%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLComparisonVisitor.java (99%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLItem.java (95%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLItemType.java (94%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLPackage.java (95%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLStatus.java (94%) rename teavm-classlib/src/main/java/org/teavm/classlib/impl/{ => report}/JCLVisibility.java (94%) diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml index ce5449982..74205491e 100644 --- a/teavm-classlib/pom.xml +++ b/teavm-classlib/pom.xml @@ -71,7 +71,7 @@ - org.teavm.classlib.impl.JCLComparisonBuilder + org.teavm.classlib.impl.report.JCLComparisonBuilder java.lang java.lang.annotation diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java index 71c0970da..6e852de8e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java @@ -38,5 +38,7 @@ public class JCLPlugin implements TeaVMPlugin { "loadServices", ValueType.object("java.lang.Class"), ValueType.arrayOf(ValueType.object("java.lang.Object")))); host.add(loadServicesMethod, serviceLoaderSupp); + JavacSupport javacSupport = new JavacSupport(); + host.add(javacSupport); } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JavacSupport.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JavacSupport.java new file mode 100644 index 000000000..def1bef59 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JavacSupport.java @@ -0,0 +1,53 @@ +/* + * Copyright 2014 Alexey Andreev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.teavm.classlib.impl; + +import org.teavm.model.*; +import org.teavm.model.instructions.ConstructInstruction; +import org.teavm.model.instructions.ExitInstruction; +import org.teavm.model.instructions.InvocationType; +import org.teavm.model.instructions.InvokeInstruction; + +/** + * + * @author Alexey Andreev + */ +public class JavacSupport implements ClassHolderTransformer { + @Override + public void transformClass(ClassHolder cls, ClassReaderSource innerSource) { + if (cls.getName().equals("javax.tools.ToolProvider")) { + MethodHolder method = cls.getMethod(new MethodDescriptor("getSystemJavaCompiler", + ValueType.object("javax.tools.JavaCompiler"))); + Program program = new Program(); + BasicBlock block = program.createBasicBlock(); + program.createVariable(); + Variable var = program.createVariable(); + ConstructInstruction construct = new ConstructInstruction(); + construct.setReceiver(var); + construct.setType("com.sun.tools.javac.api.JavacTool"); + block.getInstructions().add(construct); + InvokeInstruction init = new InvokeInstruction(); + init.setInstance(var); + init.setType(InvocationType.SPECIAL); + init.setMethod(new MethodReference("com.sun.tools.javac.api.JavacTool", "", ValueType.VOID)); + block.getInstructions().add(init); + ExitInstruction exit = new ExitInstruction(); + exit.setValueToReturn(var); + block.getInstructions().add(exit); + method.setProgram(program); + } + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClass.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClass.java similarity index 96% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClass.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClass.java index 2391d1369..571d7ddff 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClass.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClass.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; import java.util.ArrayList; import java.util.List; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClassType.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClassType.java similarity index 94% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClassType.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClassType.java index 813ce8d74..e1f48578d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLClassType.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLClassType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; /** * diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonBuilder.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java similarity index 99% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonBuilder.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java index 402ccfbfa..9a05011a0 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonBuilder.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonBuilder.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; import java.io.*; import java.net.URL; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonVisitor.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java similarity index 99% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonVisitor.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java index 54aa85b63..4933c5820 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLComparisonVisitor.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLComparisonVisitor.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; import java.util.Map; import org.objectweb.asm.*; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItem.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItem.java similarity index 95% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItem.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItem.java index 471b9d16b..302f9cc28 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItem.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItem.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; /** * diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItemType.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItemType.java similarity index 94% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItemType.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItemType.java index 5bd66c172..bea707379 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLItemType.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLItemType.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; /** * diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPackage.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLPackage.java similarity index 95% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPackage.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLPackage.java index e527931fd..39bcedba0 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPackage.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLPackage.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; import java.util.ArrayList; import java.util.List; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLStatus.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLStatus.java similarity index 94% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLStatus.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLStatus.java index c951f4b38..bf48b2d2c 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLStatus.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLStatus.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; /** * diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLVisibility.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLVisibility.java similarity index 94% rename from teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLVisibility.java rename to teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLVisibility.java index 56be51ad0..b88e5b2d0 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLVisibility.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/report/JCLVisibility.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.teavm.classlib.impl; +package org.teavm.classlib.impl.report; /** * 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 59e43e861..c57e63fe1 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -291,7 +291,13 @@ public class DependencyChecker implements DependencyInfo { missingMethods.putIfAbsent(methodRef, stack); } if (method != null) { - initClass(methodRef.getClassName(), stack); + final DependencyStack callerStack = stack; + executor.execute(new Runnable() { + @Override public void run() { + initClass(dep.getReference().getClassName(), callerStack); + } + }); + } return dep; }