diff --git a/bin/mycompiler/myparser/JavaParser.jay b/bin/mycompiler/myparser/JavaParser.jay index c7ebfbdc..dd364964 100755 --- a/bin/mycompiler/myparser/JavaParser.jay +++ b/bin/mycompiler/myparser/JavaParser.jay @@ -134,7 +134,7 @@ public Vector testPair = new Vector(); %token CASE %token CATCH %token CHAR -%token CLASS +%token CLASS %token CONTINUE %token DEFAULT %token DO @@ -152,7 +152,7 @@ public Vector testPair = new Vector(); %token PUBLIC %token PACKAGE %token IMPORT -%token INTERFACE +%token INTERFACE %token IMPLEMENTS %token RETURN %token STATIC @@ -447,50 +447,50 @@ classdeclaration : CLASS classidentifier classbody // Vector SuperInterfaces, // Vector Parameterliste - $$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector()); + $$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier classbody { - $$ = new Class($3.getName(), $1, $4, containedTypes,usedIdsToCheck, null, null, $3.getParaVector()); + $$ = new Class($3.getName(), $1, $4, containedTypes,usedIdsToCheck, null, null, $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | CLASS classidentifier super classbody { - $$ = new Class($2.getName(), null, $4, containedTypes,usedIdsToCheck, $3, null, $2.getParaVector()); + $$ = new Class($2.getName(), null, $4, containedTypes,usedIdsToCheck, $3, null, $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier super classbody { - $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, $4, null, $3.getParaVector()); + $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, $4, null, $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } ///* auskommentiert von Andreas Stadelmeier A10023 | CLASS classidentifier interfaces classbody { - $$ = new Class($2.getName(), null, $4, containedTypes, usedIdsToCheck, null, $3.getVector(), $2.getParaVector()); + $$ = new Class($2.getName(), null, $4, containedTypes, usedIdsToCheck, null, $3.getVector(), $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier interfaces classbody { - $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, null, $4.getVector(), $3.getParaVector()); + $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, null, $4.getVector(), $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | CLASS classidentifier super interfaces classbody { - $$ = new Class($2.getName(), null, $5, containedTypes,usedIdsToCheck, $3, $4.getVector(), $2.getParaVector()); + $$ = new Class($2.getName(), null, $5, containedTypes,usedIdsToCheck, $3, $4.getVector(), $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier super interfaces classbody { - $$ = new Class($3.getName(), $1, $6, containedTypes, usedIdsToCheck, $4, $5.getVector(), $3.getParaVector()); + $$ = new Class($3.getName(), $1, $6, containedTypes, usedIdsToCheck, $4, $5.getVector(), $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -520,7 +520,7 @@ classidentifier : IDENTIFIER interfacedeclaration: INTERFACE interfaceidentifier interfacebody { // SCJU: Interface - Interface ic = new Interface($2.getName()); + Interface ic = new Interface($2.getName(), $1.getOffset()); ic.setParaList($2.getParaVector()); ic.setInterfaceBody($3); ic.setContainedTypes(containedTypes); @@ -529,7 +529,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | modifiers INTERFACE interfaceidentifier interfacebody { - Interface ic = new Interface($3.getName(), $1); + Interface ic = new Interface($3.getName(), $1, $2.getOffset()); ic.setInterfaceBody($4); ic.setParaList($3.getParaVector()); ic.setContainedTypes(containedTypes); @@ -538,7 +538,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | INTERFACE interfaceidentifier extendsinterfaces interfacebody { - Interface ic = new Interface($2.getName()); + Interface ic = new Interface($2.getName(), $1.getOffset()); ic.setParaList($2.getParaVector()); ic.setSuperInterfaces($3.getVector()); ic.setInterfaceBody($4); @@ -548,7 +548,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | modifiers INTERFACE interfaceidentifier extendsinterfaces interfacebody ; { - Interface ic = new Interface($3.getName(), $1); + Interface ic = new Interface($3.getName(), $1, $2.getOffset()); ic.setParaList($3.getParaVector()); ic.setSuperInterfaces($4.getVector()); ic.setInterfaceBody($5); diff --git a/src/mycompiler/SourceFile.java b/src/mycompiler/SourceFile.java index 56cf5fab..6a873269 100755 --- a/src/mycompiler/SourceFile.java +++ b/src/mycompiler/SourceFile.java @@ -1128,7 +1128,7 @@ public class SourceFile } //BasicAssumptionClass myCl = new BasicAssumptionClass(className, mod); - Class parentClass = new Class(className, mod); + Class parentClass = new Class(className, mod, 0); if(typeGenPara.size()>0){ //auskommentiert von Andreas Stadelmeier: diff --git a/src/mycompiler/myclass/BasicAssumptionClass.java b/src/mycompiler/myclass/BasicAssumptionClass.java index 53a01849..0e392e65 100755 --- a/src/mycompiler/myclass/BasicAssumptionClass.java +++ b/src/mycompiler/myclass/BasicAssumptionClass.java @@ -17,7 +17,7 @@ public class BasicAssumptionClass extends Class // ino.end // ino.method.BasicAssumptionClass.23004.body { - super(name); + super(name, 0); } // ino.end @@ -26,7 +26,7 @@ public class BasicAssumptionClass extends Class // ino.end // ino.method.BasicAssumptionClass.23007.body { - super(name,mod); + super(name,mod, 0); } // ino.end diff --git a/src/mycompiler/myclass/Class.java b/src/mycompiler/myclass/Class.java index 0677fb79..d096b77e 100755 --- a/src/mycompiler/myclass/Class.java +++ b/src/mycompiler/myclass/Class.java @@ -68,6 +68,8 @@ import org.apache.log4j.Logger; + + import sun.reflect.generics.reflectiveObjects.NotImplementedException; import typinferenz.ConstraintsSet; import typinferenz.JavaCodeResult; @@ -189,10 +191,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private SyntaxTreeNode parent; private Vector fielddecl = new Vector(); private GenericDeclarationList genericClassParameters; + private int offset; // ino.method.Class.23041.definition - public Class(String name) + public Class(String name, int offset) // ino.end // ino.method.Class.23041.body { @@ -200,11 +203,12 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit if(name.equals("java.lang.Object")){ superclassid=null; } + this.offset = offset; } // ino.end // ino.method.Class.23044.definition - public Class(String name, Modifiers mod) + public Class(String name, Modifiers mod, int offset) // ino.end // ino.method.Class.23044.body { @@ -213,6 +217,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit if(name.equals("java.lang.Object")){ superclassid=null; } + this.offset = offset; } // ino.end @@ -224,7 +229,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit // ino.end // ino.method.Class.23047.definition public Class(String name, Modifiers mod, ClassBody cb, Vector ct, Vector usedIdsToCheck, - UsedId superclass, Vector superif, Vector paralist) + UsedId superclass, Vector superif, Vector paralist, int offset) // ino.end // ino.method.Class.23047.body { @@ -245,7 +250,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } parserlog.debug("Neue Klasse: " + name); - + this.offset = offset; } // ino.end @@ -1258,8 +1263,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit */ public int getOffset(){ - //TODO: richtiges Offset: - return 0; + return this.offset; } /** @@ -1381,9 +1385,22 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } @Override - public int getGenericDeclOffset() { - //TODO: Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn - return this.getOffset(); + public String getGenericVarDeclarationString(String genericVarDeclaration) { + if(this.genericClassParameters != null){ + return ", "+genericVarDeclaration; + }else{ + return "<"+genericVarDeclaration+">"; + } + } + + @Override + public int getGenericVarDeclarationOffset(){ + // Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn + if(this.genericClassParameters != null){ + return this.genericClassParameters.getOffsetOfLastElement(); + }else{ + return this.offset; + } } diff --git a/src/mycompiler/myclass/Field.java b/src/mycompiler/myclass/Field.java index 1d8398b4..35be7fcb 100644 --- a/src/mycompiler/myclass/Field.java +++ b/src/mycompiler/myclass/Field.java @@ -134,11 +134,23 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty return true; } + @Override + public String getGenericVarDeclarationString(String genericVarDeclaration) { + if(this.genericParameters != null){ + return ", "+genericVarDeclaration; + }else{ + return "<"+genericVarDeclaration+">"; + } + } @Override - public int getGenericDeclOffset() { - //TODO: Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn - return this.offset; + public int getGenericVarDeclarationOffset(){ + // Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn + if(this.genericParameters != null){ + return this.genericParameters.getOffsetOfLastElement(); + }else{ + return this.offset; + } } @Override diff --git a/src/mycompiler/myinterface/Interface.java b/src/mycompiler/myinterface/Interface.java index 5394d070..2e7cad7f 100755 --- a/src/mycompiler/myinterface/Interface.java +++ b/src/mycompiler/myinterface/Interface.java @@ -35,12 +35,12 @@ import mycompiler.SourceFile; */ public class Interface extends Class { - public Interface(String name){ - super(name); + public Interface(String name, int offset){ + super(name, offset); } - public Interface(String name, Modifiers modifiers) { - super(name,modifiers); + public Interface(String name, Modifiers modifiers, int offset) { + super(name,modifiers, offset); } public Vector getParaList() { diff --git a/src/mycompiler/myparser/JavaParser.java b/src/mycompiler/myparser/JavaParser.java index a23a3706..318d287f 100644 --- a/src/mycompiler/myparser/JavaParser.java +++ b/src/mycompiler/myparser/JavaParser.java @@ -909,7 +909,7 @@ case 20: /* Vector SuperInterfaces, */ /* Vector Parameterliste*/ - yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -917,7 +917,7 @@ case 20: case 21: // line 455 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, null, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -925,7 +925,7 @@ case 21: case 22: // line 461 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -933,7 +933,7 @@ case 22: case 23: // line 467 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -941,7 +941,7 @@ case 23: case 24: // line 474 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -949,7 +949,7 @@ case 24: case 25: // line 480 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, null, ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -957,7 +957,7 @@ case 25: case 26: // line 486 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes,usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -965,7 +965,7 @@ case 26: case 27: // line 492 "./../src/mycompiler/myparser/JavaParser.jay" { - yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector()); + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, usedIdsToCheck, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -1002,7 +1002,7 @@ case 32: // line 521 "./../src/mycompiler/myparser/JavaParser.jay" { /* SCJU: Interface*/ - Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName()); + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName(), ((Token)yyVals[-2+yyTop]).getOffset()); ic.setParaList(((InterfaceAndParameter)yyVals[-1+yyTop]).getParaVector()); ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); ic.setContainedTypes(containedTypes); @@ -1013,7 +1013,7 @@ case 32: case 33: // line 531 "./../src/mycompiler/myparser/JavaParser.jay" { - Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop])); + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((Token)yyVals[-2+yyTop]).getOffset()); ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); ic.setParaList(((InterfaceAndParameter)yyVals[-1+yyTop]).getParaVector()); ic.setContainedTypes(containedTypes); @@ -1024,7 +1024,7 @@ case 33: case 34: // line 540 "./../src/mycompiler/myparser/JavaParser.jay" { - Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName()); + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName(), ((Token)yyVals[-3+yyTop]).getOffset()); ic.setParaList(((InterfaceAndParameter)yyVals[-2+yyTop]).getParaVector()); ic.setSuperInterfaces(((InterfaceList)yyVals[-1+yyTop]).getVector()); ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); @@ -1036,7 +1036,7 @@ case 34: case 35: // line 550 "./../src/mycompiler/myparser/JavaParser.jay" { - Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop])); + Interface ic = new Interface(((InterfaceAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((Token)yyVals[-3+yyTop]).getOffset()); ic.setParaList(((InterfaceAndParameter)yyVals[-2+yyTop]).getParaVector()); ic.setSuperInterfaces(((InterfaceList)yyVals[-1+yyTop]).getVector()); ic.setInterfaceBody(((InterfaceBody)yyVals[0+yyTop])); diff --git a/src/mycompiler/myparser/JavaParser.jay b/src/mycompiler/myparser/JavaParser.jay index c7ebfbdc..dd364964 100755 --- a/src/mycompiler/myparser/JavaParser.jay +++ b/src/mycompiler/myparser/JavaParser.jay @@ -134,7 +134,7 @@ public Vector testPair = new Vector(); %token CASE %token CATCH %token CHAR -%token CLASS +%token CLASS %token CONTINUE %token DEFAULT %token DO @@ -152,7 +152,7 @@ public Vector testPair = new Vector(); %token PUBLIC %token PACKAGE %token IMPORT -%token INTERFACE +%token INTERFACE %token IMPLEMENTS %token RETURN %token STATIC @@ -447,50 +447,50 @@ classdeclaration : CLASS classidentifier classbody // Vector SuperInterfaces, // Vector Parameterliste - $$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector()); + $$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier classbody { - $$ = new Class($3.getName(), $1, $4, containedTypes,usedIdsToCheck, null, null, $3.getParaVector()); + $$ = new Class($3.getName(), $1, $4, containedTypes,usedIdsToCheck, null, null, $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | CLASS classidentifier super classbody { - $$ = new Class($2.getName(), null, $4, containedTypes,usedIdsToCheck, $3, null, $2.getParaVector()); + $$ = new Class($2.getName(), null, $4, containedTypes,usedIdsToCheck, $3, null, $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier super classbody { - $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, $4, null, $3.getParaVector()); + $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, $4, null, $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } ///* auskommentiert von Andreas Stadelmeier A10023 | CLASS classidentifier interfaces classbody { - $$ = new Class($2.getName(), null, $4, containedTypes, usedIdsToCheck, null, $3.getVector(), $2.getParaVector()); + $$ = new Class($2.getName(), null, $4, containedTypes, usedIdsToCheck, null, $3.getVector(), $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier interfaces classbody { - $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, null, $4.getVector(), $3.getParaVector()); + $$ = new Class($3.getName(), $1, $5, containedTypes, usedIdsToCheck, null, $4.getVector(), $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | CLASS classidentifier super interfaces classbody { - $$ = new Class($2.getName(), null, $5, containedTypes,usedIdsToCheck, $3, $4.getVector(), $2.getParaVector()); + $$ = new Class($2.getName(), null, $5, containedTypes,usedIdsToCheck, $3, $4.getVector(), $2.getParaVector(), $1.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } | modifiers CLASS classidentifier super interfaces classbody { - $$ = new Class($3.getName(), $1, $6, containedTypes, usedIdsToCheck, $4, $5.getVector(), $3.getParaVector()); + $$ = new Class($3.getName(), $1, $6, containedTypes, usedIdsToCheck, $4, $5.getVector(), $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -520,7 +520,7 @@ classidentifier : IDENTIFIER interfacedeclaration: INTERFACE interfaceidentifier interfacebody { // SCJU: Interface - Interface ic = new Interface($2.getName()); + Interface ic = new Interface($2.getName(), $1.getOffset()); ic.setParaList($2.getParaVector()); ic.setInterfaceBody($3); ic.setContainedTypes(containedTypes); @@ -529,7 +529,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | modifiers INTERFACE interfaceidentifier interfacebody { - Interface ic = new Interface($3.getName(), $1); + Interface ic = new Interface($3.getName(), $1, $2.getOffset()); ic.setInterfaceBody($4); ic.setParaList($3.getParaVector()); ic.setContainedTypes(containedTypes); @@ -538,7 +538,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | INTERFACE interfaceidentifier extendsinterfaces interfacebody { - Interface ic = new Interface($2.getName()); + Interface ic = new Interface($2.getName(), $1.getOffset()); ic.setParaList($2.getParaVector()); ic.setSuperInterfaces($3.getVector()); ic.setInterfaceBody($4); @@ -548,7 +548,7 @@ interfacedeclaration: INTERFACE interfaceidentifier interfacebody } | modifiers INTERFACE interfaceidentifier extendsinterfaces interfacebody ; { - Interface ic = new Interface($3.getName(), $1); + Interface ic = new Interface($3.getName(), $1, $2.getOffset()); ic.setParaList($3.getParaVector()); ic.setSuperInterfaces($4.getVector()); ic.setInterfaceBody($5); diff --git a/src/typinferenz/FunNInterface.java b/src/typinferenz/FunNInterface.java index 75442735..0b5e3dec 100644 --- a/src/typinferenz/FunNInterface.java +++ b/src/typinferenz/FunNInterface.java @@ -22,7 +22,7 @@ public class FunNInterface extends Class{ * @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt R apply(T1 par1); */ public FunNInterface(int N) { - super("Fun"+N); + super("Fun"+N, 0); Vector paralist = new Vector(); paralist.add(new GenericTypeVar("R",0)); //paralist.add(TypePlaceholder.fresh()); diff --git a/src/typinferenz/GenericTypeInsertable.java b/src/typinferenz/GenericTypeInsertable.java index 791fcbf7..1d676f76 100644 --- a/src/typinferenz/GenericTypeInsertable.java +++ b/src/typinferenz/GenericTypeInsertable.java @@ -5,10 +5,8 @@ package typinferenz; */ public interface GenericTypeInsertable { - /** - * Gibt den Offset im Quellcode an, an dem neue Deklarationen von generischen Variablen eingesetzt werden können. - * @return - */ - public int getGenericDeclOffset(); + public String getGenericVarDeclarationString(String genericVarDeclaration); + public int getGenericVarDeclarationOffset(); + } diff --git a/src/typinferenz/typedeployment/GenericTypeInsertPoint.java b/src/typinferenz/typedeployment/GenericTypeInsertPoint.java index 174a9540..ceaba466 100644 --- a/src/typinferenz/typedeployment/GenericTypeInsertPoint.java +++ b/src/typinferenz/typedeployment/GenericTypeInsertPoint.java @@ -51,7 +51,9 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { public String getTypeInsertString() { - return this.patch.getInsertString(this.resultSet); + String genericVar = this.patch.getInsertString(this.resultSet); + if(genericVar.length()==0)return ""; + return this.genericInsertPoint.getGenericVarDeclarationString(genericVar); } /* @@ -122,6 +124,18 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { */ @Override public JavaCodeResult patch(String fileContent, int additionalOffset) { + /* + int offset = additionalOffset; + String insertString = ""; + if(this.genericParameters != null){ + offset += this.genericParameters.getOffsetOfLastElement(); + insertString = ", "+genericVarDecl; + }else{ + offset += this.offset; + + } + return sourceCode.substring(0,offset) + insertString + sourceCode.substring(offset); + */ //TODO: Es kann sein, dass eine Methode bereits Generische Variablen hat, diese müssen dann an diese Liste angefügt werden. JavaCodeResult ret = new JavaCodeResult(fileContent.substring(0, this.getOffset()+additionalOffset)); JavaCodeResult mitte = new JavaCodeResult(this.getTypeInsertString()).attach(fileContent.substring(this.getOffset()+additionalOffset)); @@ -147,7 +161,7 @@ public class GenericTypeInsertPoint extends SourcePatchPoint { */ @Override public int getOffset() { - return genericInsertPoint.getGenericDeclOffset(); + return genericInsertPoint.getGenericVarDeclarationOffset(); } } @@ -171,8 +185,11 @@ class GenericVarPatch { public String getInsertString(ResultSet rs){ String ret = ""; - for(GenericVarDeclarationPatch p : this.genericVarDeclarations){ - ret += p.getInsertString(rs) + ", "; + Iterator it = this.genericVarDeclarations.iterator(); + while(it.hasNext()){ + GenericVarDeclarationPatch p = it.next(); + ret += p.getInsertString(rs); + if(it.hasNext())ret += ", "; } return ret; }