JavaPatternMatching/src/mycompiler/SourceFile.java

1567 lines
71 KiB
Java
Raw Normal View History

2013-10-18 11:33:46 +00:00
// ino.module.SourceFile.8722.package
package mycompiler;
// ino.end
// ino.module.SourceFile.8722.import
import java.util.Collection;
2013-10-18 11:33:46 +00:00
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Vector;
import mycompiler.mybytecode.ClassFile;
2013-10-18 11:33:46 +00:00
import mycompiler.myclass.BasicAssumptionClass;
import mycompiler.myclass.Class;
import mycompiler.myclass.ImportDeclarations;
import mycompiler.myclass.UsedId;
import mycompiler.myexception.CTypeReconstructionException;
import mycompiler.myexception.JVMCodeException;
import mycompiler.myexception.SCClassException;
import mycompiler.myexception.SCException;
import mycompiler.myinterface.Interface;
import mycompiler.mymodifier.Modifiers;
import mycompiler.mymodifier.Public;
import mycompiler.mytype.BooleanType;
import mycompiler.mytype.GenericTypeVar;
import mycompiler.mytype.Pair;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
import mycompiler.mytype.TypePlaceholder;
import mycompiler.mytype.Void;
import mycompiler.mytypereconstruction.CIntersectionType;
import mycompiler.mytypereconstruction.CSupportData;
import mycompiler.mytypereconstruction.TypeinferenceResultSet;
2013-10-18 11:33:46 +00:00
import mycompiler.mytypereconstruction.typeassumption.CInstVarTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CMethodTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CParaTypeAssumption;
import mycompiler.mytypereconstruction.typeassumption.CTypeAssumption;
import mycompiler.mytypereconstruction.unify.FC_TTO;
import mycompiler.mytypereconstruction.unify.Unify;
2013-10-18 11:33:46 +00:00
import org.apache.log4j.Logger;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
2014-02-11 01:47:39 +00:00
import typinferenz.ConstraintsSet;
import typinferenz.FunN;
import typinferenz.FunNInterface;
import typinferenz.FunNMethod;
2014-03-09 12:03:30 +00:00
import typinferenz.ResultSet;
2014-02-11 01:47:39 +00:00
import typinferenz.UndConstraint;
import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.TypeAssumptions;
2014-03-18 19:18:57 +00:00
import typinferenz.exceptions.TypinferenzException;
2013-10-18 11:33:46 +00:00
// ino.class.SourceFile.21355.declaration
public class SourceFile
2014-02-12 01:12:12 +00:00
extends SyntaxTreeNode
2013-10-18 11:33:46 +00:00
// ino.end
// ino.class.SourceFile.21355.body
{
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.decldescription type=javadoc
/**
* @autor HOTI
* Dieses Flag bestimmt, ob die basicAssumptions (Integer, Vector, ...) direkt von
* der Java-Laufzeitumgebung anhand der Imports oder von den "Fixed Hacks" geladen
* werden (Mit Fixed Hacks sind die von Hand eingetragene Basetypes gemeint)
*/
// ino.end
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.declaration
private static final boolean LOAD_BASIC_ASSUMPTIONS_FROM_JRE = true;
// ino.end
// ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.decldescription type=javadoc
/**
* @autor HOTI
* Wenn dieses Flag auf <b>true</b> gesetzt ist, wird immer als Superklasse Object
* mit rein geladen. Dies hat nat<EFBFBD>rlich zur Folge, dass man in der GUI jeden Typ
* ausw<EFBFBD>hlen muss, weil ALLES in Java von Object erbt. Sobald die GUI das <EFBFBD>ber eine
* Checkbox o.<EFBFBD>. ausblendbar macht kann es aktiviert werden. Ebenso beeinflusst es
* die superclass von allen Class-Objekten. (Wenn true ist jede Class automatisch
* wenn nicht anders eingegeben Subclass von Object (Wie es sein muss))
*/
// ino.end
// ino.attribute.READ_OBJECT_SUPERCLASSES_FROM_JRE.21361.declaration
public static final boolean READ_OBJECT_SUPERCLASSES_FROM_JRE = false;
// ino.end
// ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.decldescription type=javadoc
/**
* Wenn dieses Flag auf <b>false</b> ist, werden f<EFBFBD>r alle Basisklassen (definiert
* durch die Hashtable baseTypeTranslationTable) KEINE Superklassen geladen. D.h.
* Integer hat bspw. nicht die Superklasse Number sondern OBJECT.
* Dies verursacht bei den Int-Operationen ein Problem
* (+,-,*,/,<,>,...)
*/
// ino.end
// ino.attribute.READ_BASE_TYPE_SUPERCLASSES_FROM_JRE.21364.declaration
private static final boolean READ_BASE_TYPE_SUPERCLASSES_FROM_JRE = false;
// ino.end
/**
* @autor PL
* Wenn dieses Flag auf <b>false</b> ist, werden f<EFBFBD>r alle importierten Klassen
* KEINE Superklassen geladen.
*/
private static final boolean READ_IMPORTED_SUPERCLASSES_FROM_JRE = false;
// ino.attribute.codegenlog.21367.decldescription type=line
// Logger fuer Code-Gen
// ino.end
// ino.attribute.codegenlog.21367.declaration
protected static Logger codegenlog = Logger.getLogger("codegen");
// ino.end
// ino.attribute.inferencelog.21370.declaration
protected static Logger inferencelog = Logger.getLogger("inference");
// ino.end
// ino.attribute.pkgName.21373.declaration
private UsedId pkgName;
// ino.end
// ino.attribute.KlassenVektor.21376.declaration
public Vector<Class> KlassenVektor = new Vector<Class>();
// ino.end
// ino.attribute.InterfaceVektor.21379.declaration
public Vector<Interface> InterfaceVektor = new Vector<Interface>();
// ino.end
2013-10-18 11:33:46 +00:00
/**
* Die SourceFile repr<EFBFBD>sntiert eine zu einem Syntaxbaum eingelesene Java-Datei.
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar.
2013-10-18 11:33:46 +00:00
*/
public SourceFile(){
// HOTI 4.5.06
2013-10-18 11:33:46 +00:00
// Base-Type-Translations anlegen (siehe kommentar BaseTypeTranslationTable)
baseTypeTranslationTable=new Hashtable<String,String>();
baseTypeTranslationTable.put("int","java.lang.Integer");
baseTypeTranslationTable.put("char","java.lang.Character");
baseTypeTranslationTable.put("boolean","java.lang.Boolean");
baseTypeTranslationTable.put("double","java.lang.Double");
baseTypeTranslationTable.put("long","java.lang.Long");
baseTypeTranslationTable.put("float","java.lang.Float");
//baseTypeTranslationTable.put("this.is.a.temporary.entry","java.util.Vector"); auskommentiert PL 07-08-11
this.imports=new ImportDeclarations();
this.imports.add(UsedId.createFromQualifiedName("java.lang.Integer",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.String",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.Character",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.Boolean",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.Double",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.Float",-1));
this.imports.add(UsedId.createFromQualifiedName("java.lang.Long",-1));
//this.imports.add(UsedId.createFromQualifiedName("java.lang.Byte"));
// HOTI 4.5.06 Wenn die Klassen immer als "Daddy" Object haben,
// muss das der JCC auch kennen
if(READ_OBJECT_SUPERCLASSES_FROM_JRE){
this.imports.add(UsedId.createFromQualifiedName("java.lang.Object",-1));
}
}
// ino.attribute.imports.21382.decldescription type=javadoc
/**
* HOTI 4.5.06
* Beinhaltet alle Imports des aktuell geparsten Files
* in Form einer UsedId
*/
// ino.end
// ino.attribute.imports.21382.declaration
private ImportDeclarations imports=new ImportDeclarations();
// ino.end
// ino.attribute.baseTypeTranslationTable.21385.decldescription type=javadoc
/**
* Table zum <EFBFBD>bersetzen der nicht implementierten Base-Types:
* <EFBFBD>berall im Compiler wird statt bspw. int Integer verwendet
* d.h. 1+2 liefert ein Integer
* Deshalb ben<EFBFBD>tigen wir hier eine Tabelle, mit der man die von
* der JRE gelieferten Base-Typen (int,char, etc) und die Objekt-
* Typen umwandeln k<EFBFBD>nnen
*/
// ino.end
// ino.attribute.baseTypeTranslationTable.21385.declaration
private Hashtable<String,String> baseTypeTranslationTable;
2013-10-18 11:33:46 +00:00
// ino.end
2013-10-18 11:33:46 +00:00
// ino.method.addElement.21394.defdescription type=javadoc
/**
* Fuegt ein neues Element (Interface oder Klasse) hinzu.
* @param c
*/
// ino.end
// ino.method.addElement.21394.definition
public void addElement(AClassOrInterface e)
// ino.end
// ino.method.addElement.21394.body
{
if (e instanceof Class) {
KlassenVektor.addElement((Class) e);
} else if (e instanceof Interface) {
InterfaceVektor.addElement((Interface) e);
}
}
// ino.end
// ino.method.codegen.21397.defdescription type=javadoc
/**
* Startet die Bytecodegenerierung fuer alle in der Datei
* enthaltenen Klassen und Interfaces.
*
*/
// ino.end
// ino.method.codegen.21397.definition
public Vector<ClassFile> codegen(ResultSet result)
2013-10-18 11:33:46 +00:00
throws JVMCodeException
// ino.end
// ino.method.codegen.21397.body
{
Vector<ClassFile> ret = new Vector<ClassFile>();
2013-10-18 11:33:46 +00:00
codegenlog.info("Anzahl der Interfaces: "
+ Integer.toString(InterfaceVektor.size()));
for(int i = 0; i < InterfaceVektor.size(); i++) {
InterfaceVektor.elementAt(i).codegen(result);
2013-10-18 11:33:46 +00:00
}
codegenlog.info("Anzahl der Klassen: "
+ Integer.toString(KlassenVektor.size()));
for(int i = 0; i < KlassenVektor.size(); i++) {
ret.add(KlassenVektor.elementAt(i).codegen(result));
2013-10-18 11:33:46 +00:00
}
return ret;
2013-10-18 11:33:46 +00:00
}
// ino.end
// ino.method.createPairFromClassAndSuperclass.21400.defdescription type=javadoc
/**
* Erstellt ein Typ-Paar, welches im 1. Durchlauf in die Menge der Finite Closure
* aufgenommen wird Input: Klassenname, Name der Superklasse, ParameterDerKlasse,
* Parameter der Superklasse
* @return
*/
// ino.end
// ino.method.createPairFromClassAndSuperclass.21400.definition
private Pair createPairFromClassAndSuperclass(String className, String superclassName, Vector classParaOrg, Vector superclassParaOrg)
// ino.end
// ino.method.createPairFromClassAndSuperclass.21400.body
{
// Paar erstellen
if(classParaOrg!=null && classParaOrg.size()==0){
classParaOrg=null;
}
if(superclassParaOrg!=null && superclassParaOrg.size()==0){
superclassParaOrg=null;
}
Pair P = new Pair(
new RefType( className, classParaOrg,-1),
new RefType( superclassName, superclassParaOrg,-1)
);
//PL 04-12-29 freshe Variablen ANFANG
RefType r1 = (RefType)P.getTA1Copy();
RefType r2 = (RefType)P.getTA2Copy();
// #JB# 05.04.2005
// ###########################################################
Hashtable<String,Type> substHash = new Hashtable<String,Type>(); //fuer jedes Paar komplett neue Variablen
Unify.varSubst(r1, substHash);
Unify.varSubst(r2, substHash);
// ###########################################################
P = new Pair(r1, r2);
//PL 04-12-29 freshe Variablen ENDE
//HIER AUSKOMMENTIERT, SOLLTE MAN AM ENDE WIEDER DAZU NEHMEN PL 04-12-28
// gleiches Paar aufnehmen
//vFC.add( new Pair( P.getTA1Copy(), P.getTA1Copy() ) );
return(P);
}
// ino.end
// ino.method.makeFC.21403.defdescription type=javadoc
/**
* Erstellt die Finite Closure
* @return FC_TTO-Object, welches die Finite Closure repr<EFBFBD>sentiert
*/
// ino.end
// ino.method.makeFC.21403.definition
public FC_TTO makeFC( )
// ino.end
// ino.method.makeFC.21403.body
{
// Menge FC bilden
Vector<Pair> vFC = new Vector<Pair>(); // Menge FC
// 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen
for( int i = 0; i < KlassenVektor.size(); i++ )
{
Class tempKlasse = KlassenVektor.elementAt(i);
inferencelog.debug("Verarbeite "+tempKlasse.getName());
if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse
Pair P=createPairFromClassAndSuperclass(tempKlasse.getName(),tempKlasse.get_Superclass_Name(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList());
vFC.add( P );
}
if(tempKlasse.getSuperInterfaces()!=null){
Iterator<UsedId> interfaceIterator=tempKlasse.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){
UsedId intf=interfaceIterator.next();
String interfaceName=intf.getQualifiedName();
Pair P=createPairFromClassAndSuperclass(tempKlasse.getName(),interfaceName,tempKlasse.get_ParaList(),intf.get_ParaList());
vFC.add( P );
}
}
} // Schleifenende durch Klassenvektor
for(int i=0; i<InterfaceVektor.size();i++){
Interface intf= InterfaceVektor.get(i);
if(intf.getSuperInterfaces()!=null){
Iterator<UsedId> interfaceIterator=intf.getSuperInterfaces().iterator();
while(interfaceIterator.hasNext()){
UsedId superintf=interfaceIterator.next();
String superinterfaceName=superintf.getQualifiedName();
2014-03-27 15:51:57 +00:00
Pair P=createPairFromClassAndSuperclass(intf.getName(),superinterfaceName,intf.getParaList(), superintf.get_ParaList());
2013-10-18 11:33:46 +00:00
vFC.add( P );
}
}
}
Vector tto = (Vector)vFC.clone();
Unify.printMenge( "FC", vFC, 6 );
/* z.B.
*******************************
Menge FC = {
(Vektor< A >, Vektor< A >),
(Vektor< A >, AbstractList< A >),
(Matrix< A >, Matrix< A >),
(Matrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, ExMatrix< A >),
(ExMatrix< A >, Matrix< A >) }
*******************************
ODER
*******************************
Menge FC = {
(BB< A >, BB< A >),
(BB< A >, CC< A >),
(AA< A, B >, AA< A, B >),
(AA< A, B >, BB< DD< B, A > >) }
*******************************
*/
// 2. Regel 2 der Huellendefinition "eingeschraenkt" anwenden
// d.h. sinnvolle Substitutionen suchen (nicht alle)
boolean bPaarHinzu = true;
while( bPaarHinzu )
{
bPaarHinzu = false; //PL 04-12-29 nur wenn hinzugefuegt auf true setzen
// konkret: rechte Seite von FC nach Typkonstruktoren in der Parameterliste durchsuchen
for( int n = 0; n < vFC.size(); n++ )
{
// Elemente in FC k<>nnen nur Pair's sein --> Cast ohne Abfrage
Pair PTypKonst = vFC.elementAt(n);
// Parameter des rechten Typausdrucks des betrachteten Paars extrahieren
Vector<Type> vPara = ((RefType)(PTypKonst.TA2)).get_ParaList();
RefType Subst = null; // Substitution
int nSubstStelle = 0;
inferencelog.debug("nSubstStelleStart" + nSubstStelle + " " + n);
// Parameter durchlaufen und nach Typkonstruktor suchen
// #JB# 17.05.2005
// ###########################################################
if(vPara!=null){
// ###########################################################
for( ; nSubstStelle < vPara.size(); nSubstStelle++ )
{
inferencelog.debug("nSubstStelle" + nSubstStelle);
if( vPara.elementAt(nSubstStelle) instanceof RefType && ((RefType)vPara.elementAt(nSubstStelle)).get_ParaList() != null )
{
// Typkonstruktor gefunden -> wird nun als Substitution verwendet
Subst = new RefType( (RefType)vPara.elementAt(nSubstStelle) ,-1);
inferencelog.debug( "Ausgangstyp:" + ((RefType)PTypKonst.TA2).getName() );
inferencelog.debug( "RefType = " + ((RefType)vPara.elementAt(nSubstStelle)).getName() );
break; // Einschraenkung - nur fuer ein RefType wird eine Substitution gesucht
}
}
// ###########################################################
}
// ###########################################################
if( Subst != null )
{
// Rechter Typ hat einen Typkonstruktor --> sinvolles neues Paar bilden
// d.h. Rechter Typ auf linker Paarseite suchen
// System.out.println("Subststelle = " + nSubstStelle );
for( int t = 0; t < vFC.size(); t++ )
{
Pair PSuchen = vFC.elementAt(t);
if( ((RefType)(PTypKonst.TA2)).getTypeName().equals( ((RefType)PSuchen.TA1).getTypeName() ) )
{
inferencelog.debug(" gefundener Typ links: " + ((RefType)(PSuchen.TA1)).getName() );
inferencelog.debug(" gefundener Typ rechts: " + ((RefType)(PSuchen.TA2)).getName() );
// Paar gefunden, das als linken Typ den gleichen Typen enth<74>lt, der als Parameter einen Typkonstruktor hat
// Substitution
//Pair P = new Pair( PSuchen.getTA1Copy( ), PSuchen.getTA2Copy( ) );
//linker Typterm bleibt gleich
//rechter Typterm wird aussen auf den Supertyp gesetzt.
//restliches FC erfolgt ueber die Transitivitaet
//siehe im unteren Teil
Pair P = new Pair( PTypKonst.getTA1Copy( ), PSuchen.getTA2Copy( ) );
// System.out.println(" Subst " + Subst.getName() );
// System.out.println(" Vor: P = " + P.toString() + P.TA1 );
// System.out.println(" Vor: PSuchen = " + PSuchen.toString() + PSuchen.TA1 );
// Parameter, der substituiert wird, sollte TV sein ???
//TypePlaceholder TV = null;
// if( ((RefType)P.TA1).isTV( nSubstStelle ) )
// try
// {
// TV = new TypePlaceholder( ((RefType)P.TA1).getParaN( nSubstStelle ) );
// }
// catch( Exception E )
// {
// continue;
// }
// else
// continue;
//es werden alle Parameter in einem Typeterm, der
//der Argumente hat ersetzt PL 04-12-28
Hashtable<String,Type> hts = new Hashtable<String,Type>();
//for(int u = nSubstStelle; u < vPara.size(); u++) {
for(int u = 0; u < vPara.size(); u++) {
try {
// #JB# 05.04.2005
// ###########################################################
//TV = new TypePlaceholder( ((RefType)PSuchen.TA1).getParaN(u) );
//System.out.println("TV_Name: " + u + TV.Type2String());
// ###########################################################
inferencelog.debug("Typterm_Name: " + vPara.elementAt(u));
inferencelog.debug("Typterm_Name: " + ((Type)vPara.elementAt(u)).Type2String());
hts.put(((RefType)PSuchen.TA1).getParaN(u), vPara.elementAt(u));
}
catch( Exception E ) {
inferencelog.error(E.getMessage());
//FIXME Throw Exception or Error instead of exiting!
System.exit(0);
}
// Subst( P,
// 2,
// TV,
// new RefType( (RefType)vPara.elementAt(u) ),
// false ); // rechte Seite substituieren
//Es genuegt die rechte Seite zu substituieren, da
//die linke Seite ein Typterm ausschlie<69>lich mit
//Typvariablen ist
}
//Unify.SubstHashtableGeneric(((RefType)P.TA1), hts); //funktioniert nicht
Unify.SubstHashtableGeneric(((RefType)P.TA2), hts); //funktioniert nicht
// System.out.println(" TV!!!= " + TV.getName() );
//Subst( P, 1, TV, Subst, false ); // linke Seite substituieren
//Subst( P, 2, TV, Subst, false ); // rechte Seite substituieren
// System.out.println(" nach Subst: P = " + P.toString() );
// System.out.println(" Nach: PSuchen = " + PSuchen.toString() );
// System.out.println(" Nach: " + P.toString() );
// Paar einfuegen, falls noch nicht vorhanden
// System.out.println("Paar alt:" + PSuchen.toString() );
// System.out.println("Paar neu:" + P.toString() );
if( !P.isInVector( vFC ) )
{
vFC.add( P );
Unify.printMenge( "FC", vFC, 6 );
bPaarHinzu = true;
}
//PL 04-12-29
// else //unnoetig, da am Anfang bereits false gesetzt
// {
// bPaarHinzu = false;
// }
}
}
} // end if: Substitution gefunden???
} // end for: Typkonstruktor suchen
// Transitivitaet berechnen
for( int u = 0; u < vFC.size(); u++ )
{
Pair PTemp = vFC.elementAt(u);
// falls rechtes Paar = RefType
if( PTemp.TA2 instanceof RefType )
{
RefType R = (RefType)PTemp.TA2;
// rechte Seite auf linker Seite suchen
for( int e = 0; e < vFC.size(); e++ )
{
Pair PSuch = vFC.elementAt(e);
// als linke Paarseite theortisch nur RefType's moeglich --> Cast
RefType RSuch = (RefType)PSuch.TA1;
//if( R.getName().equals(RSuch.getName()) )
if (R.is_Equiv(RSuch, new Hashtable<String,Type>())) //eingefuegt PL 05-01-07
{
// Paar einfuegen, falls noch nicht vorhanden
RefType L1 = (RefType)PTemp.getTA1Copy();
RefType L2 = (RefType)PTemp.getTA2Copy();
RefType R1 = (RefType)PSuch.getTA1Copy();
RefType R2 = (RefType)PSuch.getTA2Copy();
//zunaechst Variablen disjunkt machen ANFANG
// #JB# 05.04.2005
// ###########################################################
Hashtable<String,Type> substHash1 = new Hashtable<String,Type>();
Unify.varSubst(L1, substHash1);
Unify.varSubst(L2, substHash1);
Hashtable<String,Type> substHash2 = new Hashtable<String,Type>();
Unify.varSubst(R1, substHash2);
Unify.varSubst(R2, substHash2);
// ###########################################################
//zunaechst Variablen disjunkt machen ENDE
//Variablen so umbennen, dass transitiver Abschluss richtige
//Namen hat ANFANG
// #JB# 05.04.2005
// ###########################################################
Hashtable<String,Type> h = new Hashtable<String,Type>();
L2.Equiv2Equal(R1, h);
Hashtable<String,Type> substHash3 = h;
Unify.varSubst(L1, substHash3);
Unify.varSubst(R2, substHash3);
// ###########################################################
//Variablen so umbennen, dass transitiver Abschluss richitge
//Namen hat ENDE
//Pair P = new Pair( (RefType)PTemp.TA1, (RefType)PSuch.TA2 );
Pair P = new Pair(L1, R2);
if( !P.isInVector( vFC ) )
{
vFC.add( P );
bPaarHinzu = true;
}
else
{
bPaarHinzu = false;
}
}
} // end for: linke Seite suchen
} // end if: Element ist RefType
} // end for: Transitivit<69>ten berechnen
//PL HIER REFLEXIVE HUELLE EINFUEGEN
// 05-01-07
} // Ende WHILE
/* z.B.
*******************************
Menge nach trans: FC = {
(Vektor< A >, Vektor< A >),
(Vektor< A >, AbstractList< A >),
(Matrix< A >, Matrix< A >),
(Matrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, ExMatrix< A >),
(ExMatrix< A >, Matrix< A >),
(Vektor< Vektor< A > >, Vektor< Vektor< A > >),
(Vektor< Vektor< A > >, AbstractList< Vektor< A > >),
(Matrix< A >, AbstractList< Vektor< A > >),
(ExMatrix< A >, Vektor< Vektor< A > >),
(ExMatrix< A >, AbstractList< Vektor< A > >) }
ODER
*******************************
Menge nach trans: FC = {
(BB< A >, BB< A >),
(BB< A >, CC< A >),
(AA< A, B >, AA< A, B >),
(AA< A, B >, BB< DD< B, A > >),
(BB< DD< B, A > >, BB< DD< B, A > >),
(BB< DD< B, A > >, CC< DD< B, A > >),
(AA< A, B >, CC< DD< B, A > >) }
*******************************
******************************* */
// printMenge( "nach trans: FC", vFC, 6 );
FC_TTO fctto = new FC_TTO(vFC, tto,KlassenVektor);
return fctto;
}
// ino.end
2014-02-11 01:47:39 +00:00
public TypeAssumptions getPublicFieldAssumptions(){
TypeAssumptions publicAssumptions = new TypeAssumptions(null);
2014-02-11 01:47:39 +00:00
//Alle PublicAssumptions der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
publicAssumptions.add(klasse.getPublicFieldAssumptions());
}
return publicAssumptions;
}
2013-10-18 11:33:46 +00:00
/////////////////////////////////////////////////////////////////////////
// TypeReconstructionAlgorithmus
/////////////////////////////////////////////////////////////////////////
// ino.method.typeReconstruction.21406.defdescription type=javadoc
/**
* Tyrekonstruktionsalgorithmus: ruft f<EFBFBD>r jede Klasse den Algorithmus TRProg auf.
* Dessen Ergebnismenge A, die Menge aller Typannahmen, f<EFBFBD>r eine Klasse dient als
* Eingabe f<EFBFBD>r TRProg der n<EFBFBD>chsten Klasse. Am Ende enth<EFBFBD>lt A alle m<EFBFBD>glichen
* Typkombinationen f<EFBFBD>r alle Klassen zusammen.
* <br>Author: J<EFBFBD>rg B<EFBFBD>uerle
* @return Liste aller m<EFBFBD>glichen Typkombinationen
* @throws CTypeReconstructionException Wenn was schief l<EFBFBD>uft
*/
// ino.end
// ino.method.typeReconstruction.21406.definition
2014-02-11 01:47:39 +00:00
public Vector<TypeinferenceResultSet> typeReconstruction(TypeAssumptions globalAssumptions)
2013-10-18 11:33:46 +00:00
throws CTypeReconstructionException
// ino.end
// ino.method.typeReconstruction.21406.body
{
2014-02-11 01:47:39 +00:00
Vector<TypeinferenceResultSet> ret = new Vector<TypeinferenceResultSet>();
//Logger initialisieren:
Logger typinferenzLog = Logger.getLogger("Typeinference");
//FiniteClosure generieren:
FC_TTO finiteClosure = this.makeFC();
//Alle Assumptions f<>r diese SourceFile sammeln:
for(Class klasse : this.KlassenVektor){
globalAssumptions.add(klasse.getPublicFieldAssumptions());
}
ConstraintsSet oderConstraints = new ConstraintsSet();
2014-02-11 01:47:39 +00:00
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
oderConstraints.add(klasse.typeReconstruction(finiteClosure, globalAssumptions));
}
////////////////
//Karthesisches Produkt bilden:
////////////////
//Die Constraints in Pair's umwandeln (Karthesisches Produkt bilden):
Vector<Vector<Pair>> xConstraints = new Vector<Vector<Pair>>();// = oderConstraints.getConstraints();
for(Vector<UndConstraint> uC:oderConstraints.getConstraints()){ //mit dem getConstraints-Aufruf wird das Karthesische Produkt erzeugt.
Vector<Pair> cons = new Vector<Pair>();
for(UndConstraint undCons:uC){
cons.addAll(undCons.getConstraintPairs());
}
xConstraints.add(cons);
}
typinferenzLog.debug("Karthesisches Produkt der Constraints: "+xConstraints);
//////////////////////////////
// Unifizierung der Constraints:
//////////////////////////////
for(Vector<Pair> constraints : xConstraints){
//Alle durch das Karthesische Produkt entstandenen M<>glichkeiten durchgehen:
Vector<Vector<Pair>> result = new Vector<Vector<Pair>>();
2014-02-11 01:47:39 +00:00
//Alle FunN-Typen werden per clone-methode in RefTypes verwandelt. (Die clone Methode in FunN darf nicht <20>berschrieben werden.
for(Pair p : constraints){
if(p.TA1 instanceof FunN){
p.TA1 = p.TA1.clone();
}
if(p.TA2 instanceof FunN){
p.TA2 = p.TA2.clone();
}
2014-02-11 01:47:39 +00:00
}
//Erst die Unifizierung erstellen:
Vector<Pair> constraintsClone = (Vector<Pair>)constraints.clone();
Vector<Vector<Pair>> unifyResult = Unify.unify(constraintsClone, finiteClosure);
//Dann den Ergebnissen anf<6E>gen
result.addAll(unifyResult);
// Debugoutput:Vector<Vector<Pair>>
typinferenzLog.debug("Unifiziertes Ergebnis: "+result);
/*
// Pr<50>fe ob eindeutige L<>sung:
if(result.size()>1 && !Unify.hasSolvedForm(result.elementAt(0))){
typinferenzLog.debug("Keine eindeutige L<>sung!");
}else if(result.size()>1){
//Replace TPH:
for(Pair res : result.elementAt(0)){
if(res.OperatorEqual()){
if(res.TA1 instanceof TypePlaceholder)((TypePlaceholder)res.TA1).fireReplaceTypeEvent(new CReplaceTypeEvent(res.TA1, res.TA2));
}
}
}
*/
//typinferenzLog.debug();
//typinferenzLog.debug(supportData.getFiniteClosure());
//typinferenzLog.debug("Typinformationen: \n"+this.getTypeInformation(this.getMethodList(), fieldInitializers));
typinferenzLog.debug("\nJavaFiles:\n");
//typinferenzLog.debug(this.printJavaCode(new ResultSet(new Vector<Pair>())));
//F<>r jede Klasse in diesem SourceFile gilt das selbe ResultSet:
for(Class klasse : this.KlassenVektor){
//Der Unifikationsalgorithmus kann wiederum auch mehrere L<>sungen errechnen, diese werden im folgenden durchlaufen:
for(Vector<Pair> resultSet : result){
//Add Result set as a new ReconstructionResult to ret:
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet(klasse, constraints, new ResultSet(resultSet));
ret.add(reconstructionResult);
//ResultSet res = new ResultSet(resultSet);
typinferenzLog.debug("JavaFile f<>r ResultSet "+reconstructionResult+"\n");
typinferenzLog.debug(klasse.printJavaCode(reconstructionResult));
}
}
2014-02-11 01:47:39 +00:00
}
2013-10-18 11:33:46 +00:00
2014-02-11 01:47:39 +00:00
return ret;
/*
2013-10-18 11:33:46 +00:00
// HOTI: Nur zur Info.Ich habe den Loglevel auf Info geschaltet, damit
// in der GUI (Eclipse-Plugin) die Console nicht zugemüllt wird.
// Wers braucht kanns natürlich ausschalten
// inferencelog.setLevel(Level.INFO);
Vector<TypeinferenceResultSet> A = new Vector<TypeinferenceResultSet>();
2013-10-18 11:33:46 +00:00
TypeAssumptions basics;
2013-10-18 11:33:46 +00:00
2014-03-18 19:18:57 +00:00
basics = this.makeBasicAssumptions();
2013-10-18 11:33:46 +00:00
//A.addElement(basics); //auskommentiert von Andreas Stadelmeier
// PL 05-07-31 alle GenericTypeVars werden ueberprueft, ob sie nicht
// deklarierte Classen sind und dann ggfs. gewandelt.
for (int i = 0; i < this.KlassenVektor.size(); i++) {
Class tempKlasse = this.KlassenVektor.elementAt(i);
MyCompiler.wandleGeneric2RefType(tempKlasse.getContainedTypes(),
this.KlassenVektor);
if(tempKlasse.getSuperInterfaces()!=null){
for(int k=0;k<tempKlasse.getSuperInterfaces().size();k++){
MyCompiler.wandleGeneric2RefType(tempKlasse.getSuperInterfaces().elementAt(k).get_ParaList(),this.KlassenVektor);
}
}
}
for (int i = 0; i < this.InterfaceVektor.size(); i++) {
Interface tempIntf = this.InterfaceVektor.elementAt(i);
MyCompiler.wandleGeneric2RefType(tempIntf.getContainedTypes(),
this.KlassenVektor);
}
// HOTI 04-13-06 Alle Methoden der Klassen überprüfen, ob sie als
// RefType deklarierte Attribute haben, die aber GenericTypeVars sind
// Bsp.:
// bei public E elementAt(i){...} wird E vorerst als RefType erkannt
for (int i = 0; i < this.KlassenVektor.size(); i++) {
Class tempKlasse = this.KlassenVektor.elementAt(i);
tempKlasse.wandleRefTypeAttributes2GenericAttributes();
}
for (int i = 0;i< this.InterfaceVektor.size(); i++){
Interface tempInterface = this.InterfaceVektor.elementAt(i);
tempInterface.wandleRefTypeAttributes2GenericAttributes();
}
// HOT 8.5.06 Wandelt alle Referenzen auf p.ex. Vector in java.util.Vector
for (int i = 0; i < this.KlassenVektor.size(); i++) {
Class tempKlasse = this.KlassenVektor.elementAt(i);
MyCompiler.makeRefTypesFullyQualified(tempKlasse.getContainedTypes(), this.imports);
String newSuperclass=MyCompiler.getFullyQualifiedNameFromClassname(tempKlasse.get_Superclass_Name(),this.imports);
if(newSuperclass!=null){
// Hier nicht setUsedID, sondern nur den Namen updaten. Sonst gehen die Parameter der Superklasse verloren
tempKlasse.superclassid.name=UsedId.createFromQualifiedName(newSuperclass,-1).name;
}
if(tempKlasse.getSuperInterfaces()!=null && tempKlasse.getSuperInterfaces().size()>0){
for(int j=0;j<tempKlasse.getSuperInterfaces().size();j++){
UsedId uid=tempKlasse.getSuperInterfaces().elementAt(j);
String newSuperif=MyCompiler.getFullyQualifiedNameFromClassname(uid.getQualifiedName(),this.imports);
if(newSuperif!=null){
UsedId newuid=UsedId.createFromQualifiedName(newSuperif,uid.getOffset());
uid.name=newuid.name;
}
MyCompiler.makeRefTypesFullyQualified(uid.get_ParaList(),this.imports);
}
}
for(int j=0;j<tempKlasse.getUsedIdsToCheck().size();j++){
UsedId id=tempKlasse.getUsedIdsToCheck().elementAt(j);
String newClassname=MyCompiler.getFullyQualifiedNameFromClassname(id.getQualifiedName(),this.imports);
if(newClassname!=null)
id.name=UsedId.createFromQualifiedName(newClassname,-1).name;
}
}
for (int i = 0; i < this.InterfaceVektor.size(); i++) {
Interface tempIntf = this.InterfaceVektor.elementAt(i);
MyCompiler.makeRefTypesFullyQualified(tempIntf.getContainedTypes(), this.imports);
}
inferencelog.info("Rufe \"SourceFile.makeFC()\"...");
inferencelog.info("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
FC_TTO finiteClosure = this.makeFC();
inferencelog.info("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
inferencelog.info("Bin aus \"SourceFile.makeFC()\" zur<75>ck.");
this.removeBasicAssumptions();
// PL 05-08-02
// verschoben nach Class.java am Ende von TRProg
// this.addClassNamesAndGenericsToRR(basics);
// HOTI 04-22-06 Fuer jede Klasse die Methoden und Instanzvariablen in die Assumptions aufnehmen
//
Iterator<Interface> intf_it = InterfaceVektor.iterator();
while (intf_it.hasNext()) {
Interface intf = intf_it.next();
// HOTI In diesem Moment gibt es nur _eine_ potentielle CTypeReconstructionResult, d.h.
// dort können die Definitionen der Interfaces (Methodintersectiontypes, FieldDecls) abgelegt werden
//intf.addThisToAssumptions(basics);
2013-10-18 11:33:46 +00:00
}
// Fuer jede Klasse die Assumptions der <20>ffentlichen Felder zusammentragen:
TypeAssumptions publicFieldsAssumptions = new TypeAssumptions();
for(Class cl : KlassenVektor){
publicFieldsAssumptions.add(cl.getPublicFieldAssumptions());
}
// Die BasicAssumptions anf<6E>gen:
publicFieldsAssumptions.add(this.getBasicAssumptions());
// Fuer jede Klasse separat den TRA aufrufen
Iterator<Class> class_it = KlassenVektor.iterator();
while (class_it.hasNext()) {
Class cl = class_it.next();
CSupportData supportData = new CSupportData(finiteClosure, A, cl.getName(), cl.get_ParaList());
inferencelog.info("Rufe " + cl.getName() + ".TRProg()...");
2014-02-11 01:47:39 +00:00
A.addAll(cl.typeReconstruction(supportData, publicFieldsAssumptions));
2013-10-18 11:33:46 +00:00
}
return A;
2014-02-11 01:47:39 +00:00
*/
2013-10-18 11:33:46 +00:00
}
// ino.end
/**
* Erstellt die Basic Assumptions (siehe MakeBasicAssumptions) als AssumptionSet
* @return
*/
private TypeAssumptions getBasicAssumptions() {
TypeAssumptions ret = new TypeAssumptions(null);
2013-10-18 11:33:46 +00:00
// AB hier der Teil aus makeBasicAssumptionsFromJRE:
Vector<UsedId> doneImports=new Vector<UsedId>();
//CTypeReconstructionResult basicAssumptions = new CTypeReconstructionResult(null);
Modifiers mod = new Modifiers();
mod.addModifier(new Public());
// F<>r jede einzelne Klasse
while (imports.size()>0) {
UsedId importDecl = imports.get(0);
// Properties laden
java.lang.Class<?> x;
try {
x = java.lang.Class.forName(importDecl.getQualifiedName());
} catch (ClassNotFoundException e) {
throw new CTypeReconstructionException("Fehlerhafte Import-Declaration: "+e.getMessage(),importDecl);
}
java.lang.reflect.Field[] fields=x.getDeclaredFields();
java.lang.reflect.Method[] methods=x.getDeclaredMethods();
java.lang.reflect.Constructor[] constructors=x.getConstructors();
java.lang.reflect.TypeVariable[] tvs=x.getTypeParameters();
//String className=x.getSimpleName();
String className=x.getName();
// Generische Typen erzeugen
Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>();
Vector<GenericTypeVar> typeGenPara = new Vector<GenericTypeVar>();
for(int j=0;j<tvs.length;j++){
GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(),-1);
typeGenPara.addElement(gtv);
jreSpiderRegistry.put(tvs[j].getName(),gtv);
}
//BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod);
if(typeGenPara.size()>0){
//basicAssumptions.addGenericTypeVars(className, typeGenPara);
//myCl.set_ParaList((Vector)typeGenPara);
}
if(x.getSuperclass()!=null){
//boolean isObject=x.getSuperclass().getSimpleName().equalsIgnoreCase("Object");
boolean isObject=x.getSuperclass().getName().equalsIgnoreCase("java.lang.Object");
boolean isBaseType=isBaseType(className);
//if((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && (!isBaseType|| READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
if (((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && READ_IMPORTED_SUPERCLASSES_FROM_JRE) //eingefuegt 07-08-11
|| (isBaseType && READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
{
String superclassFullyQualifiedName = x.getSuperclass().getCanonicalName();
//Andere Methode, da Vector.contains bei Strings nicht richtig vergleicht.
if(!containsString(imports,superclassFullyQualifiedName) && !containsString(doneImports,superclassFullyQualifiedName)){
imports.addElement(UsedId.createFromQualifiedName(superclassFullyQualifiedName,-1));
}
//UsedId ui = new UsedId();
//ui.set_Name(x.getSuperclass().getSimpleName());
UsedId ui=UsedId.createFromQualifiedName(x.getSuperclass().getName(),-1);
java.lang.Class superClass=x.getSuperclass();
java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters();
Vector<Type> supertypeGenPara = new Vector<Type>();
for(int tvi=0;tvi<superclassTVS.length;tvi++){
GenericTypeVar newGTV=new GenericTypeVar(superclassTVS[tvi].getName(),-1);
supertypeGenPara.addElement(newGTV);
}
if(supertypeGenPara.size()==0){
supertypeGenPara=null;
}
ui.set_ParaList(supertypeGenPara);
ui.vParaOrg=supertypeGenPara;
//myCl.set_UsedId(ui);
}
}
//this.addElement(myCl);
//basicAssumptions.addClassName(className);
for(int j=0;j<fields.length;j++){
if(java.lang.reflect.Modifier.isPublic(fields[j].getModifiers())){
//CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getSimpleName()), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>());
CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>());
//basicAssumptions.addFieldOrLocalVarAssumption(instVar);
//ret.add(instVar); //auskommentiert von Andreas Stadelmeier
2013-10-18 11:33:46 +00:00
}
}
for(int j=0;j<methods.length;j++){
if(java.lang.reflect.Modifier.isPublic(methods[j].getModifiers())){
String methodName=methods[j].getName();
java.lang.reflect.Type genericReturnType=methods[j].getGenericReturnType();
Type returnType=createTypeFromJavaGenericType(genericReturnType,methods[j].getReturnType(),jreSpiderRegistry);
java.lang.reflect.Type[] gpt=methods[j].getGenericParameterTypes();
java.lang.Class[] pt=methods[j].getParameterTypes();
CMethodTypeAssumption method = new CMethodTypeAssumption(new RefType(className, 0), methodName, returnType, pt.length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
for(int k=0;k<gpt.length;k++){
Type type=createTypeFromJavaGenericType(gpt[k],pt[k],jreSpiderRegistry);
// Fixme HOTI beachte overloaded id
method.addParaAssumption(new CParaTypeAssumption(className, methodName, pt.length,0,type.getName(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
}
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
//ret.add(method); //auskommentiert von Andreas Stadelmeier
2013-10-18 11:33:46 +00:00
}
}
for(int j=0;j<constructors.length;j++){
if(java.lang.reflect.Modifier.isPublic(constructors[j].getModifiers())){
String methodName="<init>";
CMethodTypeAssumption constructor = new CMethodTypeAssumption(new RefType(className, 0), methodName, new RefType(className,-1), constructors[j].getParameterTypes().length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
for(int k=0;k<constructors[j].getParameterTypes().length;k++){
String paraType=constructors[j].getParameterTypes()[k].getName();
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
// Fixme HOTI beachte overloaded id
constructor.addParaAssumption(new CParaTypeAssumption(className, methodName, constructors[j].getParameterTypes().length,0,paraType, new RefType(paraType,-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
}
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
//ret.add(constructor); //auskommentiert von Andreas Stadelmeier
2013-10-18 11:33:46 +00:00
}
}
imports.removeElement(importDecl);
doneImports.addElement(importDecl);
}
imports.addAll(doneImports);
return ret;
}
// ino.method.makeBasicAssumptionsFromJRE.21409.definition
@Deprecated //angef<65>gt von Andreas Stadelmeier. Grund: Die Funktion wurde neu als getBasicAssumptions angelegt
private TypeinferenceResultSet makeBasicAssumptionsFromJRE(Vector<UsedId> imports)
2013-10-18 11:33:46 +00:00
// ino.end
// ino.method.makeBasicAssumptionsFromJRE.21409.body
{
return null;
/*
2013-10-18 11:33:46 +00:00
Vector<UsedId> doneImports=new Vector<UsedId>();
TypeinferenceResultSet basicAssumptions = new TypeinferenceResultSet(null);
2013-10-18 11:33:46 +00:00
Modifiers mod = new Modifiers();
mod.addModifier(new Public());
// F<>r jede einzelne Klasse
while (imports.size()>0) {
UsedId importDecl = imports.get(0);
// Properties laden
java.lang.Class<?> x;
try {
x = java.lang.Class.forName(importDecl.getQualifiedName());
} catch (ClassNotFoundException e) {
throw new CTypeReconstructionException("Fehlerhafte Import-Declaration: "+e.getMessage(),importDecl);
}
java.lang.reflect.Field[] fields=x.getDeclaredFields();
java.lang.reflect.Method[] methods=x.getDeclaredMethods();
java.lang.reflect.Constructor[] constructors=x.getConstructors();
java.lang.reflect.TypeVariable[] tvs=x.getTypeParameters();
//String className=x.getSimpleName();
String className=x.getName();
// Generische Typen erzeugen
Hashtable<String,GenericTypeVar> jreSpiderRegistry=new Hashtable<String,GenericTypeVar>();
Vector<GenericTypeVar> typeGenPara = new Vector<GenericTypeVar>();
for(int j=0;j<tvs.length;j++){
GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(),-1);
typeGenPara.addElement(gtv);
jreSpiderRegistry.put(tvs[j].getName(),gtv);
}
BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod);
if(typeGenPara.size()>0){
basicAssumptions.addGenericTypeVars(className, typeGenPara);
myCl.set_ParaList((Vector)typeGenPara);
}
if(x.getSuperclass()!=null){
//boolean isObject=x.getSuperclass().getSimpleName().equalsIgnoreCase("Object");
boolean isObject=x.getSuperclass().getName().equalsIgnoreCase("java.lang.Object");
boolean isBaseType=isBaseType(className);
//if((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && (!isBaseType|| READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
if (((!isObject || READ_OBJECT_SUPERCLASSES_FROM_JRE) && READ_IMPORTED_SUPERCLASSES_FROM_JRE) //eingefuegt 07-08-11
|| (isBaseType && READ_BASE_TYPE_SUPERCLASSES_FROM_JRE))
{
String superclassFullyQualifiedName = x.getSuperclass().getCanonicalName();
//Andere Methode, da Vector.contains bei Strings nicht richtig vergleicht.
if(!containsString(imports,superclassFullyQualifiedName) && !containsString(doneImports,superclassFullyQualifiedName)){
imports.addElement(UsedId.createFromQualifiedName(superclassFullyQualifiedName,-1));
}
//UsedId ui = new UsedId();
//ui.set_Name(x.getSuperclass().getSimpleName());
UsedId ui=UsedId.createFromQualifiedName(x.getSuperclass().getName(),-1);
java.lang.Class superClass=x.getSuperclass();
java.lang.reflect.TypeVariable[] superclassTVS=superClass.getTypeParameters();
Vector<Type> supertypeGenPara = new Vector<Type>();
for(int tvi=0;tvi<superclassTVS.length;tvi++){
GenericTypeVar newGTV=new GenericTypeVar(superclassTVS[tvi].getName(),-1);
supertypeGenPara.addElement(newGTV);
}
if(supertypeGenPara.size()==0){
supertypeGenPara=null;
}
ui.set_ParaList(supertypeGenPara);
ui.vParaOrg=supertypeGenPara;
myCl.set_UsedId(ui);
}
}
this.addElement(myCl);
basicAssumptions.addClassName(className);
for(int j=0;j<fields.length;j++){
if(java.lang.reflect.Modifier.isPublic(fields[j].getModifiers())){
//CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getSimpleName()), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>());
CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>());
basicAssumptions.addFieldOrLocalVarAssumption(instVar);
}
}
for(int j=0;j<methods.length;j++){
if(java.lang.reflect.Modifier.isPublic(methods[j].getModifiers())){
String methodName=methods[j].getName();
java.lang.reflect.Type genericReturnType=methods[j].getGenericReturnType();
Type returnType=createTypeFromJavaGenericType(genericReturnType,methods[j].getReturnType(),jreSpiderRegistry);
java.lang.reflect.Type[] gpt=methods[j].getGenericParameterTypes();
java.lang.Class[] pt=methods[j].getParameterTypes();
CMethodTypeAssumption method = new CMethodTypeAssumption(new RefType(className, 0), methodName, returnType, pt.length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
for(int k=0;k<gpt.length;k++){
Type type=createTypeFromJavaGenericType(gpt[k],pt[k],jreSpiderRegistry);
// Fixme HOTI beachte overloaded id
method.addParaAssumption(new CParaTypeAssumption(className, methodName, pt.length,0,type.getName(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
}
basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
}
}
for(int j=0;j<constructors.length;j++){
if(java.lang.reflect.Modifier.isPublic(constructors[j].getModifiers())){
String methodName="<init>";
CMethodTypeAssumption constructor = new CMethodTypeAssumption(new RefType(className, 0), methodName, new RefType(className,-1), constructors[j].getParameterTypes().length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
for(int k=0;k<constructors[j].getParameterTypes().length;k++){
String paraType=constructors[j].getParameterTypes()[k].getName();
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
// Fixme HOTI beachte overloaded id
constructor.addParaAssumption(new CParaTypeAssumption(className, methodName, constructors[j].getParameterTypes().length,0,paraType, new RefType(paraType,-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
}
basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
}
}
imports.removeElement(importDecl);
doneImports.addElement(importDecl);
}
imports.addAll(doneImports);
return basicAssumptions;
*/
2013-10-18 11:33:46 +00:00
}
// ino.end
// ino.method.isBaseType.21412.definition
private boolean isBaseType(String type)
// ino.end
// ino.method.isBaseType.21412.body
{
return baseTypeTranslationTable.containsValue(type);
}
// ino.end
/*Die contains Methode des Vectors vergleicht bei Strings nicht korrekt,
* da zwei Strings mit dem gleichen Inhalt unterschiedliche Instanzen sind.
* Deshalb diese Methode 07-01-20 luar*/
private boolean containsString(Vector<UsedId> searchVector, String searchString)
{
boolean found = false;
for(UsedId id : searchVector)
{
String s = id.getQualifiedName();
found |= s.equals(searchString);
}
return found;
}
// ino.method.createTypeFromJavaGenericType.21415.definition
private Type createTypeFromJavaGenericType(java.lang.reflect.Type type, java.lang.Class<?> cl, Hashtable<String,GenericTypeVar>jreSpiderRegistry)
// ino.end
// ino.method.createTypeFromJavaGenericType.21415.body
{
if(type instanceof TypeVariableImpl){
TypeVariableImpl tvi=((TypeVariableImpl)type);
return(new GenericTypeVar(jreSpiderRegistry.get(tvi.getName()).getName(),-1));
}else{
//String jccNameForClass=baseTypeTranslationTable.get(cl.getSimpleName());
String jccNameForClass=baseTypeTranslationTable.get(cl.getName());
if(cl.getSimpleName().equalsIgnoreCase("void")){
return(new Void(-1));
}else if(jccNameForClass!=null){
RefType rt=new RefType(jccNameForClass,-1);
rt.setPrimitiveFlag(true);
return(rt);
}else{
//return(new RefType(cl.getSimpleName()));
return(new RefType(cl.getName(),-1));
}
}
}
// ino.end
// ino.method.makeBasicAssumptions.21418.defdescription type=javadoc
/**
* Erzeugt die Anfangsinformationen <EFBFBD>ber bereits bekannte Klassen.
* <br/>Achtung Workaround: Die RefTypes m<EFBFBD>ssen sp<EFBFBD>ter noch durch BaseTypes
* ersetzt werden. <br>
* Author: J<EFBFBD>rg B<EFBFBD>uerle
*
* @return A priori Typinformationen
* @throws ClassNotFoundException
*/
// ino.end
// ino.method.makeBasicAssumptions.21418.definition
2014-02-11 01:47:39 +00:00
public TypeAssumptions makeBasicAssumptions()
2013-10-18 11:33:46 +00:00
// ino.end
// ino.method.makeBasicAssumptions.21418.body
{
/*
2013-10-18 11:33:46 +00:00
if(LOAD_BASIC_ASSUMPTIONS_FROM_JRE){
Vector<UsedId> strImports=new Vector<UsedId>();
ImportDeclarations usedIdImports=getImports();
for(int i=0;i<usedIdImports.size();i++){
UsedId uid=usedIdImports.get(i);
if(uid.hasWildCard()){
throw new CTypeReconstructionException("Wildcards in den Imports werden bislang nicht unterstuetzt: "+uid.getQualifiedName(),uid);
//throw new ClassNotFoundException("Bei den Imports sind momentan keine Wildcards erlaubt!");
}else{
strImports.addElement(uid);
}
}
TypeinferenceResultSet res=makeBasicAssumptionsFromJRE(strImports);
2013-10-18 11:33:46 +00:00
ImportDeclarations newImports=new ImportDeclarations();
for(int i=0;i<strImports.size();i++){
newImports.addElement(strImports.get(i));
}
setImports(newImports);
return(res);
}
TypeinferenceResultSet foo = new TypeinferenceResultSet(null);
2013-10-18 11:33:46 +00:00
CMethodTypeAssumption meth = null;
CInstVarTypeAssumption instVar = null;
Class c = null;
UsedId ui = null;
//Vector pl = null;
Modifiers mod = new Modifiers();
mod.addModifier(new Public());
//------------------------
// Integer bauen:
//------------------------
foo.addClassName("java.lang.Integer"); //PL 05-08-01 eingefuegt
instVar = new CInstVarTypeAssumption("java.lang.Integer", "MAX_VALUE", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>());
foo.addFieldOrLocalVarAssumption(instVar);
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "<init>", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "<init>", new RefType("java.lang.Integer",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Integer", "<init>", 1, 0,"value", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Integer", 0), "intValue", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Integer", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Vector();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Boolean bauen:
//------------------------
foo.addClassName("java.lang.Boolean"); //PL 05-08-01 eingefuegt
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "<init>", new RefType("java.lang.Boolean",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "<init>", new RefType("java.lang.Boolean",-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Boolean", "<init>", 1, 0, "value", new RefType("java.lang.Boolean",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Boolean", 0), "booleanValue", new RefType("java.lang.Boolean",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Boolean", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Vector();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Character bauen:
//------------------------
foo.addClassName("java.lang.Character"); //PL 05-08-01 eingefuegt
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "<init>", new RefType("java.lang.Character",-1),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "<init>", new RefType("java.lang.Character",-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Character", "<init>", 1, 0,"value", new RefType("java.lang.Character",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Character", 0), "charValue", new BooleanType(),0, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Character", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Vector();
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Vector bauen:
//------------------------
foo.addClassName("java.lang.Vector"); //PL 05-08-01 eingefuegt
TypePlaceholder E = TypePlaceholder.fresh(); // Sp<53>ter ersetzen durch GenericTypeVar
Vector<GenericTypeVar> typeGenPara = new Vector<GenericTypeVar>();
typeGenPara.addElement(new GenericTypeVar(E.getName(),-1));
foo.addGenericTypeVars("java.lang.Vector", typeGenPara);
meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "elementAt", new GenericTypeVar(E.getName(),-1), 1,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Vector", "elementAt", 1, 0, "index", new RefType("java.lang.Integer",-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "addElement", new Void(-1),1, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
meth.addParaAssumption(new CParaTypeAssumption("java.lang.Vector", "addElement", 1, 0,"element", new GenericTypeVar(E.getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
foo.addMethodIntersectionType(new CIntersectionType(meth));
meth = new CMethodTypeAssumption(new RefType("java.lang.Vector", 0), "size", new RefType("java.lang.Integer",-1), 0,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
foo.addMethodIntersectionType(new CIntersectionType(meth));
c = new BasicAssumptionClass("java.lang.Vector", mod);
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
// pl = new Vector();
// pl.addElement(E);
// c.set_ParaList(pl);
this.addElement(c);
//------------------------
// Stack bauen:
//------------------------
foo.addClassName("java.lang.Stack"); //PL 05-08-01 eingefuegt
c = new BasicAssumptionClass("java.lang.Stack", mod);
ui = new UsedId(-1);
ui.set_Name("java.lang.Vector");
c.set_UsedId(ui);
// pl = new Vector();
// pl.addElement(E);
// c.set_ParaList(pl);
this.addElement(c);
return foo;
*/
2014-03-18 19:18:57 +00:00
TypeAssumptions ret = new TypeAssumptions();
//Basic Assumptions f<>r die FunN Interfaces:
//TODO: Hier mehr als Fun1-Fun5 implementieren
for(int i = 0; i<6; i++){
FunNInterface funN = new FunNInterface(i);
ret.add(funN.getPublicFieldAssumptions());
}
2014-03-18 19:18:57 +00:00
return ret; //TODO: Diese TypeAssumptions mit basic-Assumptions f<>llen
2013-10-18 11:33:46 +00:00
}
// ino.end
// ino.method.setImports.21421.definition
private void setImports(ImportDeclarations newImports)
// ino.end
// ino.method.setImports.21421.body
{
this.imports=newImports;
}
// ino.end
// ino.method.removeBasicAssumptions.21424.defdescription type=javadoc
/**
* L<EFBFBD>scht die Anfangsinformation wieder aus dem Klassenvektor
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
*/
// ino.end
// ino.method.removeBasicAssumptions.21424.definition
private void removeBasicAssumptions()
// ino.end
// ino.method.removeBasicAssumptions.21424.body
{
for(int i=0; i<KlassenVektor.size(); i++){
Class cl = KlassenVektor.elementAt(i);
if(cl instanceof BasicAssumptionClass){
KlassenVektor.removeElementAt(i);
i--;
}
}
}
// ino.end
// ino.method.getPackageName.21427.defdescription type=javadoc
/**
* Erzeugt f<EFBFBD>r jede Klasse einen Vector, in den Referenzen auf die GenericTypeVars
* dieser Klasse gespeichert werden. Diese Vectoren werden unter den Klassennamen
* in der
* Ergebnisdatenstruktur abgelegt. Au<EFBFBD>erdem werden alle Klassennamen gespeichert.
* <br/>Author: J<EFBFBD>rg B<EFBFBD>uerle
* @param res
* /
* /*private void addClassNamesAndGenericsToRR(CTypeReconstructionResult res){
* Iterator<Class> it = this.getClassIterator();
* while(it.hasNext()){
* Class cl = it.next();
* res.addClassName(cl.get_classname());
* Vector<GenericTypeVar> genericsList = new Vector<GenericTypeVar>();
*
* for(int i =0; i<cl.get_ParaList().size(); i++){
* Type para = (Type)cl.get_ParaList().elementAt(i);
* if(para instanceof GenericTypeVar){
* genericsList.addElement((GenericTypeVar)para);
* }
* }
* res.addGenericTypeVars(cl.get_classname(), genericsList);
* }
* }
*/
// ino.end
// ino.method.getPackageName.21427.definition
public UsedId getPackageName()
// ino.end
// ino.method.getPackageName.21427.body
{
return pkgName;
}
// ino.end
// ino.method.setPackageName.21430.definition
public void setPackageName(UsedId pkgName)
// ino.end
// ino.method.setPackageName.21430.body
{
this.pkgName = pkgName;
// Die Package-Namen fuer alle Klassen und Interfaces
// im Source-File nachziehen
for (int i=0; i<KlassenVektor.size(); i++) {
KlassenVektor.elementAt(i).setPackageName(pkgName);
}
}
// ino.end
// ino.method.addImports.21433.definition
public void addImports(ImportDeclarations imports)
// ino.end
// ino.method.addImports.21433.body
{
this.imports.addAll(imports);
}
// ino.end
// ino.method.getImports.21436.definition
public ImportDeclarations getImports()
// ino.end
// ino.method.getImports.21436.body
{
if(imports==null){
return(new ImportDeclarations());
}
return(imports);
}
// ino.end
// ino.method.getClassIterator.21439.definition
public Iterator<Class> getClassIterator()
// ino.end
// ino.method.getClassIterator.21439.body
{
return KlassenVektor.iterator();
}
// ino.end
// ino.method.getInterfaceIterator.21442.definition
public Iterator<Interface> getInterfaceIterator()
// ino.end
// ino.method.getInterfaceIterator.21442.body
{
return InterfaceVektor.iterator();
}
// ino.end
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
if(parent!=null)throw new TypinferenzException("Eine SourceFile hat keine Elternelement im Syntaxbaum");
super.parserPostProcessing(parent);
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
}
@Override
public SyntaxTreeNode getParent() {
return null;
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<SyntaxTreeNode>();
2014-02-12 01:12:12 +00:00
for(Class cl : this.KlassenVektor){
ret.add(cl);
}
return ret;
}
/**
* SourceFile stellt eine geparste Java-Datei dar. Mit dieser Methode wird der Name der eingelesenen Datei gesetzt.
* @param filename - Der Name der eingelesenen JavaDatei
*/
@Deprecated
public void setFileName(String filename) {
//this.filename = filename;
}
2013-10-18 11:33:46 +00:00
}
// ino.end