forked from JavaTX/JavaCompilerCore
Fix test case a bit
This commit is contained in:
parent
7fb4824f8d
commit
df78937ef3
@ -68,7 +68,7 @@ public class JavaTXCompiler {
|
||||
|
||||
Boolean log = false; //gibt an ob ein Log-File nach System.getProperty("user.dir")+""/logFiles/"" geschrieben werden soll?
|
||||
public volatile UnifyTaskModel usedTasks = new UnifyTaskModel();
|
||||
private final DirectoryClassLoader classLoader;
|
||||
public final DirectoryClassLoader classLoader;
|
||||
|
||||
private final List<File> classPath;
|
||||
private final File outputPath;
|
||||
@ -150,11 +150,25 @@ public class JavaTXCompiler {
|
||||
// sf enthaelt neues Source-File, neue Klassen-Objekte und neue
|
||||
// ArrayListen-Objekte fuer Fields, Construktoren und Methoden
|
||||
// Alle anderen Objekte werden nur kopiert.
|
||||
sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass));
|
||||
allClasses.addAll(sf_new.getClasses());
|
||||
var isCached = false;
|
||||
for (var clazz : sf.availableClasses) {
|
||||
if (loadedClasses.containsKey(clazz.getClassName())) {
|
||||
allClasses.removeIf(cl -> cl.getClassName().equals(clazz.getClassName()));
|
||||
var cif = loadedClasses.get(clazz.getClassName()).cif();
|
||||
allClasses.add(cif);
|
||||
isCached = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isCached) {
|
||||
sf_new.KlassenVektor.forEach(cl -> addMethods(sf_new, cl, sf.availableClasses, objectClass));
|
||||
allClasses.addAll(sf_new.getClasses());
|
||||
}
|
||||
}
|
||||
|
||||
TYPE ty = new TYPE(sourceFiles.get(sourceFile), allClasses);
|
||||
return ty.getConstraints();
|
||||
var constraints = ty.getConstraints();
|
||||
return constraints;
|
||||
}
|
||||
|
||||
void addMethods(SourceFile sf, ClassOrInterface cl, List<ClassOrInterface> importedClasses, ClassOrInterface objectClass) {
|
||||
@ -647,6 +661,10 @@ public class JavaTXCompiler {
|
||||
|
||||
public final JavaClassRegistry classRegistry = new JavaClassRegistry();
|
||||
|
||||
public record ClassEntry(File classFile, ClassOrInterface cif) {}
|
||||
|
||||
public final Map<JavaClassName, ClassEntry> loadedClasses = new HashMap<>();
|
||||
|
||||
private SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||
SourceFileContext tree = JavaTXParser.parse(sourceFile);
|
||||
environment.addClassesToRegistry(classRegistry, tree, sourceFile, this);
|
||||
@ -685,7 +703,10 @@ public class JavaTXCompiler {
|
||||
}
|
||||
|
||||
writeClassFile(classFiles, path, outputPath == null);
|
||||
return ASTFactory.createClass(classLoader.loadClass(name.toString()));
|
||||
var clazz = classLoader.loadClass(name.toString());
|
||||
var classOrInterface = ASTFactory.createClass(clazz);
|
||||
loadedClasses.put(name, new ClassEntry(new File(path, clazz.getName() + ".class"), classOrInterface));
|
||||
return classOrInterface;
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
@ -41,4 +41,8 @@ public class DirectoryClassLoader extends URLClassLoader implements IByteArrayCl
|
||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
||||
return super.findClass(name);
|
||||
}
|
||||
|
||||
public Class<?> _findLoadedClass(String name) throws ClassNotFoundException {
|
||||
return super.findLoadedClass(name);
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,8 @@ public class GatherNames {
|
||||
if (importDeclCtx.MUL() == null) {
|
||||
var name = importDeclCtx.qualifiedName().getText();
|
||||
var className = new JavaClassName(name);
|
||||
if (compiler.loadJavaTXClass(className) != null) {
|
||||
var clazz = compiler.loadJavaTXClass(className);
|
||||
if (clazz != null) {
|
||||
ret.put(name, compiler.classRegistry.getNumberOfGenerics(name));
|
||||
} else {
|
||||
Class<?> cl = compiler.getClassLoader().loadClass(name);
|
||||
|
@ -9,10 +9,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Stellt jede Art von Klasse dar. Auch abstrakte Klassen und Interfaces
|
||||
|
@ -18,11 +18,12 @@ public class InheritTest {
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
var classLoader = new ByteArrayClassLoader();
|
||||
|
||||
classToTestAA = TestCodegen.generateClassFiles(classLoader, "AA.jav").get("AA");
|
||||
classToTestBB = TestCodegen.generateClassFiles(classLoader, "BB.jav").get("BB");
|
||||
classToTestCC = TestCodegen.generateClassFiles(classLoader, "CC.jav").get("CC");
|
||||
classToTestDD = TestCodegen.generateClassFiles(classLoader, "DD.jav").get("DD");
|
||||
classToTest = TestCodegen.generateClassFiles(classLoader, "Inherit.jav").get("Inherit");
|
||||
var classes = TestCodegen.generateClassFiles(classLoader, "Inherit.jav");
|
||||
classToTest = classes.get("Inherit");
|
||||
classToTestAA = classes.get("AA");
|
||||
classToTestBB = classes.get("BB");
|
||||
classToTestCC = classes.get("CC");
|
||||
classToTestDD = classes.get("DD");
|
||||
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
instanceOfClassAA = classToTestAA.getDeclaredConstructor().newInstance();
|
||||
|
@ -21,6 +21,7 @@ import static org.junit.Assert.*;
|
||||
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -64,6 +65,11 @@ public class TestCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
for (var entry : compiler.loadedClasses.entrySet()) {
|
||||
var name = entry.getKey().toString();
|
||||
result.put(name, classLoader.loadClass(Path.of(entry.getValue().classFile().toURI())));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user