Fehler beseitigen

This commit is contained in:
JanUlrich 2014-07-16 18:38:55 +02:00
parent 26d3a89fd9
commit 45d176aed2
11 changed files with 43 additions and 17 deletions

View File

@ -56,8 +56,10 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
@Override
public Iterable<GenericTypeVar> getGenericParameter() {
if(this.genericParameters == null)return new Vector<GenericTypeVar>();
return this.genericParameters;
Vector<GenericTypeVar> ret = new Vector<>();
if(this.genericParameters == null)return ret;
ret.addAll(this.genericParameters);
return ret;
}
public void set_DeclId(DeclId did)
@ -157,4 +159,5 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
public void setGenericParameter(GenericDeclarationList params) {
this.genericParameters = params;
}
}

View File

@ -129,6 +129,15 @@ public class FieldDeclaration extends Field{
@Override
public ConstraintsSet TYPE(TypeAssumptions publicAssumptions) {
ConstraintsSet ret = new ConstraintsSet();
TypeAssumptions localAssumptions = publicAssumptions.clone();
for(GenericTypeVar gp : this.getGenericParameter()){
localAssumptions.add(gp.createAssumptions());
}
for(GenericTypeVar gp : this.getGenericParameter()){
gp.TYPE(localAssumptions);
}
/*
if(this.getType() instanceof GenericTypeVar){
//Falls Typ ein GTV ist muss er syntaktisch kontrolliert werden...
@ -137,7 +146,7 @@ public class FieldDeclaration extends Field{
*/
//TypeCheck, falls es sich um einen RefType handelt:
this.getType().checkType(publicAssumptions, this);
this.getType().checkType(localAssumptions, this);
/*
if(this.getType()!=null && (this.getType() instanceof RefType)){
Type replaceType = null;
@ -152,7 +161,7 @@ public class FieldDeclaration extends Field{
if(this.wert!=null){
//Falls bei der Deklaration ein Wert zugewiesen wird, verhält sich das Constraintserzeugen wie bei dem Assign-Statement:
ret.add(this.wert.TYPEExpr(publicAssumptions));
ret.add(this.wert.TYPEExpr(localAssumptions));
ret.add(new SingleConstraint(this.wert.getType(), this.getType()));
}
return ret;

View File

@ -553,6 +553,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
TypeAssumptions localAss = new TypeAssumptions();
localAss.add(ass); //Die globalen Assumptions anhängen
//Generische Parameterdeklarationen den Assumptions anfügen:
for(GenericTypeVar gtv : this.getGenericParameter()){
localAss.add(gtv.createAssumptions());
}
for(GenericTypeVar gtv : this.getGenericParameter()){
ret.add(gtv.TYPE(localAss));
}

View File

@ -11,6 +11,7 @@ import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import typinferenz.ConstraintsSet;
import typinferenz.SingleConstraint;
import typinferenz.assumptions.TypeAssumptions;
import typinferenz.exceptions.TypeinferenceException;
// ino.class.BoundedGenericTypeVar.26464.description type=javadoc
/**
@ -75,11 +76,13 @@ public class BoundedGenericTypeVar extends GenericTypeVar
@Override
public ConstraintsSet TYPE(TypeAssumptions ass) {
ConstraintsSet ret = super.TYPE(ass);
ass.addGenericVarAssumption(this);
//ass.addGenericVarAssumption(this);
//Die Type methode der BoundedGenericTypeVar schreibt zusätzlich noch die Constraints für die bounds
if(this.bounds != null){
for(Type ev : this.bounds){
ret.add(new SingleConstraint(ass.getTypeFor(this), ass.getTypeFor(ev)));
Type extendsType = ass.getTypeFor(ev);
if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this);
ret.add(new SingleConstraint(ass.getTypeFor(this), extendsType ));
}
}
return ret;

View File

@ -199,6 +199,12 @@ public class GenericTypeVar extends Type
return this.name;
}
public TypeAssumptions createAssumptions(){
TypeAssumptions ret = new TypeAssumptions();
ret.addGenericVarAssumption(this);
return ret;
}
/**
* Die Type Methode auf generische Variablen angewandt sorgt für deren Eintragung in die TypeAssumptions.
* @param ass
@ -206,7 +212,6 @@ public class GenericTypeVar extends Type
*/
public ConstraintsSet TYPE(TypeAssumptions ass){
ConstraintsSet ret = new ConstraintsSet();
ass.addGenericVarAssumption(this);
return ret;
}

View File

@ -287,7 +287,8 @@ public class Type implements IItemWithOffset
*/
public Type checkType(TypeAssumptions ass, IItemWithOffset parent){
Type t = ass.getTypeFor(this);
if(t==null)throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
if(t==null)
throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent);
return t;
}

View File

@ -25,4 +25,5 @@ public class GenericVarAssumption extends Assumption{
public String toString(){
return this.getIdentifier() +"::"+this.getAssumedType();
}
}

View File

@ -323,6 +323,7 @@ public class TypeAssumptions {
}
//Auch die generischen Variablen durchsuchen:
for(GenericVarAssumption ass : this.genericVarAssumptions){
//if(ass.inheritsType(t))return t;
if(ass.getIdentifier().equals(t.getName()))return ass.getAssumedType();
}
@ -355,6 +356,7 @@ public class TypeAssumptions {
public void addGenericVarAssumption(
GenericTypeVar genericTypeVar) {
//TODO: Hier müssen alle Bounds einzeln geaddet werden. Die Bounds müssen hierbei nicht gespeichert werden, deren Constraints generiert die TYPE-Methode der GenericVarDeclarations
this.genericVarAssumptions.add(new GenericVarAssumption(genericTypeVar));
}

View File

@ -53,7 +53,7 @@ public class GenericTypeInsertPoint extends SourcePatchPoint {
public String getTypeInsertString() {
String genericVar = this.patch.getInsertString(this.resultSet);
if(genericVar.length()==0)return "";
return this.genericInsertPoint.getGenericVarDeclarationString(genericVar);
return this.genericInsertPoint.getGenericVarDeclarationString(genericVar)+" ";
}
/*
@ -98,7 +98,7 @@ public class GenericTypeInsertPoint extends SourcePatchPoint {
@Override
public int compareTo(SourcePatchPoint arg0) {
int ret = super.compareTo(arg0);
if(ret == 0)ret = -1;//Hack der dazu führt, dass GTIP vor anderen InsertTypes eingesetzt werden.
if(ret == 0)ret = -666;//Hack der dazu führt, dass GTIP vor anderen InsertTypes eingesetzt werden.
return ret;
}
@ -163,6 +163,11 @@ public class GenericTypeInsertPoint extends SourcePatchPoint {
public int getOffset() {
return genericInsertPoint.getGenericVarDeclarationOffset();
}
@Override
public int getInsertLength() {
return this.getTypeInsertString().length();
}
}
/**

View File

@ -17,8 +17,6 @@ public abstract class SourcePatchPoint implements Comparable<SourcePatchPoint>{
}
public abstract JavaCodeResult patch(String fileContent, int additionalOffset);
public int getInsertLength() {
return 0;
}
public abstract int getInsertLength();
}

View File

@ -66,9 +66,7 @@ public class TypeInsertSet {
*/
public String insertType(TypeInsertPoint tip, String fileContent){
TypePatchJob tpj = new TypePatchJob();
this.insertType(tip, tpj);
return tpj.run(fileContent);
}
@ -87,8 +85,6 @@ public class TypeInsertSet {
tpj.add(gip);
}
/**
* Fügt alle Typen dieses TypeInsertSets in den übergebenen Quellcode ein
* @param fileContent