Einsetzen von generischen Variablen verbessern

This commit is contained in:
JanUlrich 2014-07-16 14:35:12 +02:00
parent 694899e73f
commit f059e0b9b8
11 changed files with 113 additions and 69 deletions

View File

@ -134,7 +134,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%token CASE
%token CATCH
%token <Token> CHAR
%token CLASS
%token <Token> CLASS
%token CONTINUE
%token DEFAULT
%token DO
@ -152,7 +152,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%token <Token> PUBLIC
%token PACKAGE
%token IMPORT
%token INTERFACE
%token <Token> INTERFACE
%token IMPLEMENTS
%token RETURN
%token <Token> STATIC
@ -447,50 +447,50 @@ classdeclaration : CLASS classidentifier classbody
// Vector<UsedId> SuperInterfaces,
// Vector<Type> 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);

View File

@ -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:

View File

@ -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

View File

@ -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<Field> fielddecl = new Vector<Field>();
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<Type> ct, Vector<UsedId> usedIdsToCheck,
UsedId superclass, Vector<UsedId> superif, Vector<Type> paralist)
UsedId superclass, Vector<UsedId> superif, Vector<Type> 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;
}
}

View File

@ -134,12 +134,24 @@ 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
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
public void setGenericParameter(GenericDeclarationList params) {

View File

@ -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() {

View File

@ -909,7 +909,7 @@ case 20:
/* Vector<UsedId> SuperInterfaces, */
/* Vector<Type> 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]));

View File

@ -134,7 +134,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%token CASE
%token CATCH
%token <Token> CHAR
%token CLASS
%token <Token> CLASS
%token CONTINUE
%token DEFAULT
%token DO
@ -152,7 +152,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%token <Token> PUBLIC
%token PACKAGE
%token IMPORT
%token INTERFACE
%token <Token> INTERFACE
%token IMPLEMENTS
%token RETURN
%token <Token> STATIC
@ -447,50 +447,50 @@ classdeclaration : CLASS classidentifier classbody
// Vector<UsedId> SuperInterfaces,
// Vector<Type> 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);

View File

@ -22,7 +22,7 @@ public class FunNInterface extends Class{
* @param N - Die Anzahl der Parameter der apply-Methode. Beispiel N = 1 ergibt <code>R apply(T1 par1);</code>
*/
public FunNInterface(int N) {
super("Fun"+N);
super("Fun"+N, 0);
Vector<Type> paralist = new Vector<Type>();
paralist.add(new GenericTypeVar("R",0));
//paralist.add(TypePlaceholder.fresh());

View File

@ -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();
}

View File

@ -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<GenericVarDeclarationPatch> it = this.genericVarDeclarations.iterator();
while(it.hasNext()){
GenericVarDeclarationPatch p = it.next();
ret += p.getInsertString(rs);
if(it.hasNext())ret += ", ";
}
return ret;
}