Obsolete Klassen gelöscht. Alle Fehlermeldungen im src-Ordner behoben

This commit is contained in:
JanUlrich 2014-03-27 16:50:36 +01:00
parent 9784a10f84
commit c65774492e
12 changed files with 38 additions and 1397 deletions

View File

@ -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;

View File

@ -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: "

View File

@ -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);
}
}

View File

@ -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<Type> 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<Type> complete_paralist(boolean ext)
{
Diese Funktion vervollt<EFBFBD>ndigt die Parameterliste f<EFBFBD>r vererbte Klassen
Vector<Type> child = paralist;
paralist = (Vector<Type>)superclassid.get_ParaList();
for(Enumeration<Type> 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
*/

View File

@ -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<TypeinferenceResultSet> 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

View File

@ -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<TypeinferenceResultSet> 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<Integer> lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers();
String s = new String();
for(int l=0; l<lineNumbers.size(); l++){
s+=(lineNumbers.elementAt(l)+", ");
}
if(s.length()==0){
inferencelog.debug("Fr TypePlaceholder \""+subst.getTypeVar().getName()+"\" sind keine Liniennummern "+s+" registriert.");
}
else {
s = s.substring(0, s.length()-2);
inferencelog.debug("TypePlaceholder \""+subst.getTypeVar().getName()+"\" kommt im Quellcode in den Linien "+s+" vor.");
}*/
/////////////////////////
// Substitution durchf<EFBFBD>hren:
/////////////////////////
subst.execute();
}
inferencelog.debug("========FERTIG========");
//compiler.codeGeneration();
}catch(CTypeReconstructionException tre){
tre.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
}
// ino.end
}
// ino.end

View File

@ -1,90 +0,0 @@
// ino.module.CSimpleTest.8664.package
package mycompiler.mytest;
// ino.end
// ino.module.CSimpleTest.8664.import
import java.io.File;
import java.util.Iterator;
import java.util.Vector;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytypereconstruction.CSubstitution;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import org.apache.log4j.Logger;
// ino.end
// ino.class.CSimpleTest.26416.description type=javadoc
/**
* Testklasse f<EFBFBD>r die Compiler-API
* @author J<EFBFBD>rg B<EFBFBD>uerle
* @version $Date: 2006/06/13 10:37:32 $
*/
// ino.end
// ino.class.CSimpleTest.26416.declaration
public class CSimpleTest
// ino.end
// ino.class.CSimpleTest.26416.body
{
// ino.attribute.inferencelog.26419.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
// ino.method.main.26422.definition
public static void main(String[] args)
throws Exception
// ino.end
// ino.method.main.26422.body
{
MyCompilerAPI compiler = MyCompiler.getAPI();
try{
/////////////////////////
// Parsen:
/////////////////////////
compiler.parse(new File(args[0]));
//SourceFile tree = compiler.getSyntaxTree();
/////////////////////////
// Typrekonstruktion:
/////////////////////////
Vector<TypeinferenceResultSet> resultSet = compiler.typeReconstruction();
/////////////////////////
// Ausgabe:
/////////////////////////
TypeinferenceResultSet onePossibility = resultSet.firstElement();
Iterator substIt = onePossibility.getSubstitutions().getIterator();
while(substIt.hasNext()){
CSubstitution subst = (CSubstitution)substIt.next();
Vector<Integer> lineNumbers = ((TypePlaceholder)subst.getTypeVar()).getLineNumbers();
String s = new String();
for(int l=0; l<lineNumbers.size(); l++){
s+=(lineNumbers.elementAt(l)+", ");
}
if(s.length()==0){
inferencelog.debug("F<EFBFBD>r TypePlaceholders \""+subst.getTypeVar().getName()+"\" sind keine Liniennummern "+s+" registriert.");
}
else {
s = s.substring(0, s.length()-2);
inferencelog.debug("TypePlaceholders \""+subst.getTypeVar().getName()+"\" kommt im Quellcode in den Linien "+s+" vor.");
}
/////////////////////////
// Substitution durchf<EFBFBD>hren:
/////////////////////////
subst.execute();
}
/////////////////////////
// Code erzeugen:
/////////////////////////
//compiler.codeGeneration();
/////////////////////////
System.out.println("Fertig");
}catch(Exception e){
//System.out.println(e);
throw e;
}
}
// ino.end
}
// ino.end

View File

@ -1,92 +0,0 @@
package mycompiler.mytest;
import java.io.File;
import java.util.Vector;
import mycompiler.MyCompiler;
import mycompiler.MyCompilerAPI;
import mycompiler.SourceFile;
import mycompiler.mytype.*;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.mytypereconstruction.CSubstitution;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
import mycompiler.mytypereconstruction.unify.FC_TTO;
import mycompiler.mytypereconstruction.unify.Unify;
import org.apache.log4j.Logger;
/**
* Testklasse fr die Wildcard Algorithmus uns Parser
* @author Arne Lüdtke
*/
public class CWildcardTest
{
// protected static Logger inferencelog = Logger.getLogger("inference");
public static void main(String[] args)
throws Exception
{
MyCompilerAPI compiler = MyCompiler.getAPI();
try{
/////////////////////////
// Parsen:
/////////////////////////
compiler.parse(new File(args[0]));
MyCompiler.getAPI().setOutputDir("Bytecode/");
//compiler.semanticCheck();
/////////////////////////
// Typrekonstruktion:
/////////////////////////
//Vector<CTypeReconstructionResult> 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<Type> smallers = Unify.smaller(TA2,fc_tto);
//Vector<Type> greaters = Unify.greater(TA2,fc_tto);
MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA2);
MyCompiler.makeGenericTypeVars2TypePlaceHolders(TA1);
}
Vector<Vector<Pair>> unifyers = Unify.unify(((MyCompiler)compiler).testPair,fc_tto);
//Vector<Vector<Pair>> 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();
}
}
}

View File

@ -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<TypeinferenceResultSet> 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

View File

@ -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

View File

@ -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<CTypeAssumption> {
//private static CTypeAssumptionSet globalAssumptions = new CTypeAssumptionSet();
private String thisClassName;
//private Vector<CTypeAssumption> assumptions;
CTypeAssumptionSet assumptions = new CTypeAssumptionSet();
private Vector<MethodAssumption> methodAssumptions = new Vector<MethodAssumption>();
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<CParaTypeAssumption> 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<CParaTypeAssumption> 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<CMethodTypeAssumption> getMethodAssumptions(String className, String methodName){
Vector<CMethodTypeAssumption> ret = new Vector<CMethodTypeAssumption>();
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<CMethodTypeAssumption> getMethodAssumptions(String methodName, int parameterCount){
Vector<CMethodTypeAssumption> ret = new Vector<CMethodTypeAssumption>();
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<CTypeAssumption> 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);
}
}

View File

@ -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<TypeinferenceResultSet> 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<TypeinferenceResultSet> 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<vecAssumpt.size();i++) {
CMethodTypeAssumption assumpt = vecAssumpt.getMethodTypeAssumptions().get(0);
CMethodKey assumptKey = vecAssumpt.getIntersectionTypeKey();
//filter: own classes only
if (expect.getClasses().containsKey(assumpt.getClassName())){
//current method to compare assumption to:
testlog.debug("checking method of class "+ assumpt.getClassName());
MethodExpect method = expect.getClasses().get(assumpt.getClassName()).getMethods().get(assumptKey);
AbstractInferenceTest.assertTrue("no expectation has been defined for this method: '" + assumpt.getIdentifier() +"'", method!=null);
testlog.debug("comparing assumption to method "+method.getName());
//check parameter first, in case an undefined parameter type must be added to expected generics
checkParameters(assumpt,method);
testlog.debug("assumption return type: '"+assumpt.getAssumedType()+"'");
checkReturnType(assumpt.getAssumedType(), method);
testlog.debug("assumption generics: '"+assumpt.getGenericMethodParameters()+"'");
checkFoundGenerics(assumpt.getGenericMethodParameters(), method.getGenerics());
}
//}
}
//---------------------------
//Local and member variables:
//---------------------------
//Iterator<CTypeAssumption> 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<GenericTypeVar> assumpt, Vector<GenericTypeVar> 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<Type> 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<CParaTypeAssumption> assumpt = methodAssumpt.getParaAssumptions();
HashMap<String,VarExpect> 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<Type> 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<String,VarExpect> 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<Type> createVectorAllNumberTypes() {
Vector<Type> ret = new Vector<Type>();
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;
}
}