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<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//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;
|
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||||
@ -2079,7 +2079,7 @@ public class TypeUnifyTask extends RecursiveTask<Set<Set<UnifyPair>>> {
|
|||||||
//Set<UnifyPair> retFlat = new HashSet<>();
|
//Set<UnifyPair> retFlat = new HashSet<>();
|
||||||
//ret.stream().forEach(x -> retFlat.addAll(x));
|
//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;
|
ret = ret.stream().filter(x -> { Optional<UnifyPair> optElem;
|
||||||
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
return !((optElem=x.stream().filter(y -> (y.getLhsType()) instanceof PlaceholderType
|
||||||
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
&& !((PlaceholderType)y.getLhsType()).isWildcardable()
|
||||||
|
@ -75,6 +75,15 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
// Build the transitive closure of the inheritance tree
|
// Build the transitive closure of the inheritance tree
|
||||||
for(UnifyPair pair : pairs) {
|
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)
|
if(pair.getPairOp() != PairOperator.SMALLER)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@ -93,13 +102,17 @@ implements IFiniteClosure {
|
|||||||
|
|
||||||
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
Node<UnifyType> childNode = inheritanceGraph.get(pair.getLhsType());
|
||||||
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
Node<UnifyType> parentNode = inheritanceGraph.get(pair.getRhsType());
|
||||||
|
|
||||||
// Add edge
|
// Add edge
|
||||||
parentNode.addDescendant(childNode);
|
parentNode.addDescendant(childNode);
|
||||||
|
|
||||||
// Add edges to build the transitive closure
|
// Add edges to build the transitive closure
|
||||||
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
parentNode.getPredecessors().stream().forEach(x -> x.addDescendant(childNode));
|
||||||
childNode.getDescendants().stream().forEach(x -> x.addPredecessor(parentNode));
|
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
|
// Build the alternative representation with strings as keys
|
||||||
|
@ -45,6 +45,15 @@ class Node<T> {
|
|||||||
descendant.addPredecessor(this);
|
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)
|
* Adds a directed edge from the predecessor to this node (predecessor -> this)
|
||||||
*/
|
*/
|
||||||
@ -56,6 +65,15 @@ class Node<T> {
|
|||||||
predecessor.addDescendant(this);
|
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.
|
* The content of this node.
|
||||||
*/
|
*/
|
||||||
|
@ -7,13 +7,19 @@ import java.lang.reflect.InvocationTargetException;
|
|||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
import de.dhbwstuttgart.bytecode.genericsGeneratorTypes.GenericGenratorResultForSourceFile;
|
||||||
import de.dhbwstuttgart.core.JavaTXCompiler;
|
import de.dhbwstuttgart.core.JavaTXCompiler;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
import de.dhbwstuttgart.typeinference.result.ResultSet;
|
||||||
@ -24,17 +30,17 @@ public class InheritTest {
|
|||||||
private static JavaTXCompiler compiler;
|
private static JavaTXCompiler compiler;
|
||||||
private static ClassLoader loader;
|
private static ClassLoader loader;
|
||||||
private static Class<?> classToTest;
|
private static Class<?> classToTest;
|
||||||
private static Class<?> classToTest1;
|
private static Class<?> classToTest1, classToTest2, classToTest3, classToTest4;
|
||||||
private static String pathToClassFile;
|
private static String pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";;
|
||||||
private static Object instanceOfClass;
|
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
|
@BeforeClass
|
||||||
public static void setUpBeforeClass() throws Exception {
|
public static void setUpBeforeClass() throws Exception {
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/AA.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
|
||||||
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
List<ResultSet> typeinferenceResult = compiler.typeInference();
|
||||||
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
List<GenericGenratorResultForSourceFile> simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
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";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/BB.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
|
||||||
typeinferenceResult = compiler.typeInference();
|
typeinferenceResult = compiler.typeInference();
|
||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest1 = loader.loadClass("AA");
|
classToTest2 = loader.loadClass("BB");
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClass2 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/CC.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
|
||||||
typeinferenceResult = compiler.typeInference();
|
typeinferenceResult = compiler.typeInference();
|
||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest1 = loader.loadClass("AA");
|
classToTest3 = loader.loadClass("CC");
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClass3 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/DD.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(fileToTest);
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/";
|
|
||||||
typeinferenceResult = compiler.typeInference();
|
typeinferenceResult = compiler.typeInference();
|
||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest1 = loader.loadClass("AA");
|
classToTest4 = loader.loadClass("DD");
|
||||||
instanceOfClass1 = classToTest1.getDeclaredConstructor().newInstance();
|
instanceOfClass4 = classToTest1.getDeclaredConstructor().newInstance();
|
||||||
|
|
||||||
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
path = System.getProperty("user.dir")+"/src/test/resources/bytecode/javFiles/Inherit.jav";
|
||||||
fileToTest = new File(path);
|
fileToTest = new File(path);
|
||||||
compiler = new JavaTXCompiler(fileToTest);
|
compiler = new JavaTXCompiler(
|
||||||
pathToClassFile = System.getProperty("user.dir")+"/src/test/resources/testBytecode/generatedBC/";
|
Lists.newArrayList(fileToTest),
|
||||||
|
Lists.newArrayList(new File(pathToClassFile)));
|
||||||
|
//compiler = new JavaTXCompiler(fileToTest);
|
||||||
typeinferenceResult = compiler.typeInference();
|
typeinferenceResult = compiler.typeInference();
|
||||||
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
simplifyResultsForAllSourceFiles = compiler.getGeneratedGenericResultsForAllSourceFiles(typeinferenceResult);
|
||||||
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
compiler.generateBytecode(new File(pathToClassFile),typeinferenceResult,simplifyResultsForAllSourceFiles);
|
||||||
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
loader = new URLClassLoader(new URL[] {new URL("file://"+pathToClassFile)});
|
||||||
classToTest = loader.loadClass("Inherit");
|
classToTest = loader.loadClass("Inherit");
|
||||||
instanceOfClass = classToTest.getDeclaredConstructor().newInstance();
|
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
|
@Test
|
||||||
@ -92,15 +106,35 @@ public class InheritTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAName() {
|
public void testAAName() {
|
||||||
assertEquals("AA", classToTest1.getName());
|
assertEquals("AA", classToTest1.getName());
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
@Test
|
@Test
|
||||||
public void testPutElementVector() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
|
public void testBBName() {
|
||||||
Method m = classToTest.getDeclaredMethod("putElement", Object.class, Vector.class);
|
assertEquals("BB", classToTest2.getName());
|
||||||
Vector<Integer> v_invoke = new Vector<>();
|
}
|
||||||
m.invoke(instanceOfClass, 5, v_invoke);
|
|
||||||
|
@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<>();
|
||||||
Vector<Integer> v = new Vector<>();
|
Vector<Integer> v = new Vector<>();
|
||||||
v.add(5);
|
v.add(5);
|
||||||
assertEquals(v, v_invoke);
|
assertEquals(v, v_invoke);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
public class AA {
|
public class AA {
|
||||||
m(Integer i) { }
|
m(Integer i) { return "AA"; }
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
public class CC extends BB {
|
public class CC extends BB {
|
||||||
m(Integer i) { }
|
m(Integer i) { return "CC"; }
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
import java.lang.Integer;
|
import java.lang.Integer;
|
||||||
|
import java.lang.String;
|
||||||
|
|
||||||
|
|
||||||
public class Inherit {
|
public class Inherit {
|
||||||
|
|
||||||
main(d, i) {
|
main(d, i) {
|
||||||
d.m(i);
|
return d.m(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
main(v, i) {
|
main(v, i) {
|
||||||
var aa = v.elementAt(0);
|
var aa = v.elementAt(0);
|
||||||
aa.m(i);
|
return aa.m(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user