From 44318ee5d8985484c555e441353f4c63829ed759 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 7 Apr 2016 14:39:07 +0200 Subject: [PATCH] =?UTF-8?q?Aufr=C3=A4umen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dhbwstuttgart/syntaxtree/SourceFile.java | 3 +- .../syntaxtree/factory/UnifyTypeFactory.java | 6 +- .../typeinference/ConstraintsSet.java | 2 +- .../typeinference/OderConstraint.java | 2 +- .../typeinference/OderMenge.java | 2 +- .../typeinference/UndConstraint.java | 2 +- .../typeinference/UnifyConstraintsSet.java | 6 +- .../typeinference/UnifyOderConstraint.java | 4 +- .../typeinference/UnifyUndConstraint.java | 2 +- ...fier.java => Unifikationsalgorithmus.java} | 2 +- .../unify/model/FiniteClosure.java | 5 ++ test/bytecode/types/Overloading2.jav | 18 +++++ test/bytecode/types/Overloading2Test.java | 71 +++++++++++++++++++ .../MultipleTypesInsertTester.java | 3 +- test/unify/UnifyTypeFactoryTest.java | 5 ++ 15 files changed, 117 insertions(+), 16 deletions(-) rename src/de/dhbwstuttgart/typeinference/unify/{Unifier.java => Unifikationsalgorithmus.java} (81%) create mode 100644 test/bytecode/types/Overloading2.jav create mode 100644 test/bytecode/types/Overloading2Test.java diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index d271fd84..2892773f 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -279,7 +279,8 @@ public class SourceFile Set> xConstraints = unifyConstraints.cartesianProduct(); - + + typinferenzLog.debug("Finite Closure: "+finiteClosure, Section.TYPEINFERENCE); typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints, Section.TYPEINFERENCE); //finiteClosure.generateFullyNamedTypes(globalAssumptions); diff --git a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java index 0e0da3fc..1f14bb34 100644 --- a/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java +++ b/src/de/dhbwstuttgart/syntaxtree/factory/UnifyTypeFactory.java @@ -49,13 +49,13 @@ public class UnifyTypeFactory { RefType superClass = cAss.getAssumedClass().getSuperClass(); if(superClass != null){ UnifyType tr = UnifyTypeFactory.convert(superClass); - pairs.add(smaller(tl, tr)); + pairs.add(generateSmallerPair(tl, tr)); } } return new FiniteClosure(pairs); } - public static UnifyPair smaller(UnifyType tl, UnifyType tr){ + public static UnifyPair generateSmallerPair(UnifyType tl, UnifyType tr){ return new UnifyPair(tl, tr, PairOperator.SMALLER); } @@ -135,7 +135,7 @@ public class UnifyTypeFactory { public static UnifyPair convert(Pair p) { if(!p.OperatorSmaller())throw new NotImplementedException(); - UnifyPair ret = smaller(UnifyTypeFactory.convert(p.TA1) + UnifyPair ret = generateSmallerPair(UnifyTypeFactory.convert(p.TA1) , UnifyTypeFactory.convert(p.TA2)); return ret; } diff --git a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java index c68e4865..e9f9918d 100755 --- a/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/ConstraintsSet.java @@ -6,7 +6,7 @@ import java.util.Vector; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.logger.*; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; public class ConstraintsSet extends UndMenge implements Iterable{ private static final Logger log = Logger.getLogger(ConstraintsSet.class.getName()); diff --git a/src/de/dhbwstuttgart/typeinference/OderConstraint.java b/src/de/dhbwstuttgart/typeinference/OderConstraint.java index e9187b39..9c741ec8 100755 --- a/src/de/dhbwstuttgart/typeinference/OderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/OderConstraint.java @@ -8,7 +8,7 @@ import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; public class OderConstraint extends OderMenge{ private Set oderConstraintPairs; diff --git a/src/de/dhbwstuttgart/typeinference/OderMenge.java b/src/de/dhbwstuttgart/typeinference/OderMenge.java index 842c78a3..d6083480 100644 --- a/src/de/dhbwstuttgart/typeinference/OderMenge.java +++ b/src/de/dhbwstuttgart/typeinference/OderMenge.java @@ -10,7 +10,7 @@ import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; public abstract class OderMenge implements KomplexeMenge{ diff --git a/src/de/dhbwstuttgart/typeinference/UndConstraint.java b/src/de/dhbwstuttgart/typeinference/UndConstraint.java index 35468bd7..a53f0998 100755 --- a/src/de/dhbwstuttgart/typeinference/UndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UndConstraint.java @@ -6,7 +6,7 @@ import java.util.Vector; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.exceptions.DebugException; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; /** * Stellt ein Constraint dar, welches aus mehreren Constraint-Paaren besteht. Diese gelten alle stets gleichzeitig / sind per "Und" miteinander verknüpft. diff --git a/src/de/dhbwstuttgart/typeinference/UnifyConstraintsSet.java b/src/de/dhbwstuttgart/typeinference/UnifyConstraintsSet.java index 5c7ed8b7..b19a0197 100644 --- a/src/de/dhbwstuttgart/typeinference/UnifyConstraintsSet.java +++ b/src/de/dhbwstuttgart/typeinference/UnifyConstraintsSet.java @@ -5,7 +5,7 @@ import java.util.Set; import java.util.Vector; import de.dhbwstuttgart.logger.Logger; import de.dhbwstuttgart.logger.*; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class UnifyConstraintsSet extends UndMenge implements Iterable{ @@ -37,7 +37,7 @@ public class UnifyConstraintsSet extends UndMenge implements Iterable return constraintsSet.iterator(); } - public void filterWrongConstraints(Unifier unify) { + public void filterWrongConstraints(Unifikationsalgorithmus unify) { /* * Das ConstraintsSet enthält nur OderConstraints, welche UND-Verknüpft sind. * Hier werden Constraints in den OderConstraints kontrolliert: @@ -51,7 +51,7 @@ public class UnifyConstraintsSet extends UndMenge implements Iterable * Nimmt alle UndConstraints und filtert mithilfe dieser die falschen Constraints aus den OderConstraints * @param unifier */ - public void unifyUndConstraints(Unifier unifier) { + public void unifyUndConstraints(Unifikationsalgorithmus unifier) { Vector uCons = this.filterUndConstraints(); Vector alleUndConstraints = new Vector<>(); for(UnifyUndConstraint undConstraint : uCons){ diff --git a/src/de/dhbwstuttgart/typeinference/UnifyOderConstraint.java b/src/de/dhbwstuttgart/typeinference/UnifyOderConstraint.java index 49dbf6de..4955ea93 100644 --- a/src/de/dhbwstuttgart/typeinference/UnifyOderConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UnifyOderConstraint.java @@ -8,7 +8,7 @@ import de.dhbwstuttgart.logger.Section; import de.dhbwstuttgart.syntaxtree.type.RefType; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; public class UnifyOderConstraint extends OderMenge{ @@ -83,7 +83,7 @@ public class UnifyOderConstraint extends OderMenge{ * welche keinen Sinn ergeben, also beim unifizieren scheitern. * @param unifier - Wird für die Unifizierung benutzt */ - void filterWrongConstraints(Unifier unifier) { + void filterWrongConstraints(Unifikationsalgorithmus unifier) { Set filteredConstraints = new Menge<>(); for(UnifyUndConstraint cons : this.getUndConstraints()){ Set> unifierResult = unifier.apply(cons.getConstraintPairs()); diff --git a/src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java b/src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java index d13ead18..f1ed0548 100644 --- a/src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java +++ b/src/de/dhbwstuttgart/typeinference/UnifyUndConstraint.java @@ -6,7 +6,7 @@ import java.util.Vector; import de.dhbwstuttgart.syntaxtree.type.Type; import de.dhbwstuttgart.typeinference.exceptions.DebugException; -import de.dhbwstuttgart.typeinference.unify.Unifier; +import de.dhbwstuttgart.typeinference.unify.Unifikationsalgorithmus; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; /** diff --git a/src/de/dhbwstuttgart/typeinference/unify/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/Unifikationsalgorithmus.java similarity index 81% rename from src/de/dhbwstuttgart/typeinference/unify/Unifier.java rename to src/de/dhbwstuttgart/typeinference/unify/Unifikationsalgorithmus.java index 0a08a210..39c25e57 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/Unifikationsalgorithmus.java @@ -4,7 +4,7 @@ import java.util.Set; import de.dhbwstuttgart.typeinference.unify.model.UnifyPair; -public interface Unifier { +public interface Unifikationsalgorithmus { public Set> apply (Set E); diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java index 6fff42cc..d5aaaf72 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/FiniteClosure.java @@ -383,4 +383,9 @@ public class FiniteClosure implements IFiniteClosure { permuteParams(candidates, idx+1, result, current); } } + + @Override + public String toString(){ + return this.inheritanceGraph.toString(); + } } diff --git a/test/bytecode/types/Overloading2.jav b/test/bytecode/types/Overloading2.jav new file mode 100644 index 00000000..86961c95 --- /dev/null +++ b/test/bytecode/types/Overloading2.jav @@ -0,0 +1,18 @@ +import java.util.Vector; + +class Overloading2{ + + String method(Vector v) { + return v; + } + + Integer method(Vector v) { + return v; + } + + public static void main(String[] args){ + Overloading2 t; + t = new Overloading2(); + t.method(new Vector()); + } +} \ No newline at end of file diff --git a/test/bytecode/types/Overloading2Test.java b/test/bytecode/types/Overloading2Test.java new file mode 100644 index 00000000..aed1c45d --- /dev/null +++ b/test/bytecode/types/Overloading2Test.java @@ -0,0 +1,71 @@ +package bytecode.types; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Method; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.Vector; + +import org.junit.Test; + +import bytecode.SourceFileBytecodeTest; + +public class Overloading2Test extends SourceFileBytecodeTest{ + @Override + protected void init() { + testName = "Overloading2"; + rootDirectory = System.getProperty("user.dir")+"/test/bytecode/types/"; + } + + + @Test + public void testString() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + File file = new File(rootDirectory); + URL url = file.toURL(); + URL[] urls = new URL[]{url}; + + Class stringVector = classLoader.loadClass("java%util%Vector%%java%lang%String%"); + + Class[] params = new Class[1]; + params[0] = stringVector; + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, stringVector.newInstance()); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + @Test + public void testInteger() { + try{ + ClassLoader classLoader = getClassLoader(); + + Class cls = classLoader.loadClass(testName); + + Object obj = cls.newInstance(); + + Class integerVector = classLoader.loadClass("java%util%Vector%%java%lang%Integer%"); + + Class[] params = new Class[1]; + params[0] = integerVector; + + Method method = cls.getDeclaredMethod("method", params); + method.invoke(obj, integerVector.newInstance()); + assertTrue(true); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + +} diff --git a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java index db3346a1..4542f9f0 100755 --- a/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java +++ b/test/plugindevelopment/TypeInsertTests/MultipleTypesInsertTester.java @@ -102,12 +102,13 @@ public class MultipleTypesInsertTester extends TypeInsertTester{ } catch (IOException | yyException e) { e.printStackTrace(); TestCase.fail(); + }finally{ + writeLog(sourceFileToInfere+".log"); } for(String containString : mustContain){ TestCase.assertTrue("\""+containString+"\" muss in den inferierten Lösungen vorkommen",gesamterSrc.contains(containString)); } - writeLog(sourceFileToInfere+".log"); } private static void writeLog(String toFile){ diff --git a/test/unify/UnifyTypeFactoryTest.java b/test/unify/UnifyTypeFactoryTest.java index 10e5582c..2cf5bc53 100644 --- a/test/unify/UnifyTypeFactoryTest.java +++ b/test/unify/UnifyTypeFactoryTest.java @@ -30,6 +30,11 @@ import de.dhbwstuttgart.typeinference.unify.model.UnifyType; public class UnifyTypeFactoryTest { private static TypeFactory tf = new TypeFactory(); + @Test + public void convertUnifyTypes(){ + //UnifyType ut = + } + @Test public void convertConstraintSet(){ ConstraintsSet cons = new ConstraintsSet();