From c65774492e05605d2ff3cddef26a122c546e0f18 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Thu, 27 Mar 2014 16:50:36 +0100 Subject: [PATCH] =?UTF-8?q?Obsolete=20Klassen=20gel=C3=B6scht.=20Alle=20Fe?= =?UTF-8?q?hlermeldungen=20im=20src-Ordner=20behoben?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/mycompiler/MyCompiler.java | 1 - src/mycompiler/SourceFile.java | 2 +- src/mycompiler/myclass/Interface.java | 20 - src/mycompiler/myinterface/Interface.java | 60 ++- src/mycompiler/mytest/CByteCodeTest.java | 58 --- src/mycompiler/mytest/CInferenceTest.java | 103 ---- src/mycompiler/mytest/CSimpleTest.java | 90 ---- src/mycompiler/mytest/CWildcardTest.java | 92 ---- src/mycompiler/mytest/CompilerTestCase.java | 162 ------- src/mycompiler/mytest/JUnitTests.java | 98 ---- .../assumptions/CopyOfTypeAssumptions.java | 303 ------------ .../test/AbstractInferenceTest.java | 446 ------------------ 12 files changed, 38 insertions(+), 1397 deletions(-) delete mode 100644 src/mycompiler/myclass/Interface.java delete mode 100755 src/mycompiler/mytest/CByteCodeTest.java delete mode 100755 src/mycompiler/mytest/CInferenceTest.java delete mode 100755 src/mycompiler/mytest/CSimpleTest.java delete mode 100755 src/mycompiler/mytest/CWildcardTest.java delete mode 100755 src/mycompiler/mytest/CompilerTestCase.java delete mode 100755 src/mycompiler/mytest/JUnitTests.java delete mode 100644 src/typinferenz/assumptions/CopyOfTypeAssumptions.java delete mode 100755 test/mycompiler/test/AbstractInferenceTest.java diff --git a/src/mycompiler/MyCompiler.java b/src/mycompiler/MyCompiler.java index 1460ab22a..1788f1660 100755 --- a/src/mycompiler/MyCompiler.java +++ b/src/mycompiler/MyCompiler.java @@ -16,7 +16,6 @@ import java.util.Vector; import mycompiler.mybytecode.ClassFile; import mycompiler.myclass.Class; import mycompiler.myclass.ClassBody; -import mycompiler.myclass.Constructor_Backup; import mycompiler.myclass.DeclId; import mycompiler.myclass.FormalParameter; import mycompiler.myclass.ImportDeclarations; diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 7b478a1ca..f4d57cf54 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -230,7 +230,7 @@ public class SourceFile codegenlog.info("Anzahl der Interfaces: " + Integer.toString(InterfaceVektor.size())); for(int i = 0; i < InterfaceVektor.size(); i++) { - InterfaceVektor.elementAt(i).codegen(this); + InterfaceVektor.elementAt(i).codegen(result); } codegenlog.info("Anzahl der Klassen: " diff --git a/src/mycompiler/myclass/Interface.java b/src/mycompiler/myclass/Interface.java deleted file mode 100644 index 4434b55bd..000000000 --- a/src/mycompiler/myclass/Interface.java +++ /dev/null @@ -1,20 +0,0 @@ -package mycompiler.myclass; - -import java.util.Vector; - -import mycompiler.mymodifier.Modifiers; -import mycompiler.mytype.Type; - -/** - * Ein Interface ist eine abstrakte Klasse, erbt daher von Class - * @author janulrich - * - */ -public class Interface extends Class { - - public Interface(String name){ - super(name); - } - - -} diff --git a/src/mycompiler/myinterface/Interface.java b/src/mycompiler/myinterface/Interface.java index 3005d2742..5394d0706 100755 --- a/src/mycompiler/myinterface/Interface.java +++ b/src/mycompiler/myinterface/Interface.java @@ -7,6 +7,7 @@ import java.util.Vector; import mycompiler.AClassOrInterface; import mycompiler.mybytecode.ClassFile; +import mycompiler.myclass.Class; import mycompiler.myclass.ClassHelper; import mycompiler.myclass.Constant; import mycompiler.myclass.FormalParameter; @@ -27,12 +28,46 @@ import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; import mycompiler.SourceFile; // ino.end +/** + * Ein Interface ist eine abstrakte Klasse, erbt daher von Class + * @author janulrich + * + */ +public class Interface extends Class { + + public Interface(String name){ + super(name); + } + + public Interface(String name, Modifiers modifiers) { + super(name,modifiers); + } + + public Vector getParaList() { + // TODO Auto-generated method stub + return null; + } + + public void setInterfaceBody(InterfaceBody interfaceBody) { + // TODO Auto-generated method stub + + } + + public void setParaList(Vector paraVector) { + // TODO Auto-generated method stub + + } + + +} + // ino.class.Interface.23932.description type=javadoc /** * Die Klasse stellt die Definition eines Interfaces dar. * @author SCJU * */ +/* // ino.end // ino.class.Interface.23932.declaration public class Interface implements AClassOrInterface @@ -85,23 +120,7 @@ public class Interface implements AClassOrInterface } // ino.end - - // ino.method.getParaList.23954.defdescription type=block - /*public Vector complete_paralist(boolean ext) - { - - Diese Funktion vervollt�ndigt die Parameterliste f�r vererbte Klassen - Vector child = paralist; - - paralist = (Vector)superclassid.get_ParaList(); - - for(Enumeration e = child.elements();e.hasMoreElements();){ - paralist.addElement(e.nextElement()); - } - - return this.paralist; - }*/ - // ino.end + @@ -209,12 +228,6 @@ public class Interface implements AClassOrInterface } // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.23981.defdescription type=javadoc - /** - * Alle RefTypes, die hier im Interface definiert sind - * bspw: E doSomething() - * und eigentlich Generics sind werden zu generics gewandelt - * - */ // ino.end // ino.method.wandleRefTypeAttributes2GenericAttributes.23981.definition public void wandleRefTypeAttributes2GenericAttributes() @@ -255,3 +268,4 @@ public class Interface implements AClassOrInterface } // ino.end +*/ \ No newline at end of file diff --git a/src/mycompiler/mytest/CByteCodeTest.java b/src/mycompiler/mytest/CByteCodeTest.java deleted file mode 100755 index 23b97c6c3..000000000 --- a/src/mycompiler/mytest/CByteCodeTest.java +++ /dev/null @@ -1,58 +0,0 @@ -// ino.module.CByteCodeTest.8661.package -package mycompiler.mytest; -// ino.end - -// ino.module.CByteCodeTest.8661.import -import java.io.File; -import java.util.Iterator; -import java.util.Vector; -import mycompiler.MyCompiler; -import mycompiler.MyCompilerAPI; -import mycompiler.mytypereconstruction.CSubstitution; -import mycompiler.mytypereconstruction.TypeinferenceResultSet; -// ino.end - -// ino.class.CByteCodeTest.26367.description type=javadoc -/** - * Testklasse zum Generieren des ByteCode. - * @author scju - */ -// ino.end -// ino.class.CByteCodeTest.26367.declaration -public class CByteCodeTest -// ino.end -// ino.class.CByteCodeTest.26367.body -{ - - // ino.method.main.26370.definition - public static void main(String[] args) - throws Exception - // ino.end - // ino.method.main.26370.body - { - MyCompilerAPI compiler = MyCompiler.getAPI(); - - // Ausgabeverzeichnis festlegen - compiler.setOutputDir("Bytecode/"); - - // Parsen der Klasse - compiler.parse(new File(args[0])); - - // Typ-Rekonstruktion - Vector resultSet = compiler.typeReconstruction(); - if ((resultSet != null) && (resultSet.size() > 0)) { - TypeinferenceResultSet onePossibility = resultSet.firstElement(); - Iterator substIt = onePossibility.getSubstitutions().getIterator(); - while(substIt.hasNext()){ - CSubstitution subst = (CSubstitution)substIt.next(); - // Substition machen - subst.execute(); - } - } - - // Code generieren - compiler.codeGeneration(); - } - // ino.end -} -// ino.end diff --git a/src/mycompiler/mytest/CInferenceTest.java b/src/mycompiler/mytest/CInferenceTest.java deleted file mode 100755 index 256c7022e..000000000 --- a/src/mycompiler/mytest/CInferenceTest.java +++ /dev/null @@ -1,103 +0,0 @@ -// ino.module.CInferenceTest.8662.package -package mycompiler.mytest; -// ino.end - -// ino.module.CInferenceTest.8662.import -import java.io.File; -import java.util.Iterator; -import java.util.Vector; -import mycompiler.MyCompiler; -import mycompiler.MyCompilerAPI; -import mycompiler.myexception.CTypeReconstructionException; -import mycompiler.mytypereconstruction.CSubstitution; -import mycompiler.mytypereconstruction.TypeinferenceResultSet; -import org.apache.log4j.Logger; -// ino.end - -// ino.class.CInferenceTest.26373.description type=javadoc -/** - * Testklasse fr die Typinferenz - * @author Timo Holzherr - */ -// ino.end -// ino.class.CInferenceTest.26373.declaration -public class CInferenceTest -// ino.end -// ino.class.CInferenceTest.26373.body -{ - - // ino.attribute.inferencelog.26376.declaration - protected static Logger inferencelog = Logger.getLogger("inference"); - // ino.end - - // ino.method.main.26379.definition - public static void main(String[] args) - throws Exception - // ino.end - // ino.method.main.26379.body - { - MyCompilerAPI compiler = MyCompiler.getAPI(); - try{ - - ///////////////////////// - // Parsen: - ///////////////////////// - - //1. Argument: zu kompilierende Datei - compiler.parse(new File(args[0])); - - MyCompiler.getAPI().setOutputDir("Bytecode/"); - - //compiler.semanticCheck(); - - ///////////////////////// - // Typrekonstruktion: - ///////////////////////// - Vector resultSet = compiler.typeReconstruction(); - ///////////////////////// - // Ausgabe: - ///////////////////////// - - - if(resultSet==null||resultSet.size()==0){ - inferencelog.error("Das Resultset ist leer!!!"); - System.exit(1); - } - - // if(true)System.exit(0); - TypeinferenceResultSet onePossibility = resultSet.firstElement(); - Iterator substIt = onePossibility.getSubstitutions().getIterator(); - while(substIt.hasNext()){ - CSubstitution subst = (CSubstitution)substIt.next(); - /*Vector lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers(); - String s = new String(); - for(int l=0; l resultSet = compiler.typeReconstruction(); - ///////////////////////// - // Ausgabe: - ///////////////////////// - TypeinferenceResultSet onePossibility = resultSet.firstElement(); - Iterator substIt = onePossibility.getSubstitutions().getIterator(); - while(substIt.hasNext()){ - CSubstitution subst = (CSubstitution)substIt.next(); - Vector lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers(); - String s = new String(); - for(int l=0; l resultSet = compiler.typeReconstruction(); - ///////////////////////// - // Ausgabe: - ///////////////////////// - - //test - SourceFile file = compiler.getSyntaxTree(); - FC_TTO fc_tto = file.makeFC(); - for(Pair p : fc_tto.getFC()) - { - if(p.TA1 instanceof RefType && ((RefType)p.TA1).get_ParaList() != null) - MyCompiler.wandleGeneric2RefType(((RefType)p.TA1).get_ParaList(),fc_tto.getClasses()); - - if(p.TA2 instanceof RefType && ((RefType)p.TA2).get_ParaList() != null) - MyCompiler.wandleGeneric2RefType(((RefType)p.TA2).get_ParaList(),fc_tto.getClasses()); - } - for(Pair p : ((MyCompiler)compiler).testPair) - { - RefType TA1 = (RefType)p.TA1; - RefType TA2 = (RefType)p.TA2; - MyCompiler.wandleGeneric2RefType(TA1.get_ParaList(),fc_tto.getClasses()); - MyCompiler.wandleGeneric2RefType(TA2.get_ParaList(),fc_tto.getClasses()); - - //Vector smallers = Unify.smaller(TA2,fc_tto); - //Vector greaters = Unify.greater(TA2,fc_tto); - MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA2); - MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA1); - } - Vector> unifyers = Unify.unify(((MyCompiler)compiler).testPair,fc_tto); - - //Vector> testUni = Unify.unify(TypePlaceholder.fresh(),TypePlaceholder.fresh(),fc_tto); - /* - if(resultSet==null||resultSet.size()==0){ - //inferencelog.error("Das Resultset ist leer!!!"); - System.exit(1); - }*/ - - // inferencelog.debug("========FERTIG========"); - - compiler.codeGeneration(); - - - }catch(CTypeReconstructionException tre){ - tre.printStackTrace(); - }catch(Exception e){ - e.printStackTrace(); - } - } -} diff --git a/src/mycompiler/mytest/CompilerTestCase.java b/src/mycompiler/mytest/CompilerTestCase.java deleted file mode 100755 index ca753cf04..000000000 --- a/src/mycompiler/mytest/CompilerTestCase.java +++ /dev/null @@ -1,162 +0,0 @@ -// ino.module.CompilerTestCase.8663.package -package mycompiler.mytest; -// ino.end - -// ino.module.CompilerTestCase.8663.import -import java.io.File; -import java.util.Iterator; -import java.util.Vector; -import junit.framework.TestCase; -import mycompiler.MyCompiler; -import mycompiler.MyCompilerAPI; -import mycompiler.mytypereconstruction.CSubstitution; -import mycompiler.mytypereconstruction.TypeinferenceResultSet; -import org.apache.log4j.FileAppender; -import org.apache.log4j.Level; -import org.apache.log4j.Logger; -import org.apache.log4j.PatternLayout; -// ino.end - - -// ino.class.CompilerTestCase.26382.description type=javadoc -/** - * Testet den Compiler mit dem angegebenen JAV-File. - * @author SCJU - * - */ -// ino.end -// ino.class.CompilerTestCase.26382.declaration -public class CompilerTestCase extends TestCase -// ino.end -// ino.class.CompilerTestCase.26382.body -{ - - // ino.attribute.javFile.26386.declaration - protected File javFile; - // ino.end - // ino.attribute.compiler.26389.declaration - protected MyCompilerAPI compiler = MyCompiler.getAPI(); - // ino.end - - // ino.method.CompilerTestCase.26392.definition - public CompilerTestCase(String javFile, String name) - // ino.end - // ino.method.CompilerTestCase.26392.body - { - this.javFile = new File(javFile); - setName(name); - } - // ino.end - - // ino.method.CompilerTestCase.26395.definition - public CompilerTestCase(String javFile) - // ino.end - // ino.method.CompilerTestCase.26395.body - { - this.javFile = new File(javFile); - setName(this.javFile.getName()); - } - // ino.end - - - // ino.method.runTest.26398.definition - protected void runTest() - throws Throwable - // ino.end - // ino.method.runTest.26398.body - { - // Testablauf. Tritt eine Exception auf, - // schlaegt der Test fehl. - parseFile(); - typeReconstruction(); - codeGeneration(); - } - // ino.end - - // ino.method.parseFile.26401.definition - protected void parseFile() - throws Throwable - // ino.end - // ino.method.parseFile.26401.body - { - // Parsen der Klasse - compiler.parse(javFile); - } - // ino.end - - // ino.method.typeReconstruction.26404.definition - protected void typeReconstruction() - throws Exception - // ino.end - // ino.method.typeReconstruction.26404.body - { - // Typ-Rekonstruktion - Vector resultSet = compiler.typeReconstruction(); - // Keine Typ-Rekonstruktion erforderlich - if (resultSet == null || resultSet.size() == 0) throw new Exception("Typrekonstruktion nicht durchfuehrbar!"); - TypeinferenceResultSet onePossibility = resultSet.firstElement(); - Iterator substIt = onePossibility.getSubstitutions().getIterator(); - while(substIt.hasNext()){ - CSubstitution subst = (CSubstitution)substIt.next(); - // Substition machen - subst.execute(); - } - } - // ino.end - - // ino.method.codeGeneration.26407.definition - protected void codeGeneration() - throws Exception - // ino.end - // ino.method.codeGeneration.26407.body - { - // Code generieren - compiler.codeGeneration(); - } - // ino.end - - // ino.method.setUp.26410.definition - protected void setUp() - throws Exception - // ino.end - // ino.method.setUp.26410.body - { - super.setUp(); - - // Setup fuer Log4J - // Logfiles werden im Ordner testResults gespeichert - // Der Dateiname ist der Klassename plus .log - String logFile = "testResults/"+ javFile.getName() + ".log"; - - File f = new File(logFile); // Altes Logfile loeschen - f.delete(); - - // Ausgabeoptionen fuer die Logger - PatternLayout pl = new PatternLayout("%-15C{1} %-5p [%-9c] %m%n"); - FileAppender fa = new FileAppender(pl, logFile); - - // Die Einstellungen jedes Loggers veraendern - ModifyLogger("parser", Level.ALL, fa); - ModifyLogger("inference", Level.INFO, fa); - ModifyLogger("codegen", Level.ALL, fa); - ModifyLogger("bytecode", Level.ALL, fa); - } - // ino.end - - // ino.method.ModifyLogger.26413.defdescription type=line - // Veraendert die Ausgabeoptionen des angegebenen Loggers - // ino.end - // ino.method.ModifyLogger.26413.definition - protected void ModifyLogger(String strlogger, Level lv, FileAppender fa) - // ino.end - // ino.method.ModifyLogger.26413.body - { - Logger lg = Logger.getLogger(strlogger); - - lg.setLevel(lv); - lg.removeAllAppenders(); - lg.addAppender(fa); - } - // ino.end -} -// ino.end diff --git a/src/mycompiler/mytest/JUnitTests.java b/src/mycompiler/mytest/JUnitTests.java deleted file mode 100755 index e602650bf..000000000 --- a/src/mycompiler/mytest/JUnitTests.java +++ /dev/null @@ -1,98 +0,0 @@ -// ino.module.JUnitTests.8665.package -package mycompiler.mytest; -// ino.end - -// ino.module.JUnitTests.8665.import -import junit.framework.Test; -import junit.framework.TestSuite; -import mycompiler.MyCompiler; -// ino.end - -// ino.class.JUnitTests.26425.description type=javadoc -/** - * Erstellt eine JUnit-Testsuite, die saemtliche Testcases enthaelt und - * ausfuehrt. - * @author SCJU - * - */ -// ino.end -// ino.class.JUnitTests.26425.declaration -public class JUnitTests -// ino.end -// ino.class.JUnitTests.26425.body -{ - - - // ino.method.main.26428.defdescription type=line - // Aufruf ist auch als normale Anwendung moeglich. - // In Eclipse bietet sich allerdings eine Run-Config - // als JUnit-Test an! - // ino.end - // ino.method.main.26428.definition - public static void main(String[] args) - // ino.end - // ino.method.main.26428.body - { - junit.textui.TestRunner.run(JUnitTests.suite()); - } - // ino.end - - // ino.method.suite.26431.definition - public static Test suite() - // ino.end - // ino.method.suite.26431.body - { - TestSuite suite = new TestSuite("Teste Usecases for Compiler ..."); - //$JUnit-BEGIN$ - - - MyCompiler.getAPI().setOutputDir("Bytecode/"); - - - - // DER WICHTIGSTE - suite.addTest(new CompilerTestCase("examples/bajo1_usecases/Matrix.jav")); - - // Usecases PL - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseOne_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseTwo_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseThree_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseFour_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseFive_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseSix_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseSeven_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseEight_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseNine_pl.jav")); - suite.addTest(new CompilerTestCase("examples/pl_usecases/UsecaseTen_pl.jav")); - - - // Usecases HOTI - suite.addTest(new CompilerTestCase("examples/hoti/Constr.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Generic.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/GenericsTest.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/ImplClass.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Import.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Intf.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Multiclass.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Overl.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Simple.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Simple2.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Test.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Test2.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/Test3.jav")); - suite.addTest(new CompilerTestCase("examples/hoti/VererbProb.jav")); - - // Usecases SCJU - suite.addTest(new CompilerTestCase("examples/scju/ClassGenerics.jav")); - suite.addTest(new CompilerTestCase("examples/scju/FieldGenerics.jav")); - suite.addTest(new CompilerTestCase("examples/scju/MethodGenerics.jav")); - suite.addTest(new CompilerTestCase("examples/scju/ClassKonstanten.jav")); - suite.addTest(new CompilerTestCase("examples/scju/InterfaceTest.jav")); - suite.addTest(new CompilerTestCase("examples/scju/testPackage/Test.jav")); - //$JUnit-END$ - return suite; - } - // ino.end - -} -// ino.end diff --git a/src/typinferenz/assumptions/CopyOfTypeAssumptions.java b/src/typinferenz/assumptions/CopyOfTypeAssumptions.java deleted file mode 100644 index 53672cac8..000000000 --- a/src/typinferenz/assumptions/CopyOfTypeAssumptions.java +++ /dev/null @@ -1,303 +0,0 @@ -package typinferenz.assumptions; - -import java.util.Iterator; -import java.util.Vector; - -import sun.reflect.generics.reflectiveObjects.NotImplementedException; -import typinferenz.FunN; -import typinferenz.exceptions.TypinferenzException; -import mycompiler.mytype.GenericTypeVar; -import mycompiler.mytype.RefType; -import mycompiler.mytype.Type; -import mycompiler.mytype.TypePlaceholder; -import mycompiler.mytypereconstruction.set.CTypeAssumptionSet; -import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; - -/** - * Eine Sammlung von TypeAssumptions. - * Jede Expression und jedes Statement erhält beim Aufrufen ihrer TYPE-Methode ein AssumptionSet mit den Assumptions ihrer Umgebung als Parameter übergeben. - * @author janulrich - * - * Es gibt verschiedene Assumptions: - * 1. Methoden Assumptions - * 2. Konstruktor Assumptions - * 3. Lokale Variablen Assumptions - * 4. Feldvariablen Assumptions - * - */ -public class CopyOfTypeAssumptions implements Iterable { - - //private static CTypeAssumptionSet globalAssumptions = new CTypeAssumptionSet(); - private String thisClassName; - - //private Vector assumptions; - CTypeAssumptionSet assumptions = new CTypeAssumptionSet(); - - private Vector methodAssumptions = new Vector(); - - public CopyOfTypeAssumptions(){ - assumptions = new CTypeAssumptionSet(); - } - - /** - * Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this" - * @param klassenname - Wert für "this" - */ - public CopyOfTypeAssumptions(String klassenname){ - this(); - this.setThisClassname(klassenname); - } - - public CopyOfTypeAssumptions(CTypeAssumptionSet ass, String classname){ - assumptions = ass; - this.setThisClassname(classname); - } - - public CopyOfTypeAssumptions(CopyOfTypeAssumptions assumptions2) { - assumptions = new CTypeAssumptionSet(); - this.add(assumptions2); - } - - /** - * Im AssumptionSet muss je nach Umfeld der Wert von "this" neu gesetzt werden. - * Dies übernimmt diese Funktion. - * @param name - Der Klassenname der von this referenzierten Klasse. - */ - public void setThisClassname(String name){ - this.thisClassName = name; - } - - /** - * Erstellt eine CInstVarTypeAssumption und fügt sie den Assumptions hinzu. - * @param className - * @param identifier - * @param assumedType - */ - public void addInstVarAssumption(String className, String identifier, Type assumedType){ - this.add(createFieldVarAssumption(className, identifier, assumedType)); - } - - - /** - * Ruft createMethodAssumption auf und fügt die Assumption dem AssumptionSet hinzu - * @param classType - * @param identifier - * @param assumedType - * @param parameterTypes - */ - @Deprecated - public void addMethodAssumption_Backup(Type classType, String identifier, Type assumedType, Vector parameterTypes){ - CMethodTypeAssumption ass = createMethodAssumption(classType, identifier, assumedType, parameterTypes); - this.add(ass); - } - - public void addMethodAssumption(MethodAssumption mAss){ - this.methodAssumptions.add(mAss); - } - - /** - * - * @param className - * @param identifier - * @param assumedType - ReturnTyp der Methode - * @param parameterTypes - Liste der Parameter der Methode. TIPP: Zur Erstellung der CParaTypeAssumption-Liste kann die Methode TypeAssumptions.createCParaTypeAssumption verwendert werden. - */ - public static CMethodTypeAssumption createMethodAssumption_backup(Type classType, String identifier, Type assumedType, Vector parameterTypes){ - CMethodTypeAssumption ass = new CMethodTypeAssumption(classType, identifier, assumedType, parameterTypes.size(), 0, 0, null, null); - for(CParaTypeAssumption paraAssumption : parameterTypes){ - //Es wird eine neue ParameterAssumption generiert. Nur der Identifier und der AssumedType der CParaTypeAssumption wird dabei übernommen. - CParaTypeAssumption newParaAssumption = new CParaTypeAssumption(classType.get_Name(), identifier, parameterTypes.size(),0, paraAssumption.getIdentifier(), paraAssumption.getAssumedType(), 0,0,null); - ass.addParaAssumption(newParaAssumption); - } - return ass; - } - - public static CInstVarTypeAssumption createFieldVarAssumption_backup(String className, String fieldName, Type type){ - if(className==null || fieldName == null || type == null) throw new TypinferenzException("Ungültige Feld-Assumption"); - CInstVarTypeAssumption ret = new CInstVarTypeAssumption(className, fieldName, type, 0,0,null); - - return ret; - } - - /** - * Erstellt eine CParaTypeAssumption. - * Diese enthält nur den Identifier und den Typ des Parameters. Die Zuordnung zu einer Methode und einer Klasse erhält die Assumption erst durch den Einsatz in der TypeAssumptions.addMethodAssumption. - * @param identifier - * @param assumedType - * @return - */ - public static CParaTypeAssumption createCParaTypeAssumption_backup( String identifier, Type assumedType){ - CParaTypeAssumption ret; - ret = new CParaTypeAssumption( null, null, 0, 0, identifier, assumedType, 0,0, null); - return ret; - } - - public void addLocalVarAssumption(){ - throw new NotImplementedException(); - } - - - - /** - * Durchsucht die Assumptions des aktuellen Gültigkeitsbereichs (lokale Variablen und Felder der aktuellen Klasse) nach einem Eintrag für den übergebenen Variablennamen. - * In den Assumptions wird dann in der Reihenfolge LocalVarAssumptions, FieldAssumption nach dem übergebenen Variablennamen gesucht. - * @param variableName - der Identifier der gesuchten Variablen - * @return - Der Typ für diesen Identifier. - */ - public Type getVarType(String variableName){ - //Zuerst die Parameter durchsuchen - for(CTypeAssumption ass : this.assumptions){//this.getParameterAssumptions(null)){ - if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); - } - //TODO: Dann die lokalen Variablen - // ... (noch nicht implementiert) - - //und zuletzt die Felder der Klasse in dessen Namensraum sich dieses AssumptionSet befindet. - for(CTypeAssumption ass : this.getInstVarAssumptions()){ - if(ass.getIdentifier().equals(variableName))return ass.getAssumedType(); - } - //Wird keine Assumption gefunden, muss ein Fehler vorliegen: - throw new TypinferenzException("Eine Variable "+variableName+" ist in den Assumptions nicht vorhanden"); - } - - /** - * Ermittelt alle Assumptions zu Instanzvariablen, welche sich in der Klasse "this" befinden, also der Klasse für welche dieses AssumptionSet gültig ist. - * @return - */ - public CopyOfTypeAssumptions getInstVarAssumptions(){ - String className = this.getThisValue().getName(); - CopyOfTypeAssumptions ret = new CopyOfTypeAssumptions(); - for(CTypeAssumption ass : this.assumptions){ - if(ass instanceof CInstVarTypeAssumption && ass.getClassName().equals(className))ret.add(ass); - } - return ret; - } - - /** - * @return - Alle Assumptions dieses AssumptionSets, welche Annahmen für Parameter darstellen - */ - private CopyOfTypeAssumptions getParameterAssumptions(CMethodTypeAssumption method) { - CopyOfTypeAssumptions ret = new CopyOfTypeAssumptions(); - if(method==null)return ret; - for(CParaTypeAssumption ass : method.getParaAssumptions()){ - //if(ass instanceof CParaTypeAssumption)ret.add(ass); - ret.add(ass); - } - return ret; - } - - /** - * Sucht nach MethodAssumptions einer bestimmten Klasse mit einem bestimmten Namen. - * @param className - * @param methodName - * @param parameterCount - * @return - */ - public Vector getMethodAssumptions(String className, String methodName){ - Vector ret = new Vector(); - for(CTypeAssumption ass : this.getAssumptionsFor(className)){ - //System.out.println(ass.getIdentifier()); - if(ass.getIdentifier().equals(methodName) && ass instanceof CMethodTypeAssumption)ret.add((CMethodTypeAssumption)ass); - } - //if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden"); - return ret; - } - - /** - * Sucht nach Assumptions zu einer Methode mit dem Namen methodName und parameterCount Parametern. - * @param methodName - * @param parameterCount Anzahl der Parameter der gesuchten Methoden-Assumption - * @return - */ - public Vector getMethodAssumptions(String methodName, int parameterCount){ - Vector ret = new Vector(); - for(CTypeAssumption ass : assumptions){ - //System.out.println(ass.getIdentifier()); - if(ass.getIdentifier().equals(methodName) && ass instanceof CMethodTypeAssumption){ - CMethodTypeAssumption toAdd = (CMethodTypeAssumption)ass; - if(toAdd.getParaCount() == parameterCount)ret.add(toAdd); - } - } - //Falls es sich um die apply-Methode eines FunN-Interface handelt: - if(methodName.equals("apply")){ //Ein Workaround für den Typinferenzalgorithmus TODO: Das hier rausnehmen. - CMethodTypeAssumption funNAssumption = new FunN(parameterCount).toCMethodTypeAssumption(); - ret.add(funNAssumption); - } - if(ret.size()==0)throw new TypinferenzException("Eine Methode "+methodName+" ist in den Assumptions nicht vorhanden"); - return ret; - } - - - /** - * Fügt dem Assumption-Set eine neue Assumption hinzu. - * @param ass - * @return - */ - public CopyOfTypeAssumptions add(CTypeAssumption ass){ - if(ass.getAssumedType()==null)throw new NullPointerException();//ass.setAssumedType(TypePlaceholder.fresh()); - - //if(ass instanceof CParaTypeAssumption)throw new TypinferenzException("ParameterAssumptions müssen einer Methode zugewiesen sein"); - - //globalAssumptions.addElement(ass); - assumptions.addElement(ass); - return this; - } - - public void remove(CTypeAssumption typeAssumption){ - throw new NotImplementedException(); - } - - public CopyOfTypeAssumptions add(CopyOfTypeAssumptions assumptions){ - for(CTypeAssumption ass : assumptions){ - this.add(ass); - } - return this; - } - - public CopyOfTypeAssumptions add(CTypeAssumptionSet assumptionSet){ - assumptions.unite(assumptionSet); - return this; - } - - public Iterator iterator() { - return assumptions.iterator(); - } - - @Override - public CopyOfTypeAssumptions clone(){ - CTypeAssumptionSet assSet = new CTypeAssumptionSet(); - for(CTypeAssumption ass : assumptions){ - assSet.addElement(ass); - } - return new CopyOfTypeAssumptions(assSet, thisClassName); - } - - /** - * Jede erstellte Assumption wird von der TypeAssumptions-Klasse gespeichert. - * Diese Funktion ermittelt alle zu einer Klasse gehörenden Assumptions. - * @param classname - * @return Alle Assumptions mit - assumption.getClassname().equals(classname) - der this-Wert ist auf "classname" gesetzt. - */ - public CopyOfTypeAssumptions getAssumptionsFor(String classname){ - CTypeAssumptionSet assumptions = new CTypeAssumptionSet(); - //for(CTypeAssumption ass : globalAssumptions){ - for(CTypeAssumption ass : this.assumptions){ - if(ass.getClassName().equals(classname))assumptions.addElement(ass); - } - return new CopyOfTypeAssumptions(assumptions, classname); - } - - @Override - public String toString(){ - return assumptions.toString(); - } - - public Type getThisValue() { - return new RefType(thisClassName, 0); - } - -} diff --git a/test/mycompiler/test/AbstractInferenceTest.java b/test/mycompiler/test/AbstractInferenceTest.java deleted file mode 100755 index acba625c0..000000000 --- a/test/mycompiler/test/AbstractInferenceTest.java +++ /dev/null @@ -1,446 +0,0 @@ -package mycompiler.test; - -import java.io.File; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Vector; - -import junit.framework.TestCase; -import mycompiler.MyCompiler; -import mycompiler.MyCompilerAPI; -import mycompiler.mytype.BoundedGenericTypeVar; -import mycompiler.mytype.GenericTypeVar; -import mycompiler.mytype.RefType; -import mycompiler.mytype.Type; -import mycompiler.mytype.TypePlaceholder; -import mycompiler.mytypereconstruction.CIntersectionType; -import mycompiler.mytypereconstruction.CSubstitution; -import mycompiler.mytypereconstruction.TypeinferenceResultSet; -import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CLocalVarTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption; -import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption; -import mycompiler.mytypereconstruction.typeassumptionkey.CMethodKey; -import mycompiler.test.expectationTypes.BlockExpect; -import mycompiler.test.expectationTypes.ClassExpect; -import mycompiler.test.expectationTypes.Expectation; -import mycompiler.test.expectationTypes.GenericTypeVarExpect; -import mycompiler.test.expectationTypes.IExpectation; -import mycompiler.test.expectationTypes.IUnknownTypeExpect; -import mycompiler.test.expectationTypes.MethodExpect; -import mycompiler.test.expectationTypes.TypePlaceholderExpect; -import mycompiler.test.expectationTypes.VarExpect; - -import org.apache.log4j.Logger; - -/** Todo: - * - exception handling cannot verify correct exception yet - * - * done: - exception handling - * - commented asserts - * - log4j - * - cmethodkey usage - * - Typeplaceholder support - * @author - * last change: 26-05-08 - */ -public abstract class AbstractInferenceTest extends TestCase { - - private static Logger testlog = Logger.getLogger("funcTest"); - private File javFile=null; - private Expectation expectation=null; - private MyCompilerAPI compiler = MyCompiler.getAPI(); - - protected AbstractInferenceTest(String name, String javFilename) { - super(name); - - javFile = new File(javFilename); - - //retrieve Expectation object from specific Testcase for comparisons - this.expectation = getExpectations(); - } - - /** - * runs the JUnit-Test, calls all compiler steps - * @throws Throwable - */ - public void testSetup() throws Throwable { - //runs all compiler steps, any exception will cause the Test to fail, if not expected - - //enable Logging - Log4jWrapper.getInstance().configureLog4j(); - - try { - testlog.info("Parsing..."); - parseFile(); - testlog.info("Type reconstruction..."); - typeReconstruction(); - testlog.info("Code generation..."); - codeGeneration(); - //checks whether there is an expected exception that has not been thrown - AbstractInferenceTest.assertTrue("exception expected but not found",this.expectation.getExceptions().isEmpty()); - } catch (Exception e) { - testlog.info("Error during compiler step: " + e); - checkForExpectedException(e); - - } - } - - /** - * calls parse() from Compiler-API - * @throws Throwable - */ - - protected void parseFile() - throws Throwable - { - // Parse file - compiler.parse(javFile); - } - - /** - * calls typeReconstruction() from Compiler-API, checks result against expectations and substitutes all types according to first assumption - * @throws Exception - */ - - protected void typeReconstruction() - throws Exception - { - // Typ-Rekonstruktion - Vector resultSet = compiler.typeReconstruction(); - testlog.info("Type reconstruction completed..."); - // Keine Typ-Rekonstruktion erforderlich - if (resultSet == null || resultSet.size() == 0) throw new Exception("Type reconstruction could not be done!"); - - if (this.expectation!=null) { - if(this.expectation.getClasses()!=null) - checkResults(resultSet,this.expectation); - } - else - testlog.info("An Error has occurred receiving the expectations for this testcase: "+ this.javFile); - - TypeinferenceResultSet onePossibility = resultSet.firstElement(); - Iterator substIt = onePossibility.getSubstitutions().getIterator(); - while(substIt.hasNext()){ - CSubstitution subst = (CSubstitution)substIt.next(); - // Substition machen - subst.execute(); - } - } - - /** - * calls codeGeneration from Compiler-API - * @throws Exception - */ - - protected void codeGeneration() - throws Exception - { - // Code generieren - compiler.codeGeneration(); - } - - /** - * compares resultSet from compiler to expectations - * @param resultSet - * @param expect - */ - - protected void checkResults(Vector resultSet, Expectation expect) { - - //iterates thru all available assumption-sets - testlog.info("Starting checking for valid type assumptions..."); - for (int resIndex=0; resIndex < resultSet.size(); resIndex++) { - //checks whether all expected classes, methods, members are available - checkClasses(resultSet.get(resIndex),expect); - //-------------- - //Methods - //-------------- - //iterates through all found methods - for (CIntersectionType vecAssumpt : resultSet.get(resIndex).getMethodIntersectionTypes().values()) { - //for (int i=0; i iter2 = resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values().iterator(); - //while (iter2.hasNext()) { - //CTypeAssumption assumption = iter2.next(); - for (CTypeAssumption assumption : resultSet.get(resIndex).getFieldAndLocalVarAssumptions().values()) { - // local variable - if (assumption instanceof CLocalVarTypeAssumption) { - - CLocalVarTypeAssumption assu = (CLocalVarTypeAssumption)assumption; - if (expect.getClasses().containsKey(assu.getClassName())){ - //current method to compare assumption to: - MethodExpect method = expect.getClasses().get(assu.getClassName()).getMethods().get(new CMethodKey(assu.getClassName(),assu.getMethodName(),assu.getMethodParaCount(),assu.getMethodOverloadedID())); - testlog.debug("assumption: local variable '"+assu.getIdentifier()+"' of '"+assu.getClassName()+":"+assu.getMethodName()+"'"); - testlog.debug("searching in: '"+method.getName()+"'"); - AbstractInferenceTest.assertTrue("block variable '" + assu.getIdentifier() + "' in '" + assu.getMethodName()+ "' not valid or not found!",checkFoundVariable(assu, method.getBlock())); - } - - } - - // member variable - else if (assumption instanceof CInstVarTypeAssumption) { - - CInstVarTypeAssumption assu = (CInstVarTypeAssumption)assumption; - if (expect.getClasses().containsKey(assu.getClassName())){ - //current class to compare assumption to: - ClassExpect classexpect = expect.getClasses().get(assu.getClassName()); - testlog.debug("assumption: member variable '"+assu.getIdentifier()+"' of '"+assu.getClassName()+"'"); - testlog.debug("searching in: '"+classexpect.getName()+"'"); - checkFoundMembers(assu, classexpect.getMembers()); - } - } - } - } - - //verify that every single type assumption that was expected has been detected by the compiler - testlog.info("verifying all expectations have been met"); - AbstractInferenceTest.assertTrue("not all expected types have been found", expectation.verifyTypeExpectationsCompletelyMet()); - } - - /** - * @return returns a vector of class names of tested file - */ - protected abstract Expectation getExpectations(); - - - /** - * checks the return type of a method comparing it to the expectation - * @param assumpt - * @param expect - */ - protected void checkReturnType(Type assumpt, MethodExpect expect) { - if (!expect.getReturntypes().isEmpty()) { - AbstractInferenceTest.assertTrue("found return type " + assumpt.getName() + " is not in expected list", expect.getReturntypes().contains(assumpt)); - - checkBoundedTypes(assumpt,expect.getReturntypes().get(expect.getReturntypes().indexOf(assumpt))); - //remove this expectation to assure, all expectations have been met at least once - if (expect.getReturntypesCopy().contains(assumpt)) - expect.getReturntypesCopy().remove(assumpt); - } - else if ((assumpt instanceof GenericTypeVar || assumpt instanceof TypePlaceholder) && expect.getUnknownReturnType()!=null) { - //expect.addGeneric((GenericTypeVar) assumpt); - - checkUnknownTypes(assumpt, expect.getUnknownReturnType()); - } - else - AbstractInferenceTest.fail("no return type for " + assumpt.getName() +" has been defined in expectation"); - } - - /** - * checks for generic methods comparing them to the expectation - * @param assumpt - * @param expect - */ - protected void checkFoundGenerics(Vector assumpt, Vector expect) { - AbstractInferenceTest.assertTrue("amount of generic variables expected != assumed",((assumpt==null || assumpt.size()==0) && (expect==null || expect.size()==0)) || assumpt.size()==expect.size()); - for (GenericTypeVar typ : assumpt) { - //System.out.println("Generics: " + typ.get_Name() + ((BoundedGenericTypeVar)typ).getBounds() + ", " + expect.indexOf(typ)); - AbstractInferenceTest.assertTrue("Generic " + typ.getName() + " has not been expected",expect.contains(typ)); - - checkBoundedTypes(typ,expect.get(expect.indexOf(typ))); - } - } - - protected void checkBoundedTypes(Type assumed, Type expected) { - if (assumed instanceof BoundedGenericTypeVar) { - AbstractInferenceTest.assertTrue("assumed: BoundedGenericTypeVar, expected:' "+expected.getClass()+"'",expected instanceof BoundedGenericTypeVar); - BoundedGenericTypeVar typBound = (BoundedGenericTypeVar)assumed; - BoundedGenericTypeVar expBound = (BoundedGenericTypeVar)expected; - for (Type t : typBound.getBounds()) { - boolean ret = false; - for (Type e : expBound.getBounds()) { -//System.out.println(" here " + t + " -- " + e); - if (e.equals(t)) { - ret=true; - } - } - AbstractInferenceTest.assertTrue("Bounded generic's type is not equal", ret); - } - } - else if (assumed instanceof GenericTypeVar) { -// System.out.println("GENERICTYPEVAR"); - } - } - - protected void checkUnknownTypes(Type assumed, IUnknownTypeExpect expect) { - if (assumed instanceof GenericTypeVar) { - AbstractInferenceTest.assertTrue("Assumed type is of GenericTypeVar",expect instanceof GenericTypeVarExpect); - } - else if (assumed instanceof TypePlaceholder) { - AbstractInferenceTest.assertTrue("Assumed type is of TypePlaceholder",expect instanceof TypePlaceholderExpect); - } - - String mappedType=this.expectation.getMappings().getMappedType(expect.getName()); - if (mappedType!=null) { - AbstractInferenceTest.assertEquals("Same expected UnknownType mapped to different assumed types",mappedType,assumed.getName()); - } - else - this.expectation.getMappings().addMapping(expect.getName(), assumed.getName()); - } - - /** - * searches recursively for the matching block in the expectation set and compares found variables to the expectation - * @param assumpt - * @param expect - * @return - */ - - protected boolean checkFoundVariable(CLocalVarTypeAssumption assumpt, BlockExpect expect) { - //there is an expectation for a variable - AbstractInferenceTest.assertTrue(expect!=null); - boolean ret=false; - if (expect.getBlockID().equals(assumpt.getBlockId())) { - AbstractInferenceTest.assertTrue("Variable "+assumpt.getIdentifier() + " is not defined in expectation",expect.getLocalVar().containsKey(assumpt.getIdentifier())); - VarExpect varExpect = expect.getLocalVar().get(assumpt.getIdentifier()); - Vector expTypes = varExpect.getExpectedType(); - //check if a specific type for this variable is expected or whether it should be a typeplaceholder/generictypevar - if (!expTypes.isEmpty()) { - AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for variable " + assumpt.getIdentifier() + " is not found in expectations", expTypes.contains(assumpt.getAssumedType())); - checkBoundedTypes(assumpt.getAssumedType(), expTypes.get(expTypes.indexOf(assumpt.getAssumedType()))); - - //remove this expectation to assure, all expectations have been met at least once - expect.getLocalVar().get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); - } - else if ((assumpt.getAssumedType() instanceof GenericTypeVar || assumpt.getAssumedType() instanceof TypePlaceholder) && varExpect.getExpectedUnknownType()!=null) { - checkUnknownTypes(assumpt.getAssumedType(),varExpect.getExpectedUnknownType()); - } - else - AbstractInferenceTest.fail("no type for variable "+ assumpt.getIdentifier() + " has been defined"); - - return true; - } - else if (expect.getContainedBlocks()!=null){ - //dig one block deeper in hierarchy - for (BlockExpect exp : expect.getContainedBlocks()) - ret |= checkFoundVariable(assumpt,exp); - return ret; - } - return false; - } - /** - * checks method parameters comparing them to the expectation - * @param assumpt - * @param expect - */ - - protected void checkParameters(CMethodTypeAssumption methodAssumpt, MethodExpect methodExpect) { - Vector assumpt = methodAssumpt.getParaAssumptions(); - HashMap expect = methodExpect.getParameter(); - //amount of parameter - not needed anymore since methodkey contains amount of parameters already - //AbstractInferenceTest.assertEquals("amount of parameters not equal!", assumpt.size(),expect.size()); - - for (CParaTypeAssumption paraAssumpt : assumpt) { - //check if variable is expected - AbstractInferenceTest.assertTrue("variable " + paraAssumpt.getIdentifier() + " is not expected!", expect.containsKey(paraAssumpt.getIdentifier())); - Vector expectedTypes = expect.get(paraAssumpt.getIdentifier()).getExpectedType(); - //check if variable's type is expected - if (!expectedTypes.isEmpty()) { - AbstractInferenceTest.assertTrue("type " + paraAssumpt.getAssumedType() + " for variable " + paraAssumpt.getIdentifier() + " is not expected!", expectedTypes.contains(paraAssumpt.getAssumedType())); - AbstractInferenceTest.assertEquals("type " + paraAssumpt.getAssumedType() + " for variable " + paraAssumpt.getIdentifier() + " is not expected!", expectedTypes.get(expectedTypes.indexOf(paraAssumpt.getAssumedType())).getClass(),paraAssumpt.getAssumedType().getClass()); - checkBoundedTypes(paraAssumpt.getAssumedType(), expectedTypes.get(expectedTypes.indexOf(paraAssumpt.getAssumedType()))); - - //remove this expectation to assure, all expectations have been met at least once - expect.get(paraAssumpt.getIdentifier()).getExpectedTypeCopy().remove(paraAssumpt.getAssumedType()); - } - else if (paraAssumpt.getAssumedType() instanceof GenericTypeVar && expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType()!=null) { - //case of undefined type (generic variable), add generic to generic list - if (!methodExpect.getGenerics().contains((GenericTypeVar)paraAssumpt.getAssumedType())) - methodExpect.addGeneric((GenericTypeVar) paraAssumpt.getAssumedType()); - checkUnknownTypes(paraAssumpt.getAssumedType(),expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType() ); - } - else if (paraAssumpt.getAssumedType() instanceof TypePlaceholder && expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType()!=null) - checkUnknownTypes(paraAssumpt.getAssumedType(),expect.get(paraAssumpt.getIdentifier()).getExpectedUnknownType() ); - else - AbstractInferenceTest.fail("no type for " + paraAssumpt.getIdentifier() +" has been defined in expectation"); - } - } - - /** - * checks every class expected is included in compiler assumption + available generics - * @param assumption - * @param expectation - */ - protected void checkClasses(TypeinferenceResultSet assumption, Expectation expectation) { - - - for (String expect : expectation.getClasses().keySet()) { - //class exists - AbstractInferenceTest.assertTrue("class " + expect + " is not found in assumption!", assumption.getClassNameList().contains(expect)); - //generics - checkFoundGenerics(assumption.getGenerics(expect), expectation.getClasses().get(expect).getGenerics()); - } - } - - /** - * members found are compared to the expectation - * @param assumpt - * @param expect - */ - - protected void checkFoundMembers(CInstVarTypeAssumption assumpt, HashMap expect) { - AbstractInferenceTest.assertTrue("Member " + assumpt.getIdentifier() + " is not found in expectation!", expect.containsKey(assumpt.getIdentifier())); - AbstractInferenceTest.assertTrue("Type " + assumpt.getAssumedType() + " for member " + assumpt.getIdentifier() + " is not found in expectation",expect.get(assumpt.getIdentifier()).getExpectedType().contains(assumpt.getAssumedType())); - // - //remove this expectation to assure, all expectations have been met at least once - if (expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().contains(assumpt.getAssumedType())) - expect.get(assumpt.getIdentifier()).getExpectedTypeCopy().remove(assumpt.getAssumedType()); - } - - /** - * called to verify whether thrown exception from compiler calls is expected - * @param e - * @throws Throwable - */ - protected void checkForExpectedException (Exception e) throws Throwable { - if (!this.expectation.getExceptions().isEmpty()) { - //check if thrown exception has been expected - e.printStackTrace(); -// System.out.println(e.getClass()); - //AbstractInferenceTest2.assertTrue("Exception " + e.getMessage() + " is not same as expected", e.getClass().equals(this.expectation.getExceptions().firstElement())); - AbstractInferenceTest.assertTrue("Exception " + e.getMessage() + " is not expected", !this.expectation.getExceptions().isEmpty()); - } - else - throw e; - } - -// @Deprecated -// protected void checkForValidMethodTypes(CMethodTypeAssumption assumpt) {} -// protected void setUp() {} -// protected void tearDown() {} - - protected Vector createVectorAllNumberTypes() { - Vector ret = new Vector(); - ret.add(new RefType("java.lang.Integer",-1)); - ret.add(new RefType("java.lang.Long",-1)); - ret.add(new RefType("java.lang.Double",-1)); - ret.add(new RefType("java.lang.Float",-1)); -// ret.add(new RefType("java.lang.Short",-1)); -// ret.add(new RefType("java.lang.Byte",-1)); -// ret.add(new RefType("java.lang.Character",-1)); - - return ret; - } -}