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;
}
public ClassReaderSource getUnprocessedClassSource() {
return analyzer.getUnprocessedClassSource();
}
@Override
public ClassLoader getClassLoader() {
return analyzer.getClassLoader();

View File

@ -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);
}

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.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);