modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java
modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java modified: ../../../../main/java/de/dhbwstuttgart/typeinference/unify/model/Node.java Fehler in der Transitivaet der Finit Closure gefixt modified: ../../../java/bytecode/InheritTest.java modified: ../../bytecode/javFiles/AA.jav modified: ../../bytecode/javFiles/CC.jav modified: ../../bytecode/javFiles/Inherit.jav Noch Probl;em in der Reflections
This commit is contained in:
parent
71c801c19c
commit
eb27003515
@ -2041,7 +2041,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
|
||||
//Alle wildcard Faelle rausfiltern bei not wildable
|
||||
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||
@ -2079,7 +2079,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
||||
|
||||
//Alle wildcard Faelle rausfiltern bei not wildable
|
||||
//Alle wildcard Faelle rausfiltern bei not wildcardable
|
||||
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||
|
@ -75,6 +75,15 @@ implements IFiniteClosure {
|
||||
|
||||
// Build the transitive closure of the inheritance tree
|
||||
for(UnifyPair pair : pairs) {
|
||||
|
||||
try {
|
||||
logFile.write("Pair: " + pair + "\n");
|
||||
logFile.flush();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.err.println("no LogFile");
|
||||
}
|
||||
|
||||
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||
continue;
|
||||
|
||||
@ -100,6 +109,10 @@ implements IFiniteClosure {
|
||||
// Add edges to build the transitive closure
|
||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
||||
|
||||
//PL eingefuegt 2020-05-07 File UnitTest InheritTest.java
|
||||
this.inheritanceGraph.forEach((x,y) -> { if (y.getDescendants().contains(parentNode)) { y.addDescendant(childNode); y.addAllDescendant(childNode.getDescendants());};
|
||||
if (y.getPredecessors().contains(childNode)) { y.addPredecessor(parentNode); y.addAllPredecessor(parentNode.getPredecessors());};} );
|
||||
}
|
||||
|
||||
// Build the alternative representation with strings as keys
|
||||
|
@ -45,6 +45,15 @@ class Node<T> {
|
||||
descendant.addPredecessor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds some directed edges from this node to the descendant (this -> descendant)
|
||||
*/
|
||||
public void addAllDescendant(Set<Node<T>> allDescendants) {
|
||||
for(Node<T> descendant: allDescendants) {
|
||||
addDescendant(descendant);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||
*/
|
||||
@ -56,6 +65,15 @@ class Node<T> {
|
||||
predecessor.addDescendant(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds some directed edges from the predecessor to this node (predecessor -> this)
|
||||
*/
|
||||
public void addAllPredecessor(Set<Node<T>> allPredecessors) {
|
||||
for(Node<T> predecessor: allPredecessors) {
|
||||
addPredecessor(predecessor);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The content of this node.
|
||||
*/
|
||||
|
@ -7,13 +7,19 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||
@ -24,17 +30,17 @@ public class InheritTest {
|
||||
private static JavaTXCompiler compiler;
|
||||
private static ClassLoader loader;
|
||||
private static Class<?> classToTest;
|
||||
private static Class<?> classToTest1;
|
||||
private static String pathToClassFile;
|
||||
private static Class<?> classToTest1, classToTest2, classToTest3, classToTest4;
|
||||
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||
private static Object instanceOfClass;
|
||||
private static Object instanceOfClass1;
|
||||
private static Object instanceOfClass1, instanceOfClass2, instanceOfClass3, instanceOfClass4;
|
||||
private static HashMap<ArrayList<String>, Method> hm = new HashMap<>();
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
@ -45,45 +51,53 @@ public class InheritTest {
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest1 = loader.loadClass("AA");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTest2 = loader.loadClass("BB");
|
||||
instanceOfClass2 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest1 = loader.loadClass("AA");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTest3 = loader.loadClass("CC");
|
||||
instanceOfClass3 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest1 = loader.loadClass("AA");
|
||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
classToTest4 = loader.loadClass("DD");
|
||||
instanceOfClass4 = classToTest1.getDeclaredConstructor().newInstance();
|
||||
|
||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||
fileToTest = new File(path);
|
||||
compiler = new JavaTXCompiler(fileToTest);
|
||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
||||
compiler = new JavaTXCompiler(
|
||||
Lists.newArrayList(fileToTest),
|
||||
Lists.newArrayList(new File(pathToClassFile)));
|
||||
//compiler = new JavaTXCompiler(fileToTest);
|
||||
typeinferenceResult = compiler.typeInference();
|
||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||
classToTest = loader.loadClass("Inherit");
|
||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
||||
|
||||
for (Method m: classToTest.getMethods()) {
|
||||
ArrayList<String> param = Arrays.stream(m.getParameterTypes()).map(x -> x.getName()).collect(Collectors.toCollection(ArrayList::new));
|
||||
ArrayList<String> nameParam = new ArrayList<>();
|
||||
nameParam.add(m.getName());
|
||||
nameParam.addAll(param);
|
||||
hm.put(nameParam, m);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -92,15 +106,35 @@ public class InheritTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAName() {
|
||||
public void testAAName() {
|
||||
assertEquals("AA", classToTest1.getName());
|
||||
}
|
||||
/*
|
||||
|
||||
@Test
|
||||
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
||||
public void testBBName() {
|
||||
assertEquals("BB", classToTest2.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCCName() {
|
||||
assertEquals("CC", classToTest3.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDDName() {
|
||||
assertEquals("DD", classToTest4.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testmainAA() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, InstantiationException {
|
||||
String[] x = {"main", "AA", "java.lang.Integer"};
|
||||
ArrayList<String> nameParam = new ArrayList<>(Arrays.asList(x));
|
||||
Method m = hm.get(nameParam);
|
||||
assertEquals(m.invoke(classToTest1.getConstructor().newInstance(), 5), "AA");
|
||||
}
|
||||
/*
|
||||
Vector<Integer> v_invoke = new Vector<>();
|
||||
m.invoke(instanceOfClass, 5, v_invoke);
|
||||
Vector<Integer> v = new Vector<>();
|
||||
v.add(5);
|
||||
assertEquals(v, v_invoke);
|
||||
|
@ -1,5 +1,6 @@
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
public class AA {
|
||||
m(Integer i) { }
|
||||
m(Integer i) { return "AA"; }
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
import java.lang.Integer;
|
||||
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
public class CC extends BB {
|
||||
m(Integer i) { }
|
||||
m(Integer i) { return "CC"; }
|
||||
}
|
||||
|
@ -1,17 +1,18 @@
|
||||
import java.util.Vector;
|
||||
|
||||
import java.lang.Integer;
|
||||
import java.lang.String;
|
||||
|
||||
|
||||
public class Inherit {
|
||||
|
||||
main(d, i) {
|
||||
d.m(i);
|
||||
return d.m(i);
|
||||
}
|
||||
|
||||
main(v, i) {
|
||||
var aa = v.elementAt(0);
|
||||
aa.m(i);
|
||||
return aa.m(i);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user