2013-10-18 13:33:46 +02:00
// ino.module.SourceFile.8722.package
2014-09-04 16:35:44 +02:00
package de.dhbwstuttgart.syntaxtree ;
2013-10-18 13:33:46 +02:00
// ino.end
// ino.module.SourceFile.8722.import
2015-08-27 13:36:14 +02:00
import java.io.IOException ;
2014-03-12 16:32:50 +01:00
import java.util.Collection ;
2013-10-18 13:33:46 +02:00
import java.util.Enumeration ;
2014-03-28 18:36:08 +01:00
import java.util.HashMap ;
2013-10-18 13:33:46 +02:00
import java.util.Hashtable ;
import java.util.Iterator ;
2016-03-24 11:57:17 +01:00
import java.util.Set ;
import java.util.function.Function ;
2015-08-27 13:36:14 +02:00
2015-04-22 21:40:22 +02:00
import de.dhbwstuttgart.typeinference.Menge ;
2015-08-27 13:36:14 +02:00
2014-11-03 10:40:28 +01:00
import java.util.stream.Stream ;
2014-02-09 16:07:31 +01:00
2014-10-09 12:01:16 +02:00
import de.dhbwstuttgart.logger.Logger ;
2014-10-09 17:38:10 +02:00
import de.dhbwstuttgart.logger.Section ;
2014-09-04 16:35:44 +02:00
import de.dhbwstuttgart.core.AClassOrInterface ;
import de.dhbwstuttgart.core.MyCompiler ;
import de.dhbwstuttgart.myexception.CTypeReconstructionException ;
import de.dhbwstuttgart.myexception.JVMCodeException ;
import de.dhbwstuttgart.myexception.SCClassException ;
import de.dhbwstuttgart.myexception.SCException ;
2014-09-05 11:49:31 +02:00
import de.dhbwstuttgart.parser.JavaClassName ;
2016-03-24 11:57:17 +01:00
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.syntaxtree.misc.DeclId ;
import de.dhbwstuttgart.syntaxtree.misc.UsedId ;
2014-09-05 11:49:31 +02:00
import de.dhbwstuttgart.syntaxtree.modifier.Modifiers ;
import de.dhbwstuttgart.syntaxtree.modifier.Public ;
2015-09-22 18:43:36 +02:00
import de.dhbwstuttgart.syntaxtree.type.FunN ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar ;
import de.dhbwstuttgart.syntaxtree.type.RefType ;
import de.dhbwstuttgart.syntaxtree.type.Type ;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder ;
import de.dhbwstuttgart.syntaxtree.type.Void ;
2015-08-27 13:36:14 +02:00
import de.dhbwstuttgart.typeinference.ByteCodeResult ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.ConstraintsSet ;
import de.dhbwstuttgart.typeinference.FunNInterface ;
import de.dhbwstuttgart.typeinference.FunNMethod ;
2016-03-24 11:57:17 +01:00
import de.dhbwstuttgart.typeinference.KomplexeMenge ;
2014-09-08 15:12:47 +02:00
import de.dhbwstuttgart.typeinference.Pair ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.ResultSet ;
import de.dhbwstuttgart.typeinference.TypeinferenceResultSet ;
2015-11-06 16:42:22 +01:00
import de.dhbwstuttgart.typeinference.TypeinferenceResults ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.UndConstraint ;
2016-03-29 13:23:05 +02:00
import de.dhbwstuttgart.typeinference.UnifyConstraintsSet ;
2014-09-02 10:33:54 +02:00
import de.dhbwstuttgart.typeinference.assumptions.ClassAssumption ;
import de.dhbwstuttgart.typeinference.assumptions.MethodAssumption ;
import de.dhbwstuttgart.typeinference.assumptions.ParameterAssumption ;
import de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions ;
import de.dhbwstuttgart.typeinference.exceptions.DebugException ;
import de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException ;
2014-09-02 11:07:16 +02:00
import de.dhbwstuttgart.typeinference.unify.Unify ;
2016-03-24 11:57:17 +01:00
import de.dhbwstuttgart.typeinference.unify.model.FiniteClosure ;
2016-04-04 11:23:14 +02:00
import de.dhbwstuttgart.typeinference.unify.model.UnifyPair ;
2013-10-18 13:33:46 +02:00
public class SourceFile
2014-02-12 02:12:12 +01:00
extends SyntaxTreeNode
2013-10-18 13:33:46 +02:00
{
// ino.attribute.LOAD_BASIC_ASSUMPTIONS_FROM_JRE.21358.decldescription type=javadoc
/ * *
* @autor HOTI
2015-04-22 21:40:22 +02:00
* Dieses Flag bestimmt , ob die basicAssumptions ( Integer , Menge , . . . ) direkt von
2013-10-18 13:33:46 +02:00
* 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
2015-05-12 19:49:27 +02:00
* mit rein geladen . Dies hat natà ¼ rlich zur Folge , dass man in der GUI jeden Typ
* auswà ¤ hlen muss , weil ALLES in Java von Object erbt . Sobald die GUI das à ¼ ber eine
* Checkbox o . Ã ¤ . ausblendbar macht kann es aktiviert werden . Ebenso beeinflusst es
2013-10-18 13:33:46 +02:00
* 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
/ * *
2015-05-12 19:49:27 +02:00
* Wenn dieses Flag auf < b > false < / b > ist , werden fà ¼ r alle Basisklassen ( definiert
2013-10-18 13:33:46 +02:00
* 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
2015-05-12 19:49:27 +02:00
* Wenn dieses Flag auf < b > false < / b > ist , werden fà ¼ r alle importierten Klassen
2013-10-18 13:33:46 +02:00
* 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
2015-04-22 21:40:22 +02:00
public Menge < Class > KlassenVektor = new Menge < Class > ( ) ;
2013-10-18 13:33:46 +02:00
// ino.end
// ino.attribute.InterfaceVektor.21379.declaration
2015-04-22 21:40:22 +02:00
public Menge < Interface > InterfaceVektor = new Menge < Interface > ( ) ;
2013-10-18 13:33:46 +02:00
// ino.end
2014-03-07 22:05:10 +01:00
2015-08-27 16:36:19 +02:00
2013-10-18 13:33:46 +02:00
/ * *
2015-05-12 19:49:27 +02:00
* Die SourceFile reprà ¤ sntiert eine zu einem Syntaxbaum eingelesene Java - Datei .
2014-02-11 16:30:38 +01:00
* SourceFile stellt dabei den Wurzelknoten des Syntaxbaumes dar .
2013-10-18 13:33:46 +02:00
* /
2014-02-11 16:30:38 +01:00
public SourceFile ( ) {
// HOTI 4.5.06
2013-10-18 13:33:46 +02: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 " ) ;
2015-04-22 21:40:22 +02:00
//baseTypeTranslationTable.put("this.is.a.temporary.entry","de.dhbwstuttgart.typeinference.Menge"); auskommentiert PL 07-08-11
2013-10-18 13:33:46 +02:00
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 ) ) ;
}
}
2014-02-11 16:30:38 +01:00
2015-04-22 21:40:22 +02:00
public SourceFile ( Menge < Class > classDefinitions ) {
2014-09-16 11:31:15 +02:00
this . KlassenVektor = classDefinitions ;
}
2014-02-11 16:30:38 +01:00
/ * *
* HOTI 4 . 5 . 06
* Beinhaltet alle Imports des aktuell geparsten Files
* in Form einer UsedId
* /
private ImportDeclarations imports = new ImportDeclarations ( ) ;
2016-03-24 11:57:17 +01:00
2014-02-11 16:30:38 +01:00
/ * *
2015-05-12 19:49:27 +02:00
* Table zum à bersetzen der nicht implementierten Base - Types :
* Ã berall im Compiler wird statt bspw . int Integer verwendet
2014-02-11 16:30:38 +01:00
* d . h . 1 + 2 liefert ein Integer
2015-05-12 19:49:27 +02:00
* Deshalb benà ¶ tigen wir hier eine Tabelle , mit der man die von
2014-02-11 16:30:38 +01:00
* der JRE gelieferten Base - Typen ( int , char , etc ) und die Objekt -
2015-05-12 19:49:27 +02:00
* Typen umwandeln kà ¶ nnen
2014-02-11 16:30:38 +01:00
* /
private Hashtable < String , String > baseTypeTranslationTable ;
2013-10-18 13:33:46 +02:00
/ * *
* Fuegt ein neues Element ( Interface oder Klasse ) hinzu .
* @param c
* /
public void addElement ( AClassOrInterface e )
{
if ( e instanceof Class ) {
KlassenVektor . addElement ( ( Class ) e ) ;
} else if ( e instanceof Interface ) {
InterfaceVektor . addElement ( ( Interface ) e ) ;
}
}
2014-02-11 02:47:39 +01:00
2013-10-18 13:33:46 +02:00
/////////////////////////////////////////////////////////////////////////
// TypeReconstructionAlgorithmus
/////////////////////////////////////////////////////////////////////////
// ino.method.typeReconstruction.21406.defdescription type=javadoc
/ * *
2015-05-12 19:49:27 +02:00
* Tyrekonstruktionsalgorithmus : ruft fà ¯  ¿  ½ r jede Klasse den Algorithmus TRProg auf .
* Dessen Ergebnismenge A , die Menge aller Typannahmen , fà ¯  ¿  ½ r eine Klasse dient als
* Eingabe fà ¯  ¿  ½ r TRProg der nà ¯  ¿  ½ chsten Klasse . Am Ende enthà ¯  ¿  ½ lt A alle mà ¯  ¿  ½ glichen
* Typkombinationen fà ¯  ¿  ½ r alle Klassen zusammen .
* < br > Author : JÃ ¯ Â ¿ Â ½ rg BÃ ¯ Â ¿ Â ½ uerle
* @return Liste aller mà ¯  ¿  ½ glichen Typkombinationen
* @throws CTypeReconstructionException Wenn was schief là ¯  ¿  ½ uft
2013-10-18 13:33:46 +02:00
* /
// ino.end
// ino.method.typeReconstruction.21406.definition
2015-04-22 21:40:22 +02:00
public Menge < TypeinferenceResultSet > typeReconstruction ( TypeAssumptions globalAssumptions )
2013-10-18 13:33:46 +02:00
throws CTypeReconstructionException
// ino.end
// ino.method.typeReconstruction.21406.body
{
2015-04-22 21:40:22 +02:00
Menge < TypeinferenceResultSet > ret = new Menge < TypeinferenceResultSet > ( ) ;
2014-02-11 02:47:39 +01:00
//Logger initialisieren:
Logger typinferenzLog = Logger . getLogger ( " Typeinference " ) ;
2015-05-12 19:49:27 +02:00
//Alle Assumptions für diese SourceFile sammeln:
2014-02-14 17:31:55 +01:00
for ( Class klasse : this . KlassenVektor ) {
globalAssumptions . add ( klasse . getPublicFieldAssumptions ( ) ) ;
}
2014-04-03 10:35:25 +02:00
//Assumptions der importierten Klassen sammeln:
2014-10-08 19:00:17 +02:00
TypeAssumptions importAssumptions = this . makeBasicAssumptionsFromJRE ( imports , true ) ;
2014-04-03 10:35:25 +02:00
globalAssumptions . add ( importAssumptions ) ;
2014-10-09 17:38:10 +02:00
typinferenzLog . debug ( " Von JRE erstellte Assumptions: " + importAssumptions , Section . TYPEINFERENCE ) ;
2014-04-03 10:35:25 +02:00
2014-10-01 17:12:16 +02:00
//FiniteClosure generieren:
2016-03-24 11:57:17 +01:00
FiniteClosure finiteClosure = UnifyTypeFactory . generateFC ( globalAssumptions ) ;
2014-10-01 17:12:16 +02:00
2014-10-09 17:38:10 +02:00
typinferenzLog . debug ( " FiniteClosure: \ n " + finiteClosure , Section . TYPEINFERENCE ) ;
2014-10-01 17:12:16 +02:00
2014-03-19 15:14:50 +01:00
ConstraintsSet oderConstraints = new ConstraintsSet ( ) ;
2014-02-11 02:47:39 +01:00
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for ( Class klasse : KlassenVektor ) {
2016-03-24 11:57:17 +01:00
oderConstraints . add ( klasse . typeReconstruction ( globalAssumptions ) ) ;
2014-03-19 15:14:50 +01:00
}
2016-03-24 11:57:17 +01:00
/ * ////////////////
* Paare in MPairs umwandeln
* ( Wird zunächst mal weggelassen . Constraints werden erst beim Unifizieren umgewandelt
* /////////////////
//UnifyTypeFactory.convert(oderConstraints);
2014-03-19 15:14:50 +01:00
////////////////
2016-03-29 13:23:05 +02:00
//Typen in UnifyTypen umwandeln:
2014-03-19 15:14:50 +01:00
////////////////
2016-03-29 13:23:05 +02:00
UnifyConstraintsSet unifyConstraints = UnifyTypeFactory . convert ( oderConstraints ) ;
2014-10-01 17:12:16 +02:00
2015-05-12 19:49:27 +02:00
//Unmögliche ConstraintsSets aussortieren durch Unifizierung
2016-04-04 11:23:14 +02:00
Function < Menge < UnifyPair > , Menge < Menge < UnifyPair > > > unifier = ( pairs ) - > {
Menge < Menge < UnifyPair > > retValue = new Menge < > ( ) ;
Set < Set < UnifyPair > > unifiedPairs = new Unify ( ) . unify ( pairs , finiteClosure ) ;
2014-10-09 12:01:16 +02:00
return retValue ; } ;
2015-02-17 22:12:31 +01:00
//oderConstraints.filterWrongConstraints(unifier);
2015-12-08 15:48:35 +01:00
//oderConstraints.unifyUndConstraints(unifier); //rausgeworfen für Tests (08.12.2015)
2016-03-29 13:23:05 +02:00
2016-03-30 18:16:27 +02:00
typinferenzLog . debug ( " Ã briggebliebene Konstraints: \ n " + oderConstraints + " \ n " , Section . TYPEINFERENCE ) ;
typinferenzLog . debug ( " Ã briggebliebene Konvertierte Konstraints: \ n " + unifyConstraints + " \ n " , Section . TYPEINFERENCE ) ;
2016-03-29 13:23:05 +02:00
////////////////
//Karthesisches Produkt bilden:
////////////////
2016-04-04 11:23:14 +02:00
Set < Set < UnifyPair > > xConstraints = unifyConstraints . cartesianProduct ( ) ;
2016-03-29 13:23:05 +02:00
2016-04-07 14:39:07 +02:00
typinferenzLog . debug ( " Finite Closure: " + finiteClosure , Section . TYPEINFERENCE ) ;
2014-10-09 17:38:10 +02:00
typinferenzLog . debug ( " Karthesisches Produkt der Constraints: " + xConstraints , Section . TYPEINFERENCE ) ;
2014-09-03 16:15:04 +02:00
2016-03-24 11:57:17 +01:00
//finiteClosure.generateFullyNamedTypes(globalAssumptions);
2014-03-19 15:14:50 +01:00
//////////////////////////////
// Unifizierung der Constraints:
//////////////////////////////
2014-06-10 20:23:01 +02:00
boolean unifyFail = true ;
2016-04-04 11:23:14 +02:00
for ( Set < UnifyPair > constraints : xConstraints ) {
2015-05-12 19:49:27 +02:00
//Alle durch das Karthesische Produkt entstandenen Möglichkeiten durchgehen:
2016-03-30 18:16:27 +02:00
//Menge<Menge<Pair>> result = new Menge<Menge<Pair>>();
2014-02-11 02:47:39 +01:00
2014-11-03 10:40:28 +01:00
//IDEE: Man bildet Zusammenhangskomponenten von Paaren, die gemeinsame Variablen haben
// und unifizert nur die Zusammenhangskomponenten in Schritten 1 - 5
2016-03-29 13:23:05 +02:00
/ *
2014-11-03 10:40:28 +01:00
//Schritt 1: Alle Variablen in den Paaren von Elementen einsammeln
2016-03-29 13:23:05 +02:00
Menge < Menge < TypePlaceholder > > constraintsclonevars = constraints . stream ( ) . map ( p - > { Menge < TypePlaceholder > TPHs = new Menge < > ( ) ;
2014-11-03 10:40:28 +01:00
TPHs . addAll ( p . TA1 . getInvolvedTypePlaceholder ( ) ) ;
TPHs . addAll ( p . TA2 . getInvolvedTypePlaceholder ( ) ) ;
return TPHs ; }
2015-04-22 21:40:22 +02:00
) . collect ( Menge : : new , Menge : : add , Menge : : addAll ) ;
2014-11-03 10:40:28 +01:00
//Schritt 2: Schnittmengen jedes Elements mit jedem Elememt von vars bilden und dann index zusammenfassen
2015-05-12 19:49:27 +02:00
//in indexset sind dann die Mengen von Indizes enthalten, die gemeisam unifiziert wreden müssen
2015-04-22 21:40:22 +02:00
Menge < Menge < Integer > > indexeset = new Menge < > ( ) ;
2014-11-03 10:40:28 +01:00
if ( constraintsclonevars ! = null & & constraintsclonevars . size ( ) > 0 ) {
indexeset = Unify . schnitt ( constraintsclonevars ) ;
}
//Schritt 3: Umwandlung der Indizes in die zugehoerigen Elemente
// In streamconstraintsclone sind die Mengen von Paar enthalten die unifiziert werden muessen
2016-03-24 11:57:17 +01:00
Stream < Menge < MPair > > streamconstraintsclone = indexeset . stream ( ) . map ( x - > x . stream ( )
2014-11-03 10:40:28 +01:00
. map ( i - > constraintsClone . elementAt ( i ) )
2016-03-24 11:57:17 +01:00
. < Menge < MPair > > collect ( Menge : : new , Menge : : add , Menge : : addAll ) ) ;
2015-04-22 21:40:22 +02:00
//Menge<Menge<Pair>> vecconstraintsclone = streamconstraintsclone.collect(Menge::new, Menge::add, Menge::addAll);
2016-03-16 14:54:41 +01:00
//System.out.println();
2014-11-03 10:40:28 +01:00
//Schritt 4: Unifikation
2016-03-24 11:57:17 +01:00
Set < Set < Set < MPair > > > vecunifyResult =
2015-04-22 21:40:22 +02:00
//streamconstraintsclone.map(x -> Unify.unify(x, finiteClosure)).collect(Menge::new, Menge::add, Menge::addAll);
2015-03-05 13:55:21 +01:00
//DEBUG-Variante
streamconstraintsclone . map ( x - >
2016-03-24 11:57:17 +01:00
{ Set < Set < MPair > > z = new Unify ( ) . unify ( x , finiteClosure ) ;
2015-03-05 13:55:21 +01:00
return z ;
}
2015-04-22 21:40:22 +02:00
) . collect ( Menge : : new , Menge : : add , Menge : : addAll ) ;
2015-03-05 13:55:21 +01:00
2014-11-03 10:40:28 +01:00
//card gibt die Cardinalitaet der unifizierten Mengen an
2015-04-22 21:40:22 +02:00
Menge < Integer > card = vecunifyResult . stream ( ) . map ( x - > x . size ( ) ) . collect ( Menge : : new , Menge : : add , Menge : : addAll ) ;
2014-11-03 10:40:28 +01:00
; //.reduce(1,(a,b) -> { if ((a > 0) && (b > 0)) return (a * b); else return 1; });
//Schritt 5: Bildung des cartesischen Produkts
//sollte wieder entfernt werden: Weiterarbeit mit:
//[[x_1 -> t_1, x_2 -> t2], [x_1 -> t'_1, x_2 -> t'_2]] x ... x [[x_n -> t_1n], [x_n -> t2n], [x_n -> t3n]]
2016-03-24 11:57:17 +01:00
Set < Set < Pair > > cardprodret_start = new Menge < > ( ) ;
2015-04-22 21:40:22 +02:00
cardprodret_start . add ( new Menge < Pair > ( ) ) ;
2014-11-03 10:40:28 +01:00
//cart. Produkt mit Linkverschiebung
2016-03-24 11:57:17 +01:00
Set < Set < Pair > > unifyResult = vecunifyResult . stream ( ) . reduce ( cardprodret_start , ( x , y ) - > {
Set < Set < Pair > > cardprodret = new Menge < > ( ) ;
2014-11-03 10:40:28 +01:00
if ( y . size ( ) > 0 ) {
//System.out.println(y);
2015-04-22 21:40:22 +02:00
//Menge<Menge<Pair>> cardprodretold = x;
//cardprodret = new Menge<>();
2014-11-03 10:40:28 +01:00
for ( int j = 0 ; j < x . size ( ) ; j + + ) {
for ( int k = 0 ; k < y . size ( ) ; k + + ) {
2016-03-24 11:57:17 +01:00
Set < Pair > help = new Menge < > ( ) ;
2014-11-03 10:40:28 +01:00
help . addAll ( y . elementAt ( k ) ) ;
help . addAll ( x . elementAt ( j ) ) ;
cardprodret . add ( help ) ;
}
}
}
else
2015-04-22 21:40:22 +02:00
return new Menge < > ( ) ; //kein unifiziertes Ergebnis, damit wird das Geseamtergebnis []
2014-11-03 10:40:28 +01:00
return cardprodret ;
} ) ;
2016-03-29 13:23:05 +02:00
* /
2016-04-04 11:23:14 +02:00
Set < Set < UnifyPair > > unifyResult = new Unify ( ) . unify ( constraints , finiteClosure ) ;
2016-03-30 18:16:27 +02:00
2016-04-04 11:23:14 +02:00
Menge < Menge < Pair > > convertedResult = unifyResult . parallelStream ( ) . < Menge < Pair > > map ( ( Set < UnifyPair > resultSet ) - > {
Menge < Pair > innerConvert = resultSet . stream ( ) . map ( ( UnifyPair mp ) - > UnifyTypeFactory . convert ( mp ) )
2016-03-30 18:16:27 +02:00
. collect ( Menge < Pair > : : new , Menge : : add , Menge : : addAll ) ;
return innerConvert ;
} ) . collect ( Menge : : new , Menge : : add , Menge : : addAll ) ;
Menge < Pair > convertedConstraints = constraints . stream ( ) . map (
2016-04-04 11:23:14 +02:00
( UnifyPair mp ) - > { return UnifyTypeFactory . convert ( mp ) ; }
2016-03-30 18:16:27 +02:00
) . collect ( Menge < Pair > : : new , Menge : : add , Menge : : addAll ) ;
2015-05-12 19:49:27 +02:00
//Dann den Ergebnissen anfügen
2016-03-16 14:54:41 +01:00
typinferenzLog . debug ( " \ nErgebnis der Unifizierung: \ n " + unifyResult , Section . TYPEINFERENCE ) ;
2016-03-30 18:16:27 +02:00
//result.addAll(convertedResult);
2014-03-19 15:14:50 +01:00
2014-10-09 17:38:10 +02:00
typinferenzLog . debug ( " \ nJavaFiles: \ n " , Section . TYPEINFERENCE ) ;
2014-03-19 15:14:50 +01:00
2015-04-22 21:40:22 +02:00
//typinferenzLog.debug(this.printJavaCode(new ResultSet(new Menge<Pair>())));
2014-03-19 15:14:50 +01:00
2015-05-12 19:49:27 +02:00
//Für jede Klasse in diesem SourceFile gilt das selbe ResultSet:
2014-03-19 15:14:50 +01:00
for ( Class klasse : this . KlassenVektor ) {
2015-05-12 19:49:27 +02:00
//Der Unifikationsalgorithmus kann wiederum auch mehrere Lösungen errechnen, diese werden im folgenden durchlaufen:
2016-03-30 18:16:27 +02:00
for ( Menge < Pair > resultSet : convertedResult ) {
2014-06-10 20:23:01 +02:00
unifyFail = false ; //Ein Unifiziertes Ergebnis ist entstanden (es kann auch leer sein, das bedeutet nur, dass die Constraints mindestens in einem Fall Sinn ergaben)
2014-03-19 15:14:50 +01:00
//Add Result set as a new ReconstructionResult to ret:
2016-03-30 18:16:27 +02:00
TypeinferenceResultSet reconstructionResult = new TypeinferenceResultSet ( klasse , convertedConstraints , new ResultSet ( resultSet ) ) ;
2014-03-19 15:14:50 +01:00
ret . add ( reconstructionResult ) ;
//ResultSet res = new ResultSet(resultSet);
2015-05-12 19:49:27 +02:00
typinferenzLog . debug ( " JavaFile für ResultSet " + reconstructionResult + " \ n " , Section . TYPEINFERENCE ) ;
2014-10-09 17:38:10 +02:00
typinferenzLog . debug ( klasse . printJavaCode ( reconstructionResult ) , Section . TYPEINFERENCE ) ;
2014-03-19 15:14:50 +01:00
}
}
2014-02-11 02:47:39 +01:00
}
2014-06-10 20:23:01 +02:00
if ( unifyFail ) {
if ( ! this . KlassenVektor . isEmpty ( ) ) throw new TypeinferenceException ( " Fehler in Typinferierung " , this . KlassenVektor . firstElement ( ) ) ;
}
2014-02-11 02:47:39 +01:00
return ret ;
2013-10-18 13:33:46 +02:00
}
2014-10-08 19:00:17 +02:00
/ * *
2015-05-12 19:49:27 +02:00
* Erstellt die Assumptions der standardmà ¤ à ig importierten Packages ( java . lang . ) sowie der von imports à ¼ bergebenen Klassen zusammen .
2014-10-08 19:00:17 +02:00
* @param imports
2015-05-12 19:49:27 +02:00
* @param withSuptypes - Gibt an , ob auch die subklassen der Packages den Assumptions angefà ¼ gt werden sollen .
2014-10-08 19:00:17 +02:00
* @return
* /
2016-03-17 16:54:43 +01:00
public TypeAssumptions makeBasicAssumptionsFromJRE ( Menge < UsedId > imports , boolean withSubtypes )
2013-10-18 13:33:46 +02:00
// ino.end
// ino.method.makeBasicAssumptionsFromJRE.21409.body
{
2014-04-01 21:38:53 +02:00
//return null;
///*
2015-04-22 21:40:22 +02:00
Menge < UsedId > doneImports = new Menge < UsedId > ( ) ;
2013-10-18 13:33:46 +02:00
2014-04-01 21:38:53 +02:00
//TypeinferenceResultSet basicAssumptions = new TypeinferenceResultSet(null);
TypeAssumptions basicAssumptions = new TypeAssumptions ( ) ;
2013-10-18 13:33:46 +02:00
Modifiers mod = new Modifiers ( ) ;
mod . addModifier ( new Public ( ) ) ;
2015-05-12 19:49:27 +02:00
//Für Object:
2014-05-07 21:57:29 +02:00
imports . add ( new UsedId ( " java.lang.Object " , - 1 ) ) ;
2013-10-18 13:33:46 +02:00
2015-05-12 19:49:27 +02:00
// Für jede einzelne Klasse
2013-10-18 13:33:46 +02:00
while ( imports . size ( ) > 0 ) {
UsedId importDecl = imports . get ( 0 ) ;
// Properties laden
java . lang . Class < ? > x ;
try {
2014-09-02 18:49:19 +02:00
x = java . lang . Class . forName ( importDecl . getQualifiedName ( ) . toString ( ) ) ;
2013-10-18 13:33:46 +02:00
} 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 ( ) ;
2014-10-01 17:12:16 +02:00
//Ermittle die Superklasse:
2014-10-08 19:00:17 +02:00
Class sClass = new Class ( " Object " , 0 ) ;
if ( withSubtypes ) sClass = getSuperClassOfJREClass ( x , basicAssumptions ) ;
2014-09-04 16:35:44 +02:00
2014-10-08 19:00:17 +02:00
// Namen von Generische Typen erzeugen
2013-10-18 13:33:46 +02:00
Hashtable < String , GenericTypeVar > jreSpiderRegistry = new Hashtable < String , GenericTypeVar > ( ) ;
2015-04-22 21:40:22 +02:00
Menge < String > typeGenPara = new Menge < String > ( ) ;
2013-10-18 13:33:46 +02:00
for ( int j = 0 ; j < tvs . length ; j + + ) {
2014-10-08 19:00:17 +02:00
//GenericTypeVar gtv=new GenericTypeVar(tvs[j].getName(), parentClass,-1);
typeGenPara . addElement ( tvs [ j ] . getName ( ) ) ;
//jreSpiderRegistry.put(tvs[j].getName(),gtv);
2013-10-18 13:33:46 +02:00
}
2014-10-08 19:00:17 +02:00
Class parentClass = new Class ( className , sClass . getType ( ) , mod , typeGenPara ) ;
2014-04-01 21:38:53 +02:00
//BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod);
2014-10-08 19:00:17 +02:00
for ( GenericTypeVar classParam : parentClass . getGenericParameter ( ) ) {
jreSpiderRegistry . put ( classParam . getName ( ) . toString ( ) , classParam ) ;
}
2013-10-18 13:33:46 +02:00
if ( typeGenPara . size ( ) > 0 ) {
2014-04-01 21:38:53 +02:00
//auskommentiert von Andreas Stadelmeier:
//basicAssumptions.addGenericTypeVars(className, typeGenPara);
2015-04-22 21:40:22 +02:00
//parentClass.set_ParaList((Menge)typeGenPara);//myCl.set_ParaList((Menge)typeGenPara);
2013-10-18 13:33:46 +02:00
}
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 ( ) ;
2015-04-22 21:40:22 +02:00
//Andere Methode, da Menge.contains bei Strings nicht richtig vergleicht.
2013-10-18 13:33:46 +02:00
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 ( ) ;
2015-04-22 21:40:22 +02:00
Menge < Type > supertypeGenPara = new Menge < Type > ( ) ;
2013-10-18 13:33:46 +02:00
for ( int tvi = 0 ; tvi < superclassTVS . length ; tvi + + ) {
2014-09-04 16:35:44 +02:00
GenericTypeVar newGTV = new GenericTypeVar ( superclassTVS [ tvi ] . getName ( ) , parentClass , - 1 ) ;
2013-10-18 13:33:46 +02:00
supertypeGenPara . addElement ( newGTV ) ;
}
2014-10-07 15:36:18 +02:00
2013-10-18 13:33:46 +02:00
if ( supertypeGenPara . size ( ) = = 0 ) {
supertypeGenPara = null ;
}
ui . set_ParaList ( supertypeGenPara ) ;
ui . vParaOrg = supertypeGenPara ;
2014-04-01 21:38:53 +02:00
parentClass . set_UsedId ( ui ) ;
2013-10-18 13:33:46 +02:00
}
}
2014-04-01 21:38:53 +02:00
//auskommentiert von Andreas Stadelmeier
//this.addElement(myCl);
//basicAssumptions.addClassName(className);
2013-10-18 13:33:46 +02:00
for ( int j = 0 ; j < fields . length ; j + + ) {
if ( java . lang . reflect . Modifier . isPublic ( fields [ j ] . getModifiers ( ) ) ) {
2014-09-14 18:38:43 +02:00
parentClass . addField ( new FieldDeclaration ( fields [ j ] . getName ( ) , new RefType ( fields [ j ] . getType ( ) . getName ( ) , parentClass , - 1 ) ) ) ;
2013-10-18 13:33:46 +02:00
}
}
for ( int j = 0 ; j < methods . length ; j + + ) {
if ( java . lang . reflect . Modifier . isPublic ( methods [ j ] . getModifiers ( ) ) ) {
String methodName = methods [ j ] . getName ( ) ;
2014-08-07 16:09:07 +02:00
//if(methodName.equals("add")){
2014-04-09 14:12:55 +02:00
2013-10-18 13:33:46 +02:00
java . lang . reflect . Type genericReturnType = methods [ j ] . getGenericReturnType ( ) ;
2014-09-04 16:35:44 +02:00
Type returnType = createTypeFromJavaGenericType ( genericReturnType , methods [ j ] . getReturnType ( ) , jreSpiderRegistry , parentClass ) ;
2014-09-03 10:42:12 +02:00
2013-10-18 13:33:46 +02:00
java . lang . reflect . Type [ ] gpt = methods [ j ] . getGenericParameterTypes ( ) ;
java . lang . Class [ ] pt = methods [ j ] . getParameterTypes ( ) ;
2015-04-22 21:40:22 +02:00
//CMethodTypeAssumption method = new CMethodTypeAssumption(new RefType(className, 0), methodName, returnType, pt.length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>(),null);
2014-09-02 10:33:54 +02:00
Method method = de . dhbwstuttgart . syntaxtree . Method . createEmptyMethod ( methodName , parentClass ) ;
2014-04-03 10:35:25 +02:00
method . setType ( returnType ) ;
ParameterList parameterList = new ParameterList ( ) ;
2013-10-18 13:33:46 +02:00
for ( int k = 0 ; k < gpt . length ; k + + ) {
2014-09-04 16:35:44 +02:00
Type type = createTypeFromJavaGenericType ( gpt [ k ] , pt [ k ] , jreSpiderRegistry , parentClass ) ;
2013-10-18 13:33:46 +02:00
// Fixme HOTI beachte overloaded id
2015-04-22 21:40:22 +02:00
//method.addParaAssumption(new CParaTypeAssumption(className, methodName, pt.length,0,type.getName(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
2014-04-03 10:35:25 +02:00
FormalParameter parameter = new FormalParameter ( new DeclId ( type . get_Name ( ) ) ) ;
parameter . setType ( type ) ;
parameterList . formalparameter . add ( parameter ) ;
2013-10-18 13:33:46 +02:00
}
2014-04-03 10:35:25 +02:00
method . setParameterList ( parameterList ) ;
2014-04-01 21:38:53 +02:00
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
2015-02-25 18:29:44 +01:00
2014-04-03 10:35:25 +02:00
parentClass . addField ( method ) ;
2014-04-09 14:12:55 +02:00
2014-08-07 16:09:07 +02:00
//}
2014-04-09 14:12:55 +02:00
}
2013-10-18 13:33:46 +02:00
}
for ( int j = 0 ; j < constructors . length ; j + + ) {
2014-09-14 18:38:43 +02:00
String methodName = className ;
Method constructorMethod = de . dhbwstuttgart . syntaxtree . Method . createEmptyMethod ( methodName , parentClass ) ;
2013-10-18 13:33:46 +02:00
if ( java . lang . reflect . Modifier . isPublic ( constructors [ j ] . getModifiers ( ) ) ) {
2014-08-28 18:42:40 +02:00
ParameterList paraList = new ParameterList ( ) ;
2013-10-18 13:33:46 +02:00
for ( int k = 0 ; k < constructors [ j ] . getParameterTypes ( ) . length ; k + + ) {
String paraType = constructors [ j ] . getParameterTypes ( ) [ k ] . getName ( ) ;
//String paraType=constructors[j].getParameterTypes()[k].getSimpleName();
2014-08-28 18:42:40 +02:00
// Fixme HOTI beachte overloaded id
FormalParameter fpara = new FormalParameter ( new DeclId ( " p " + k ) ) ;
2014-09-14 18:38:43 +02:00
fpara . setType ( new RefType ( paraType , constructorMethod , - 1 ) ) ;
2014-08-28 18:42:40 +02:00
paraList . formalparameter . add ( fpara ) ;
2013-10-18 13:33:46 +02:00
}
2014-04-01 21:38:53 +02:00
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
2014-08-28 18:42:40 +02:00
constructorMethod . parameterlist = paraList ;
2015-08-27 13:36:14 +02:00
Constructor constructor = new Constructor ( constructorMethod , parentClass ) ;
2015-02-25 18:29:44 +01:00
constructor . parserPostProcessing ( parentClass ) ;
parentClass . addField ( constructor ) ;
2013-10-18 13:33:46 +02:00
}
}
2014-04-03 10:35:25 +02:00
basicAssumptions . add ( parentClass . getPublicFieldAssumptions ( ) ) ;
basicAssumptions . addClassAssumption ( new ClassAssumption ( parentClass ) ) ;
2013-10-18 13:33:46 +02:00
imports . removeElement ( importDecl ) ;
doneImports . addElement ( importDecl ) ;
}
imports . addAll ( doneImports ) ;
return basicAssumptions ;
2014-04-01 21:38:53 +02:00
//*/
2013-10-18 13:33:46 +02:00
}
// ino.end
2014-10-01 17:12:16 +02:00
private Class getSuperClassOfJREClass ( java . lang . Class < ? > x , TypeAssumptions ass ) {
Class ret ;
java . lang . Class s = x . getSuperclass ( ) ;
2014-10-07 10:47:52 +02:00
if ( s = = null ) {
return new Class ( " java.lang.Object " , new Modifiers ( ) , 0 ) ;
}
2014-10-07 15:36:18 +02:00
2015-05-12 19:49:27 +02:00
Menge < String > supertypeGenPara = new Menge < > ( ) ; //Die Generischen Parameter für die Superklasse berechnen:
2014-10-07 15:36:18 +02:00
java . lang . reflect . TypeVariable [ ] superclassTVS = s . getTypeParameters ( ) ;
for ( int tvi = 0 ; tvi < superclassTVS . length ; tvi + + ) {
supertypeGenPara . addElement ( superclassTVS [ tvi ] . getName ( ) ) ;
}
2014-10-01 17:12:16 +02:00
Class ss = this . getSuperClassOfJREClass ( s , ass ) ;
2014-10-07 15:36:18 +02:00
ret = new Class ( s . getName ( ) , ss . getType ( ) , new Modifiers ( ) , supertypeGenPara ) ;
2014-10-07 10:47:52 +02:00
2014-10-07 15:36:18 +02:00
2015-05-12 19:49:27 +02:00
ass . addClassAssumption ( new ClassAssumption ( ss ) ) ; //Die beiden SuperKlassen den Assumptions anfügen...
2014-10-07 10:47:52 +02:00
ass . addClassAssumption ( new ClassAssumption ( ret ) ) ;
2014-10-01 17:12:16 +02:00
return ret ;
}
2013-10-18 13:33:46 +02:00
2014-10-01 17:12:16 +02:00
// ino.method.isBaseType.21412.definition
2013-10-18 13:33:46 +02:00
private boolean isBaseType ( String type )
// ino.end
// ino.method.isBaseType.21412.body
{
return baseTypeTranslationTable . containsValue ( type ) ;
}
// ino.end
2015-04-22 21:40:22 +02:00
/ * Die contains Methode des Menges vergleicht bei Strings nicht korrekt ,
2013-10-18 13:33:46 +02:00
* da zwei Strings mit dem gleichen Inhalt unterschiedliche Instanzen sind .
* Deshalb diese Methode 07 - 01 - 20 luar * /
2015-04-22 21:40:22 +02:00
private boolean containsString ( Menge < UsedId > searchMenge , String searchString )
2013-10-18 13:33:46 +02:00
{
boolean found = false ;
2015-04-22 21:40:22 +02:00
for ( UsedId id : searchMenge )
2013-10-18 13:33:46 +02:00
{
2014-09-02 18:49:19 +02:00
String s = id . getQualifiedName ( ) . toString ( ) ;
2013-10-18 13:33:46 +02:00
found | = s . equals ( searchString ) ;
}
return found ;
}
// ino.method.createTypeFromJavaGenericType.21415.definition
2014-09-04 16:35:44 +02:00
private Type createTypeFromJavaGenericType ( java . lang . reflect . Type type , java . lang . Class < ? > cl , Hashtable < String , GenericTypeVar > jreSpiderRegistry , Class parentClass )
2013-10-18 13:33:46 +02:00
// ino.end
// ino.method.createTypeFromJavaGenericType.21415.body
{
2015-05-12 19:49:27 +02:00
/ * auskommentiert , da die Klassen von Sun in der Open JDK 1 . 8 nicht unterstà ¼ tzt werden .
2013-10-18 13:33:46 +02:00
if ( type instanceof TypeVariableImpl ) {
2014-10-01 17:12:16 +02:00
TypeVariableImpl tvi = ( ( TypeVariableImpl ) type ) ;
2014-09-04 16:35:44 +02:00
return ( new GenericTypeVar ( jreSpiderRegistry . get ( tvi . getName ( ) ) . getName ( ) . toString ( ) , parentClass , - 1 ) ) ;
2013-10-18 13:33:46 +02:00
} else {
2014-10-01 17:12:16 +02:00
* /
2014-10-07 15:36:18 +02:00
GenericTypeVar gtv = jreSpiderRegistry . get ( type . getTypeName ( ) ) ;
if ( gtv ! = null ) return gtv ;
//new GenericTypeVar(jreSpiderRegistry.get(type.getTypeName()).getName().toString(),parentClass,-1));
//String jccNameForClass=baseTypeTranslationTable.get(cl.getSimpleName());
String jccNameForClass = baseTypeTranslationTable . get ( cl . getName ( ) ) ;
if ( cl . getSimpleName ( ) . equalsIgnoreCase ( " void " ) ) {
return ( new Void ( parentClass , - 1 ) ) ;
} else if ( jccNameForClass ! = null ) {
RefType rt = new RefType ( jccNameForClass , parentClass , - 1 ) ;
rt . setPrimitiveFlag ( true ) ;
return ( rt ) ;
} else {
//return(new RefType(cl.getSimpleName()));
return ( new RefType ( cl . getName ( ) , parentClass , - 1 ) ) ;
}
2014-10-01 17:12:16 +02:00
//}
2013-10-18 13:33:46 +02:00
}
// ino.end
// ino.method.makeBasicAssumptions.21418.defdescription type=javadoc
/ * *
2015-05-12 19:49:27 +02:00
* Erzeugt die Anfangsinformationen à ¯  ¿  ½ ber bereits bekannte Klassen .
* < br / > Achtung Workaround : Die RefTypes mà ¯  ¿  ½ ssen spà ¯  ¿  ½ ter noch durch BaseTypes
2013-10-18 13:33:46 +02:00
* ersetzt werden . < br >
2015-05-12 19:49:27 +02:00
* Author : JÃ ¯ Â ¿ Â ½ rg BÃ ¯ Â ¿ Â ½ uerle
2013-10-18 13:33:46 +02:00
*
* @return A priori Typinformationen
* @throws ClassNotFoundException
* /
// ino.end
// ino.method.makeBasicAssumptions.21418.definition
2014-04-14 18:05:24 +02:00
private TypeAssumptions makeBasicAssumptions ( )
2013-10-18 13:33:46 +02:00
// ino.end
// ino.method.makeBasicAssumptions.21418.body
{
2014-02-09 16:07:31 +01:00
/ *
2013-10-18 13:33:46 +02:00
if ( LOAD_BASIC_ASSUMPTIONS_FROM_JRE ) {
2015-04-22 21:40:22 +02:00
Menge < UsedId > strImports = new Menge < UsedId > ( ) ;
2013-10-18 13:33:46 +02:00
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 ) ;
}
}
2014-02-09 16:07:31 +01:00
TypeinferenceResultSet res = makeBasicAssumptionsFromJRE ( strImports ) ;
2013-10-18 13:33:46 +02:00
ImportDeclarations newImports = new ImportDeclarations ( ) ;
for ( int i = 0 ; i < strImports . size ( ) ; i + + ) {
newImports . addElement ( strImports . get ( i ) ) ;
}
setImports ( newImports ) ;
return ( res ) ;
}
2014-02-09 16:07:31 +01:00
TypeinferenceResultSet foo = new TypeinferenceResultSet ( null ) ;
2013-10-18 13:33:46 +02:00
CMethodTypeAssumption meth = null ;
CInstVarTypeAssumption instVar = null ;
Class c = null ;
UsedId ui = null ;
2015-04-22 21:40:22 +02:00
//Menge pl = null;
2013-10-18 13:33:46 +02:00
Modifiers mod = new Modifiers ( ) ;
mod . addModifier ( new Public ( ) ) ;
//------------------------
// Integer bauen:
//------------------------
foo . addClassName ( " java.lang.Integer " ) ; //PL 05-08-01 eingefuegt
2015-04-22 21:40:22 +02:00
instVar = new CInstVarTypeAssumption ( " java.lang.Integer " , " MAX_VALUE " , new RefType ( " java.lang.Integer " , - 1 ) , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) ) ;
2013-10-18 13:33:46 +02:00
foo . addFieldOrLocalVarAssumption ( instVar ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Integer " , 0 ) , " <init> " , new RefType ( " java.lang.Integer " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Integer " , 0 ) , " <init> " , new RefType ( " java.lang.Integer " , - 1 ) , 1 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < 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 Menge < Integer > ( ) ) ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Integer " , 0 ) , " intValue " , new RefType ( " java.lang.Integer " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
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);
2015-04-22 21:40:22 +02:00
// pl = new Menge();
2013-10-18 13:33:46 +02:00
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this . addElement ( c ) ;
//------------------------
// Boolean bauen:
//------------------------
foo . addClassName ( " java.lang.Boolean " ) ; //PL 05-08-01 eingefuegt
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Boolean " , 0 ) , " <init> " , new RefType ( " java.lang.Boolean " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Boolean " , 0 ) , " <init> " , new RefType ( " java.lang.Boolean " , - 1 ) , 1 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < 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 Menge < Integer > ( ) ) ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Boolean " , 0 ) , " booleanValue " , new RefType ( " java.lang.Boolean " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
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);
2015-04-22 21:40:22 +02:00
// pl = new Menge();
2013-10-18 13:33:46 +02:00
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this . addElement ( c ) ;
//------------------------
// Character bauen:
//------------------------
foo . addClassName ( " java.lang.Character " ) ; //PL 05-08-01 eingefuegt
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Character " , 0 ) , " <init> " , new RefType ( " java.lang.Character " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Character " , 0 ) , " <init> " , new RefType ( " java.lang.Character " , - 1 ) , 1 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < 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 Menge < Integer > ( ) ) ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Character " , 0 ) , " charValue " , new BooleanType ( ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
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);
2015-04-22 21:40:22 +02:00
// pl = new Menge();
2013-10-18 13:33:46 +02:00
// pl.addElement(new GenericTypeVar("bla"));
// c.set_ParaList(pl);
this . addElement ( c ) ;
//------------------------
2015-04-22 21:40:22 +02:00
// Menge bauen:
2013-10-18 13:33:46 +02:00
//------------------------
2015-04-22 21:40:22 +02:00
foo . addClassName ( " java.lang.Menge " ) ; //PL 05-08-01 eingefuegt
2015-05-12 19:49:27 +02:00
TypePlaceholder E = TypePlaceholder . fresh ( ) ; // Sp�ter ersetzen durch GenericTypeVar
2015-04-22 21:40:22 +02:00
Menge < GenericTypeVar > typeGenPara = new Menge < GenericTypeVar > ( ) ;
2013-10-18 13:33:46 +02:00
typeGenPara . addElement ( new GenericTypeVar ( E . getName ( ) , - 1 ) ) ;
2015-04-22 21:40:22 +02:00
foo . addGenericTypeVars ( " java.lang.Menge " , typeGenPara ) ;
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Menge " , 0 ) , " elementAt " , new GenericTypeVar ( E . getName ( ) , - 1 ) , 1 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
meth . addParaAssumption ( new CParaTypeAssumption ( " java.lang.Menge " , " elementAt " , 1 , 0 , " index " , new RefType ( " java.lang.Integer " , - 1 ) , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) ) ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Menge " , 0 ) , " addElement " , new Void ( - 1 ) , 1 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
meth . addParaAssumption ( new CParaTypeAssumption ( " java.lang.Menge " , " addElement " , 1 , 0 , " element " , new GenericTypeVar ( E . getName ( ) , - 1 ) , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) ) ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
meth = new CMethodTypeAssumption ( new RefType ( " java.lang.Menge " , 0 ) , " size " , new RefType ( " java.lang.Integer " , - 1 ) , 0 , MyCompiler . NO_LINENUMBER , MyCompiler . NO_LINENUMBER , new Menge < Integer > ( ) , null ) ;
2013-10-18 13:33:46 +02:00
foo . addMethodIntersectionType ( new CIntersectionType ( meth ) ) ;
2015-04-22 21:40:22 +02:00
c = new BasicAssumptionClass ( " java.lang.Menge " , mod ) ;
2013-10-18 13:33:46 +02:00
// ui = new UsedId();
// ui.set_Name("Super-Class-Blub");
// c.set_UsedId(ui);
2015-04-22 21:40:22 +02:00
// pl = new Menge();
2013-10-18 13:33:46 +02:00
// 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 ) ;
2015-04-22 21:40:22 +02:00
ui . set_Name ( " java.lang.Menge " ) ;
2013-10-18 13:33:46 +02:00
c . set_UsedId ( ui ) ;
2015-04-22 21:40:22 +02:00
// pl = new Menge();
2013-10-18 13:33:46 +02:00
// pl.addElement(E);
// c.set_ParaList(pl);
this . addElement ( c ) ;
return foo ;
2014-02-09 16:07:31 +01:00
* /
2014-03-18 20:18:57 +01:00
TypeAssumptions ret = new TypeAssumptions ( ) ;
2015-05-12 19:49:27 +02:00
//Basic Assumptions für die FunN Interfaces:
2014-03-26 23:28:17 +01:00
//TODO: Hier mehr als Fun1-Fun5 implementieren
for ( int i = 0 ; i < 6 ; i + + ) {
FunNInterface funN = new FunNInterface ( i ) ;
ret . add ( funN . getPublicFieldAssumptions ( ) ) ;
}
2015-05-12 19:49:27 +02:00
return ret ; //TODO: Diese TypeAssumptions mit basic-Assumptions füllen
2013-10-18 13:33:46 +02: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
/ * *
2015-05-12 19:49:27 +02:00
* LÃ ¯ Â ¿ Â ½ scht die Anfangsinformation wieder aus dem Klassenvektor
* < br / > Author : JÃ ¯ Â ¿ Â ½ rg BÃ ¯ Â ¿ Â ½ uerle
2013-10-18 13:33:46 +02:00
* /
// 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
/ * *
2015-05-12 19:49:27 +02:00
* Erzeugt fà ¯  ¿  ½ r jede Klasse einen Menge , in den Referenzen auf die GenericTypeVars
2015-04-22 21:40:22 +02:00
* dieser Klasse gespeichert werden . Diese Mengeen werden unter den Klassennamen
2013-10-18 13:33:46 +02:00
* in der
2015-05-12 19:49:27 +02:00
* Ergebnisdatenstruktur abgelegt . Auà ¯  ¿  ½ erdem werden alle Klassennamen gespeichert .
* < br / > Author : JÃ ¯ Â ¿ Â ½ rg BÃ ¯ Â ¿ Â ½ uerle
2013-10-18 13:33:46 +02:00
* @param res
* /
* / * private void addClassNamesAndGenericsToRR ( CTypeReconstructionResult res ) {
* Iterator < Class > it = this . getClassIterator ( ) ;
* while ( it . hasNext ( ) ) {
* Class cl = it . next ( ) ;
* res . addClassName ( cl . get_classname ( ) ) ;
2015-04-22 21:40:22 +02:00
* Menge < GenericTypeVar > genericsList = new Menge < GenericTypeVar > ( ) ;
2013-10-18 13:33:46 +02:00
*
* 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
2014-02-11 16:30:38 +01:00
@Override
public void parserPostProcessing ( SyntaxTreeNode parent ) {
2014-04-15 14:56:20 +02:00
if ( parent ! = null ) throw new DebugException ( " Eine SourceFile hat kein Elternelement im Syntaxbaum " ) ;
2015-08-26 14:48:51 +02:00
super . parserPostProcessing ( this ) ;
2014-02-19 23:04:48 +01:00
//for(SyntaxTreeNode node : this.getChildren())node.parserPostProcessing(this);
2014-02-11 16:30:38 +01:00
}
@Override
public SyntaxTreeNode getParent ( ) {
return null ;
}
@Override
2015-04-22 21:40:22 +02:00
public Menge < SyntaxTreeNode > getChildren ( ) {
Menge < SyntaxTreeNode > ret = new Menge < SyntaxTreeNode > ( ) ;
2014-02-12 02:12:12 +01:00
for ( Class cl : this . KlassenVektor ) {
ret . add ( cl ) ;
}
return ret ;
2014-02-11 16:30:38 +01:00
}
/ * *
* SourceFile stellt eine geparste Java - Datei dar . Mit dieser Methode wird der Name der eingelesenen Datei gesetzt .
* @param filename - Der Name der eingelesenen JavaDatei
* /
2014-03-07 22:05:10 +01:00
@Deprecated
2014-02-11 16:30:38 +01:00
public void setFileName ( String filename ) {
2014-03-07 22:05:10 +01:00
//this.filename = filename;
2014-02-11 16:30:38 +01:00
}
2014-09-08 15:12:47 +02:00
@Override
public int getOffset ( ) {
// TODO Auto-generated method stub
return 0 ;
}
@Override
public int getVariableLength ( ) {
// TODO Auto-generated method stub
return 0 ;
}
2015-08-27 13:36:14 +02:00
/ * *
* Bisher wird nur der Bytecode der Klassen generiert . Nicht der Interfaces .
* @return
* /
2015-11-06 16:42:22 +01:00
public Menge < ByteCodeResult > generateBytecode ( TypeinferenceResults results ) {
2015-10-22 20:40:33 +02:00
Menge < ByteCodeResult > ret = new Menge < > ( ) ;
2015-08-27 13:36:14 +02:00
for ( Class cl : this . KlassenVektor ) {
2015-11-06 16:42:22 +01:00
ret . add ( cl . genByteCode ( results ) ) ;
2015-08-27 13:36:14 +02:00
}
return ret ;
}
2013-10-18 13:33:46 +02:00
}
// ino.end