Backup-commit

This commit is contained in:
JanUlrich 2014-04-03 10:35:25 +02:00
parent 38f4a1351f
commit 8d4213511d
9 changed files with 149 additions and 13 deletions

View File

@ -45,7 +45,6 @@ import mycompiler.mytypereconstruction.unify.Unify;
import org.apache.log4j.Logger;
import mycompiler.myclass.*;
import mycompiler.*;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import sun.reflect.generics.reflectiveObjects.TypeVariableImpl;
@ -55,7 +54,9 @@ import typinferenz.FunNInterface;
import typinferenz.FunNMethod;
import typinferenz.ResultSet;
import typinferenz.UndConstraint;
import typinferenz.assumptions.ClassAssumption;
import typinferenz.assumptions.MethodAssumption;
import typinferenz.assumptions.ParameterAssumption;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypinferenzException;
@ -660,6 +661,11 @@ public class SourceFile
globalAssumptions.add(klasse.getPublicFieldAssumptions());
}
//Assumptions der importierten Klassen sammeln:
TypeAssumptions importAssumptions = this.makeBasicAssumptionsFromJRE(imports);
globalAssumptions.add(importAssumptions);
typinferenzLog.debug("Von JRE erstellte Assumptions: "+importAssumptions);
ConstraintsSet oderConstraints = new ConstraintsSet();
//Alle Constraints der in dieser SourceFile enthaltenen Klassen sammeln:
for(Class klasse : KlassenVektor){
@ -904,6 +910,7 @@ public class SourceFile
* 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);
@ -1048,7 +1055,6 @@ public class SourceFile
}
// ino.method.makeBasicAssumptionsFromJRE.21409.definition
@Deprecated //angefügt von Andreas Stadelmeier. Grund: Die Funktion wurde neu als getBasicAssumptions angelegt
private TypeAssumptions makeBasicAssumptionsFromJRE(Vector<UsedId> imports)
// ino.end
// ino.method.makeBasicAssumptionsFromJRE.21409.body
@ -1147,7 +1153,7 @@ public class SourceFile
//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);
parentClass.addField(new FieldDeclaration(0));
parentClass.addField(new FieldDeclaration(fields[j].getName(),new RefType(fields[j].getType().getName(),-1)));
}
}
for(int j=0;j<methods.length;j++){
@ -1159,16 +1165,22 @@ public class SourceFile
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);
//CMethodTypeAssumption method = new CMethodTypeAssumption(new RefType(className, 0), methodName, returnType, pt.length,MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>(),null);
Method method = mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass);
method.setType(returnType);
ParameterList parameterList = new ParameterList();
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>()));
//method.addParaAssumption(new CParaTypeAssumption(className, methodName, pt.length,0,type.getName(), type, MyCompiler.NO_LINENUMBER,MyCompiler.NO_LINENUMBER,new Vector<Integer>()));
FormalParameter parameter = new FormalParameter(new DeclId(type.get_Name()));
parameter.setType(type);
parameterList.formalparameter.add(parameter);
}
method.setParameterList(parameterList);
//basicAssumptions.addMethodIntersectionType(new CIntersectionType(method));
parentClass.addField(mycompiler.myclass.Method.createEmptyMethod(methodName, parentClass));
parentClass.addField(method);
}
}
@ -1187,12 +1199,13 @@ public class SourceFile
parentClass.addField(new Constructor(constructorMethod));
}
}
basicAssumptions.add(parentClass.getPublicFieldAssumptions());
basicAssumptions.addClassAssumption(new ClassAssumption(parentClass));
imports.removeElement(importDecl);
doneImports.addElement(importDecl);
}
imports.addAll(doneImports);
return basicAssumptions;
//*/

View File

@ -30,6 +30,16 @@ public class FieldDeclaration extends Field{
private Expr wert;
//private Type type;
/**
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
* Kein nachträgliches hinzfügen von Informationen oder aufrufen von parserPostProcessing ist notwendig.
*/
public FieldDeclaration(String name, Type typ){
super(0);//Dieser Deklarator wird nicht vom Parser aufgerufen. Dadurch gibt es auch keinen Offset
this.setType(typ);
this.set_DeclId(new DeclId(name));
}
public FieldDeclaration(int offset){
super(offset);
}
@ -117,6 +127,7 @@ public class FieldDeclaration extends Field{
@Override
public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) {
ConstraintsSet ret = new ConstraintsSet();
this.setType(publicAssumptions.getTypeFor(this.getType()));
SingleConstraint c1 = new SingleConstraint(this.getType(), this.getType());
ret.add(c1); //Damit die TypVariable des Felds in den Constraints auftaucht

View File

@ -465,7 +465,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
// ino.end
// ino.method.toString.23605.body
{
return this.getType() + " " +( (block!=null)?block.toString():"");
return this.getType() + " "+ this.get_Name() +( (block!=null)?block.toString():"");
}
// ino.end
@ -537,11 +537,13 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
public ConstraintsSet TYPE(TypeAssumptions ass) {
this.returntype = ass.getTypeFor(this.returntype);
ConstraintsSet ret = new ConstraintsSet();
TypeAssumptions localAss = new TypeAssumptions();
localAss.add(ass); //Die globalen Assumptions anhängen
//Die Parameter zu den Assumptions hinzufügen:
if(this.parameterlist!=null)for(FormalParameter param : this.parameterlist){
param.setType(ass.getTypeFor(param.getType()));
localAss.addParameterAssumption(new ParameterAssumption(param));
}
ret.add(this.block.TYPEStmt(localAss));

View File

@ -460,13 +460,19 @@ public class LocalVarDecl extends Statement implements TypeInsertable
@Override
public ConstraintsSet TYPEStmt(TypeAssumptions assumptions) {
ConstraintsSet ret = new ConstraintsSet();
if(this.getType()==null || this.getType() instanceof TypePlaceholder)this.setType(TypePlaceholder.fresh(this));
this.setType(assumptions.getTypeFor(this.getType()));
assumptions.addLocalVarAssumption(new LocalVarAssumption(this));
//assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden.
this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void
return ret;
}
@Override
public void parserPostProcessing(SyntaxTreeNode parent) {
super.parserPostProcessing(parent);
if(this.getType()==null || this.getType() instanceof TypePlaceholder)this.setType(TypePlaceholder.fresh(this));
}
@Override
public String getTypeInformation(){
String ret = "VarDeclaration ";

View File

@ -7,6 +7,7 @@ import java.util.Vector;
// ino.end
import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
@ -140,6 +141,16 @@ public class GenericTypeVar extends Type
return this.tph;
}
@Override
public String get_Name() {
return this.getName();
}
@Override
public String getName() {
return this.name;
}
}
// ino.end

View File

@ -0,0 +1,22 @@
package typinferenz.assumptions;
import mycompiler.myclass.*;
import mycompiler.myclass.Class;
import mycompiler.mytype.*;
public class ClassAssumption {
private Class classType;
public ClassAssumption(Class cls){
this.classType = cls;
}
public Class getAssumedClass(){
return classType;
}
public String toString(){
return this.classType.getName();
}
}

View File

@ -52,6 +52,7 @@ public class TypeAssumptions {
private Vector<FieldAssumption> fieldAssumptions = new Vector<FieldAssumption>();
private Vector<LocalVarAssumption> localVarAssumptions = new Vector<LocalVarAssumption>();
private Vector<ParameterAssumption> parameterAssumptions = new Vector<ParameterAssumption>();
private Vector<ClassAssumption> classAssumptions = new Vector<ClassAssumption>();
/**
@ -229,6 +230,7 @@ public class TypeAssumptions {
for(Assumption f : this.methodAssumptions)ret.add(f);
for(Assumption f : this.fieldAssumptions)ret.add(f);
for(Assumption f : this.parameterAssumptions)ret.add(f);
for(Assumption f : this.constructorAssumptions)ret.add(f);
return ret;
}
@ -237,7 +239,8 @@ public class TypeAssumptions {
this.fieldAssumptions.addAll(assumptions.fieldAssumptions);
this.localVarAssumptions.addAll(assumptions.localVarAssumptions);
this.parameterAssumptions.addAll(assumptions.parameterAssumptions);
this.constructorAssumptions.addAll(assumptions.constructorAssumptions);
this.classAssumptions.addAll(assumptions.classAssumptions);
return this;
}
@ -254,11 +257,13 @@ public class TypeAssumptions {
@Override
public String toString(){
String ret = "this: "+this.thisClassName;
String ret = "this: "+this.thisClassName+"\n";
ret += "Method Assumptions:\n" + this.methodAssumptions.toString() + "\n";
ret += "FieldVar Assumptions:\n" + this.fieldAssumptions.toString() + "\n";
ret += "LocalVar Assumptions:\n" + this.localVarAssumptions.toString() + "\n";
ret += "Parameter Assumptions:\n" + this.parameterAssumptions.toString() + "\n";
ret += "Konstruktor Assumptions:\n" + this.constructorAssumptions.toString() + "\n";
ret += "Class Assumptions:\n" + this.classAssumptions.toString() + "\n";
//return assumptions.toString();
return ret;
}
@ -269,6 +274,44 @@ public class TypeAssumptions {
return new RefType(thisClassName, 0);
}
/**
* Kontrolliert den vom Parser gesetzten Typ.
* Erweitert dessen Bezeichnung, wenn nötig.
* @param t
* @return
* @throws TypinferenzException
*/
public Type getTypeFor(Type t) throws TypinferenzException{
String typName = t.getName();
String[] names = typName.split("[.]");
for(ClassAssumption ass : this.classAssumptions){
String name = ass.getAssumedClass().getName(); //Das kann auch java.util.Vector sein
String[] assNames = name.split("[.]");
boolean match = true;
if(names.length == 1){
match = names[0].equals(assNames[assNames.length-1]);
}else if(names.length == 0 || names.length != assNames.length){
match = false;
}else for(int i = names.length-1; i>-1;i--){
if(!names.equals(assNames))match = false;
}
if(match){
return ass.getAssumedClass().getType();
}
}
throw new TypinferenzException("Der Typ "+t.getName()+" ist nicht korrekt");
}
/**
* Fügt eine TypAssumption an.
* Dadurch wird ein Pool von Typen aufgebaut, welche überhaupt erlaubt sind.
* Wird genutzt um vom Parser eingelesene Typen auf ihre Korrektheit zu kontrollieren.
* @param classAssumption
*/
public void addClassAssumption(ClassAssumption classAssumption) {
this.classAssumptions.add(classAssumption);
}
/**
* Prüft einen Typ auf das vorhandensein in den BasicAssumptions.
* Dabei werden alle Konstruktoren nach diesem Typ durchsucht. Denn jede Klasse hat einen Konstruktor und der muss in den TypeAssumptions vorhanden sein.

View File

@ -0,0 +1,10 @@
import java.util.Vector;
class ImportTest{
Vector<String> var;
var2;
methode(){
var.add(var2);
}
}

View File

@ -0,0 +1,18 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class ImportTest {
private static final String TEST_FILE = "ImportTest.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
mustContain.add("String var2");
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
}
}