forked from JavaTX/JavaCompilerCore
Aufräumen SourceFile
This commit is contained in:
parent
a8d8dec899
commit
e061dea7f5
@ -770,7 +770,7 @@ public class SourceFile
|
||||
.map(i -> constraintsClone.elementAt(i))
|
||||
.<Menge<Pair>>collect(Menge::new, Menge::add, Menge::addAll));
|
||||
//Menge<Menge<Pair>> vecconstraintsclone = streamconstraintsclone.collect(Menge::new, Menge::add, Menge::addAll);
|
||||
System.out.println();
|
||||
//System.out.println();
|
||||
//Schritt 4: Unifikation
|
||||
Menge<Menge<Menge<Pair>>> vecunifyResult =
|
||||
//streamconstraintsclone.map(x -> Unify.unify(x, finiteClosure)).collect(Menge::new, Menge::add, Menge::addAll);
|
||||
@ -814,6 +814,7 @@ public class SourceFile
|
||||
});
|
||||
|
||||
//Dann den Ergebnissen anfügen
|
||||
typinferenzLog.debug("\nErgebnis der Unifizierung:\n"+unifyResult, Section.TYPEINFERENCE);
|
||||
result.addAll(unifyResult);
|
||||
|
||||
typinferenzLog.debug("\nJavaFiles:\n", Section.TYPEINFERENCE);
|
||||
@ -841,281 +842,7 @@ public class SourceFile
|
||||
if(!this.KlassenVektor.isEmpty())throw new TypeinferenceException("Fehler in Typinferierung", this.KlassenVektor.firstElement());
|
||||
}
|
||||
return ret;
|
||||
/*
|
||||
// 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);
|
||||
|
||||
Menge<TypeinferenceResultSet> A = new Menge<TypeinferenceResultSet>();
|
||||
|
||||
TypeAssumptions basics;
|
||||
|
||||
basics = this.makeBasicAssumptions();
|
||||
|
||||
//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. Menge in de.dhbwstuttgart.typeinference.Menge
|
||||
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("������������������������������������");
|
||||
FC_TTO finiteClosure = this.makeFC();
|
||||
inferencelog.info("������������������������������������");
|
||||
inferencelog.info("Bin aus \"SourceFile.makeFC()\" zur�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);
|
||||
}
|
||||
|
||||
// Fuer jede Klasse die Assumptions der öffentlichen Felder zusammentragen:
|
||||
TypeAssumptions publicFieldsAssumptions = new TypeAssumptions();
|
||||
for(Class cl : KlassenVektor){
|
||||
publicFieldsAssumptions.add(cl.getPublicFieldAssumptions());
|
||||
}
|
||||
|
||||
// Die BasicAssumptions anfü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()...");
|
||||
A.addAll(cl.typeReconstruction(supportData, publicFieldsAssumptions));
|
||||
}
|
||||
|
||||
return A;
|
||||
*/
|
||||
}
|
||||
// ino.end
|
||||
|
||||
/**
|
||||
* Erstellt die Basic Assumptions (siehe MakeBasicAssumptions) als AssumptionSet
|
||||
* @return
|
||||
|
||||
@Deprecated //angefügt von Andreas Stadelmeier. Grund: Die Funktion wurde neu als makeBasicAssumptionsFromJRE angelegt
|
||||
private TypeAssumptions getBasicAssumptions() {
|
||||
TypeAssumptions ret = new TypeAssumptions(null);
|
||||
|
||||
// AB hier der Teil aus makeBasicAssumptionsFromJRE:
|
||||
Menge<UsedId> doneImports=new Menge<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().toString());
|
||||
} 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>();
|
||||
Menge<GenericTypeVar> typeGenPara = new Menge<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((Menge)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 Menge.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();
|
||||
Menge<Type> supertypeGenPara = new Menge<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 Menge<Integer>());
|
||||
CInstVarTypeAssumption instVar = new CInstVarTypeAssumption(className, fields[j].getName(), new RefType(fields[j].getType().getName(),-1), MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>());
|
||||
//basicAssumptions.addFieldOrLocalVarAssumption(instVar);
|
||||
//ret.add(instVar); //auskommentiert von Andreas Stadelmeier
|
||||
}
|
||||
}
|
||||
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 Menge<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().toString(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Menge<Integer>()));
|
||||
}
|
||||
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
|
||||
//ret.add(method); //auskommentiert von Andreas Stadelmeier
|
||||
}
|
||||
}
|
||||
|
||||
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 Menge<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 Menge<Integer>()));
|
||||
}
|
||||
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(constructor));
|
||||
//ret.add(constructor); //auskommentiert von Andreas Stadelmeier
|
||||
}
|
||||
}
|
||||
|
||||
imports.removeElement(importDecl);
|
||||
doneImports.addElement(importDecl);
|
||||
|
||||
}
|
||||
|
||||
imports.addAll(doneImports);
|
||||
|
||||
return ret;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Erstellt die Assumptions der standardmäÃig importierten Packages (java.lang.) sowie der von imports übergebenen Klassen zusammen.
|
||||
|
Loading…
Reference in New Issue
Block a user