From a78eec93d69d62d55b9b1ecf9700fcdc40eafa14 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Tue, 17 Oct 2023 07:55:01 +0200 Subject: [PATCH] metaprogramming: use unprocessed class source to get program templates This should prevent class transformations from applying twice, which can cause some errors. --- .../src/main/java/org/teavm/dependency/DependencyAgent.java | 4 ++++ .../main/java/org/teavm/dependency/DependencyAnalyzer.java | 6 ++++++ .../impl/MetaprogrammingDependencyListener.java | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/teavm/dependency/DependencyAgent.java b/core/src/main/java/org/teavm/dependency/DependencyAgent.java index 294d69b04..d2672babe 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyAgent.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAgent.java @@ -83,6 +83,10 @@ public class DependencyAgent implements DependencyInfo, ServiceRepository { return analyzer.agentClassSource; } + public ClassReaderSource getUnprocessedClassSource() { + return analyzer.getUnprocessedClassSource(); + } + @Override public ClassLoader getClassLoader() { return analyzer.getClassLoader(); diff --git a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java index d9a32c0d6..34e34d342 100644 --- a/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java +++ b/core/src/main/java/org/teavm/dependency/DependencyAnalyzer.java @@ -81,6 +81,7 @@ public abstract class DependencyAnalyzer implements DependencyInfo { || shouldLog; static final boolean dependencyReport = System.getProperty("org.teavm.dependencyReport", "false").equals("true"); private int classNameSuffix; + private ClassReaderSource unprocessedClassSource; private DependencyClassSource classSource; ClassReaderSource agentClassSource; private ClassLoader classLoader; @@ -118,6 +119,7 @@ public abstract class DependencyAnalyzer implements DependencyInfo { DependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, Diagnostics diagnostics, ReferenceCache referenceCache) { + this.unprocessedClassSource = classSource; this.diagnostics = diagnostics; this.referenceCache = referenceCache; this.classSource = new DependencyClassSource(classSource, diagnostics, incrementalCache); @@ -200,6 +202,10 @@ public abstract class DependencyAnalyzer implements DependencyInfo { return classSource != null ? classSource : agentClassSource; } + public ClassReaderSource getUnprocessedClassSource() { + return unprocessedClassSource; + } + public boolean isSynthesizedClass(String className) { return classSource != null ? classSource.isGeneratedClass(className) : generatedClassNames.contains(className); } diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java index 6d58b9d14..c3fbe0dc6 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java @@ -26,6 +26,7 @@ import org.teavm.metaprogramming.impl.model.MethodDescriber; import org.teavm.metaprogramming.impl.model.MethodModel; import org.teavm.metaprogramming.impl.optimization.Optimizations; import org.teavm.metaprogramming.impl.reflect.ReflectContext; +import org.teavm.model.ClassHierarchy; import org.teavm.model.ClassReader; import org.teavm.model.MethodReader; import org.teavm.model.MethodReference; @@ -45,8 +46,8 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene describer = new MethodDescriber(MetaprogrammingImpl.createDiagnostics(), agent.getClassSource()); MetaprogrammingImpl.classLoader = proxyClassLoader; - MetaprogrammingImpl.classSource = agent.getClassSource(); - MetaprogrammingImpl.hierarchy = agent.getClassHierarchy(); + MetaprogrammingImpl.classSource = agent.getUnprocessedClassSource(); + MetaprogrammingImpl.hierarchy = new ClassHierarchy(agent.getUnprocessedClassSource()); MetaprogrammingImpl.incrementalDependencies = agent.getIncrementalCache(); MetaprogrammingImpl.agent = agent; MetaprogrammingImpl.reflectContext = new ReflectContext(agent.getClassHierarchy(), proxyClassLoader);