metaprogramming: use unprocessed class source to get program templates

This should prevent class transformations from applying twice, which can cause some errors.
This commit is contained in:
Alexey Andreev 2023-10-17 07:55:01 +02:00
parent 9242aeb750
commit a78eec93d6
3 changed files with 13 additions and 2 deletions

View File

@ -83,6 +83,10 @@ public class DependencyAgent implements DependencyInfo, ServiceRepository {
return analyzer.agentClassSource; return analyzer.agentClassSource;
} }
public ClassReaderSource getUnprocessedClassSource() {
return analyzer.getUnprocessedClassSource();
}
@Override @Override
public ClassLoader getClassLoader() { public ClassLoader getClassLoader() {
return analyzer.getClassLoader(); return analyzer.getClassLoader();

View File

@ -81,6 +81,7 @@ public abstract class DependencyAnalyzer implements DependencyInfo {
|| shouldLog; || shouldLog;
static final boolean dependencyReport = System.getProperty("org.teavm.dependencyReport", "false").equals("true"); static final boolean dependencyReport = System.getProperty("org.teavm.dependencyReport", "false").equals("true");
private int classNameSuffix; private int classNameSuffix;
private ClassReaderSource unprocessedClassSource;
private DependencyClassSource classSource; private DependencyClassSource classSource;
ClassReaderSource agentClassSource; ClassReaderSource agentClassSource;
private ClassLoader classLoader; private ClassLoader classLoader;
@ -118,6 +119,7 @@ public abstract class DependencyAnalyzer implements DependencyInfo {
DependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services, DependencyAnalyzer(ClassReaderSource classSource, ClassLoader classLoader, ServiceRepository services,
Diagnostics diagnostics, ReferenceCache referenceCache) { Diagnostics diagnostics, ReferenceCache referenceCache) {
this.unprocessedClassSource = classSource;
this.diagnostics = diagnostics; this.diagnostics = diagnostics;
this.referenceCache = referenceCache; this.referenceCache = referenceCache;
this.classSource = new DependencyClassSource(classSource, diagnostics, incrementalCache); this.classSource = new DependencyClassSource(classSource, diagnostics, incrementalCache);
@ -200,6 +202,10 @@ public abstract class DependencyAnalyzer implements DependencyInfo {
return classSource != null ? classSource : agentClassSource; return classSource != null ? classSource : agentClassSource;
} }
public ClassReaderSource getUnprocessedClassSource() {
return unprocessedClassSource;
}
public boolean isSynthesizedClass(String className) { public boolean isSynthesizedClass(String className) {
return classSource != null ? classSource.isGeneratedClass(className) : generatedClassNames.contains(className); return classSource != null ? classSource.isGeneratedClass(className) : generatedClassNames.contains(className);
} }

View File

@ -26,6 +26,7 @@ import org.teavm.metaprogramming.impl.model.MethodDescriber;
import org.teavm.metaprogramming.impl.model.MethodModel; import org.teavm.metaprogramming.impl.model.MethodModel;
import org.teavm.metaprogramming.impl.optimization.Optimizations; import org.teavm.metaprogramming.impl.optimization.Optimizations;
import org.teavm.metaprogramming.impl.reflect.ReflectContext; import org.teavm.metaprogramming.impl.reflect.ReflectContext;
import org.teavm.model.ClassHierarchy;
import org.teavm.model.ClassReader; import org.teavm.model.ClassReader;
import org.teavm.model.MethodReader; import org.teavm.model.MethodReader;
import org.teavm.model.MethodReference; import org.teavm.model.MethodReference;
@ -45,8 +46,8 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene
describer = new MethodDescriber(MetaprogrammingImpl.createDiagnostics(), agent.getClassSource()); describer = new MethodDescriber(MetaprogrammingImpl.createDiagnostics(), agent.getClassSource());
MetaprogrammingImpl.classLoader = proxyClassLoader; MetaprogrammingImpl.classLoader = proxyClassLoader;
MetaprogrammingImpl.classSource = agent.getClassSource(); MetaprogrammingImpl.classSource = agent.getUnprocessedClassSource();
MetaprogrammingImpl.hierarchy = agent.getClassHierarchy(); MetaprogrammingImpl.hierarchy = new ClassHierarchy(agent.getUnprocessedClassSource());
MetaprogrammingImpl.incrementalDependencies = agent.getIncrementalCache(); MetaprogrammingImpl.incrementalDependencies = agent.getIncrementalCache();
MetaprogrammingImpl.agent = agent; MetaprogrammingImpl.agent = agent;
MetaprogrammingImpl.reflectContext = new ReflectContext(agent.getClassHierarchy(), proxyClassLoader); MetaprogrammingImpl.reflectContext = new ReflectContext(agent.getClassHierarchy(), proxyClassLoader);