diff --git a/src/mycompiler/SyntaxTreeNode.java b/src/mycompiler/SyntaxTreeNode.java index f0110158..f2c58bf6 100644 --- a/src/mycompiler/SyntaxTreeNode.java +++ b/src/mycompiler/SyntaxTreeNode.java @@ -34,7 +34,8 @@ public abstract class SyntaxTreeNode { public Class getParentClass(){ SyntaxTreeNode parent = this.getParent(); if(parent instanceof Class)return (Class)parent; - if(parent == null)throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein"); + if(parent == null) + throw new DebugException("Das Wurzelelement eines Syntaxbaumes muss Class sein"); return parent.getParentClass(); } diff --git a/src/mycompiler/myclass/Method.java b/src/mycompiler/myclass/Method.java index bcb94f15..35d220a8 100755 --- a/src/mycompiler/myclass/Method.java +++ b/src/mycompiler/myclass/Method.java @@ -500,8 +500,12 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable } @Override - public void wandleRefTypeAttributes2GenericAttributes(Vector paralist) + public void wandleRefTypeAttributes2GenericAttributes(Vector classParalist) { + Vector paralist = new Vector();//Mit den Generischen Typen der Methode + paralist.addAll(classParalist); + paralist.addAll(this.genericMethodParameters); + // Zuerst Returntype untersuchen Type returnType=getType(); Type pendantReturnType = null; @@ -561,7 +565,8 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable { Type replaceType = null; replaceType = ass.getTypeFor((RefType)param.getType()); - if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",param); + if(replaceType == null) + throw new TypeinferenceException("Der Typ "+param.getType().getName()+" ist nicht korrekt",param); param.setType(replaceType); } @@ -592,6 +597,9 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable return ret; } + /** + * Liefert die MethodAssumption zu dieser Methode + */ @Override public TypeAssumptions createTypeAssumptions(Class classmember) { Class parentClass = this.getParentClass(); diff --git a/src/mycompiler/mystatement/LocalVarDecl.java b/src/mycompiler/mystatement/LocalVarDecl.java index 049bc521..f42e172c 100755 --- a/src/mycompiler/mystatement/LocalVarDecl.java +++ b/src/mycompiler/mystatement/LocalVarDecl.java @@ -468,10 +468,11 @@ public class LocalVarDecl extends Statement implements TypeInsertable if((this.getType() instanceof RefType)){ Type replaceType = null; replaceType = assumptions.getTypeFor((RefType)this.getType()); - if(replaceType == null)throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); + if(replaceType == null) + throw new TypeinferenceException("Der Typ "+this.getType().getName()+" ist nicht korrekt",this); this.setType(replaceType); } - assumptions.addAssumption(new LocalVarAssumption(this)); + assumptions.addAssumption(new LocalVarAssumption(this, this.getType())); //Bevor der Typ auf Void gesetzt wird. //assumptions.remove(null); // falls Variable mit diesem Namen bereits vorhanden. this.setType(new Void(0)); //Return typ einer Variablendeklaration ist Void return ret; diff --git a/src/mycompiler/mystatement/MethodCall.java b/src/mycompiler/mystatement/MethodCall.java index 303c8d40..ab73632c 100755 --- a/src/mycompiler/mystatement/MethodCall.java +++ b/src/mycompiler/mystatement/MethodCall.java @@ -670,7 +670,7 @@ public class MethodCall extends Expr this.setType(TypePlaceholder.fresh(this)); //Berechne die Constraints des Receivers if(receiver == null){ - receiver = new Receiver(new This(0,0)); + receiver = new Receiver(new This(this)); } ret.add(receiver.get_Expr().TYPEExpr(assumptions)); diff --git a/src/mycompiler/mystatement/Statement.java b/src/mycompiler/mystatement/Statement.java index 44a30622..f7b16e4d 100755 --- a/src/mycompiler/mystatement/Statement.java +++ b/src/mycompiler/mystatement/Statement.java @@ -50,7 +50,6 @@ public abstract class Statement extends SyntaxTreeNode implements IItemWithOffse // ino.end protected Type type; - private SyntaxTreeNode parent; // ino.method.Statement.26194.definition public Statement(int offset, int variableLength) diff --git a/src/mycompiler/mystatement/This.java b/src/mycompiler/mystatement/This.java index d83e85d3..a77bb222 100755 --- a/src/mycompiler/mystatement/This.java +++ b/src/mycompiler/mystatement/This.java @@ -50,6 +50,11 @@ public class This extends Expr } // ino.end + public This(SyntaxTreeNode parent){ + this(0,0); + this.parent = parent; + } + // ino.attribute.arglist.26268.declaration public ArgumentList arglist; // ino.end diff --git a/src/mycompiler/mytype/BoundedGenericTypeVar.java b/src/mycompiler/mytype/BoundedGenericTypeVar.java index 9e63dd18..a2d8566a 100755 --- a/src/mycompiler/mytype/BoundedGenericTypeVar.java +++ b/src/mycompiler/mytype/BoundedGenericTypeVar.java @@ -51,8 +51,10 @@ public class BoundedGenericTypeVar extends GenericTypeVar // ino.method.BoundedGenericTypeVar.29409.body { super(s, offset); - if(bounds.size()>1)throw new NotImplementedException(); - this.genericTypeVar = new Pair(new RefType(s,offset),bounds.elementAt(0)); + if(bounds != null)for(Type t : bounds){ + if(t!=null)this.extendVars.add(t); + } + this.genericTypeVar = new RefType(s,offset); this.bounds = bounds; } // ino.end diff --git a/src/mycompiler/mytype/GenericTypeVar.java b/src/mycompiler/mytype/GenericTypeVar.java index b8139dbd..98a1053a 100755 --- a/src/mycompiler/mytype/GenericTypeVar.java +++ b/src/mycompiler/mytype/GenericTypeVar.java @@ -4,6 +4,7 @@ package mycompiler.mytype; // ino.module.GenericTypeVar.8671.import import java.util.HashMap; +import java.util.Iterator; import java.util.Vector; // ino.end @@ -12,6 +13,7 @@ import java.util.Vector; + import mycompiler.mytypereconstruction.replacementlistener.CReplaceTypeEvent; import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListener; import typinferenz.JavaCodeResult; @@ -32,8 +34,9 @@ public class GenericTypeVar extends Type // ino.end // ino.class.GenericTypeVar.26505.body { - Pair genericTypeVar; - /** + Type genericTypeVar; + Vector extendVars = new Vector(); + /** * Eine Registry f�r alle Generic-Instanzen, die vor der Bytecode-Generierung durch * Ihre Superklasse ersetzt werden m�ssen. Siehe "Type Erasure" in Sun Spezifikation. *
Autor: J�rg B�uerle @@ -49,7 +52,8 @@ public class GenericTypeVar extends Type */ public GenericTypeVar(Pair genericTypeVarExtendsVar, int offset){ super(offset); - genericTypeVar = genericTypeVarExtendsVar; + genericTypeVar = genericTypeVarExtendsVar.TA1; + if(genericTypeVarExtendsVar.TA2!=null)this.extendVars.add(genericTypeVarExtendsVar.TA2); this.name = genericTypeVar.toString(); } @@ -144,8 +148,16 @@ public class GenericTypeVar extends Type public JavaCodeResult printJavaCode(ResultSet resultSet) { if(this.genericTypeVar!=null){ JavaCodeResult ret = new JavaCodeResult(); - ret.attach(this.genericTypeVar.TA1.printJavaCode(resultSet)); - if(this.genericTypeVar.TA2!=null)ret.attach(" extends ").attach(this.genericTypeVar.TA2.printJavaCode(resultSet)); + ret.attach(this.genericTypeVar.printJavaCode(resultSet)); + if(this.extendVars.size()>0){ + ret.attach(" extends "); + Iterator it = this.extendVars.iterator(); + while(it.hasNext()){ + Type extend = it.next(); + ret.attach(extend.printJavaCode(resultSet)); + if(it.hasNext())ret.attach(", "); + } + } return ret; } return new JavaCodeResult(this.name); diff --git a/src/typinferenz/assumptions/LocalVarAssumption.java b/src/typinferenz/assumptions/LocalVarAssumption.java index 8aa60ea8..218c9fd2 100644 --- a/src/typinferenz/assumptions/LocalVarAssumption.java +++ b/src/typinferenz/assumptions/LocalVarAssumption.java @@ -6,15 +6,17 @@ import mycompiler.mystatement.LocalVarDecl; public class LocalVarAssumption extends Assumption { private LocalVarDecl localVar; + private Type type; - public LocalVarAssumption(LocalVarDecl localVar){ + public LocalVarAssumption(LocalVarDecl localVar, Type declaredType){ super(localVar); this.localVar = localVar; + this.type = declaredType; } @Override public Type getAssumedType() { - return this.localVar.getType(); + return this.type; } } diff --git a/src/typinferenz/assumptions/TypeAssumptions.java b/src/typinferenz/assumptions/TypeAssumptions.java index 45d885b0..13322c2a 100755 --- a/src/typinferenz/assumptions/TypeAssumptions.java +++ b/src/typinferenz/assumptions/TypeAssumptions.java @@ -54,7 +54,6 @@ public class TypeAssumptions { private Vector parameterAssumptions = new Vector(); private Vector classAssumptions = new Vector(); - /** * Dieser Konstruktor setzt bei der Initialisierung auch den Wert von "this" * @param klassenname - Wert für "this" diff --git a/test/plugindevelopment/MartinTestCases/Tester.java b/test/plugindevelopment/MartinTestCases/Tester.java index 9607e297..a73f0a42 100644 --- a/test/plugindevelopment/MartinTestCases/Tester.java +++ b/test/plugindevelopment/MartinTestCases/Tester.java @@ -51,7 +51,43 @@ public class Tester extends TypeInsertTester{ @Test public void runTests(){ - Tester.test("OL.jav", new Vector()); + Vector testFiles = new Vector(); + testFiles.add("AchimTest1.jav"); + + //testFiles.add("BoundedType1.jav"); + testFiles.add("BoundedType2.jav"); + testFiles.add("BoundedType.jav"); + testFiles.add("OL2.jav"); + testFiles.add("OL.jav"); + testFiles.add("Probleme"); + testFiles.add("Simple.jav"); + testFiles.add("SMatrix.jav"); + testFiles.add("Tester.java"); + testFiles.add("UnifyTest1.jav"); + testFiles.add("UsecaseEight_pl.jav"); + testFiles.add("UsecaseFive_pl.jav"); + testFiles.add("UsecaseFour_pl.jav"); + testFiles.add("Usecase_MUBTest1.jav"); + testFiles.add("Usecase_MUBTest2.jav"); + testFiles.add("Usecase_MUBTest3.jav"); + testFiles.add("Usecase_MUBTest4.jav"); + testFiles.add("Usecase_MUBTest5.jav"); + testFiles.add("Usecase_MUBTest6.jav"); + testFiles.add("Usecase_MUBTest.jav"); + testFiles.add("UsecaseNine_pl.jav"); + testFiles.add("UsecaseOne_pl.jav"); + testFiles.add("UsecaseSeven_pl.jav"); + testFiles.add("UsecaseSix_pl.jav"); + testFiles.add("UsecaseTen_pl.jav"); + testFiles.add("UsecaseThree_pl.jav"); + testFiles.add("UsecaseThree_pl.orig.jav"); + testFiles.add("UsecaseTwo_pl.jav"); + testFiles.add("ZweiKlassen.jav"); + //*/ + for(String file : testFiles){ + System.out.println("Testfile: "+file); + Tester.test(file, new Vector()); + } } }