diff --git a/src/de/dhbwstuttgart/antlr/VisitorTest.java b/src/de/dhbwstuttgart/antlr/VisitorTest.java index eeaf4478..2effc93d 100644 --- a/src/de/dhbwstuttgart/antlr/VisitorTest.java +++ b/src/de/dhbwstuttgart/antlr/VisitorTest.java @@ -85,7 +85,7 @@ class EvalVisitor extends Java8BaseVisitor { @Override public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) { - GenericTypeVar ret = new GenericTypeVar(name, parent, offset); + GenericTypeVar ret = null;//new GenericTypeVar(name, parent, offset); return ret; } diff --git a/src/de/dhbwstuttgart/core/AClassOrInterface.java b/src/de/dhbwstuttgart/core/AClassOrInterface.java index 16a6f16f..ab9f8a06 100755 --- a/src/de/dhbwstuttgart/core/AClassOrInterface.java +++ b/src/de/dhbwstuttgart/core/AClassOrInterface.java @@ -15,11 +15,15 @@ import org.apache.log4j.Logger; + + import de.dhbwstuttgart.myexception.JVMCodeException; import de.dhbwstuttgart.parser.JavaClassName; import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.misc.UsedId; import de.dhbwstuttgart.syntaxtree.modifier.Modifiers; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.Type; // ino.class.AClassOrInterface.21186.description type=javadoc /** @@ -37,8 +41,8 @@ public interface AClassOrInterface { public JavaClassName getName(); - public Vector getSuperInterfaces(); - public void setSuperInterfaces(Vector vector); + public Vector getSuperInterfaces(); + public void setSuperInterfaces(Vector vector); /* // ino.attribute.inferencelog.21189.decldescription type=javadoc diff --git a/src/de/dhbwstuttgart/parser/InterfaceList.java b/src/de/dhbwstuttgart/parser/InterfaceList.java index e7438067..a3b8b82d 100755 --- a/src/de/dhbwstuttgart/parser/InterfaceList.java +++ b/src/de/dhbwstuttgart/parser/InterfaceList.java @@ -7,6 +7,8 @@ import java.util.Vector; import de.dhbwstuttgart.syntaxtree.Interface; import de.dhbwstuttgart.syntaxtree.misc.UsedId; +import de.dhbwstuttgart.syntaxtree.type.RefType; +import de.dhbwstuttgart.syntaxtree.type.Type; // ino.class.InterfaceList.24383.description type=javadoc /** @@ -36,13 +38,13 @@ public class InterfaceList // ino.end // ino.method.getVector.24392.definition - public Vector getVector() + public Vector getTypeVector() // ino.end // ino.method.getVector.24392.body { - Vector ret = new Vector<>(); + Vector ret = new Vector<>(); for(UsedId name : superif){ - ret.add(new Interface(name.get_Name_1Element(), name.getOffset())); + ret.add(new Interface(name.get_Name_1Element(), name.getOffset()).getType()); } return ret; } diff --git a/src/de/dhbwstuttgart/parser/JavaParser.java b/src/de/dhbwstuttgart/parser/JavaParser.java index 585e4cb8..4968adaf 100644 --- a/src/de/dhbwstuttgart/parser/JavaParser.java +++ b/src/de/dhbwstuttgart/parser/JavaParser.java @@ -281,8 +281,8 @@ public Vector testPair = new Vector(); //t "fielddeclarator : variabledeclarator '=' expression", //t "fielddeclarator : variabledeclarator", //t "genericdeclarationlist : '<' boundedMethodParameters '>'", -//t "fielddeclaration : fielddeclarator ';'", //t "fielddeclaration : type fielddeclarator ';'", +//t "fielddeclaration : fielddeclarator ';'", //t "fielddeclaration : genericdeclarationlist type fielddeclarator ';'", //t "fielddeclaration : variabledeclarators ';'", //t "fielddeclaration : type variabledeclarators ';'", @@ -833,7 +833,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(), ((Token)yyVals[-2+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -841,7 +841,7 @@ case 20: case 21: // line 376 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-2+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-1+yyTop]).getName(), ((Modifiers)yyVals[-3+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, null, ((ClassAndParameter)yyVals[-1+yyTop]).getParaVector(), ((Token)yyVals[-2+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -849,7 +849,7 @@ case 21: case 22: // line 382 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-3+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -857,7 +857,7 @@ case 22: case 23: // line 388 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-3+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-1+yyTop]), null, ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -865,7 +865,7 @@ case 23: case 24: // line 395 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-3+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -873,7 +873,7 @@ case 24: case 25: // line 401 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-3+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-2+yyTop]).getName(), ((Modifiers)yyVals[-4+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-2+yyTop]).getParaVector(), ((Token)yyVals[-3+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -881,7 +881,7 @@ case 25: case 26: // line 407 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-4+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), null, ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -889,7 +889,7 @@ case 26: case 27: // line 413 "./../src/de/dhbwstuttgart/parser/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(), ((Token)yyVals[-4+yyTop]).getOffset()); + yyVal = new Class(((ClassAndParameter)yyVals[-3+yyTop]).getName(), ((Modifiers)yyVals[-5+yyTop]), ((ClassBody)yyVals[0+yyTop]), containedTypes, ((UsedId)yyVals[-2+yyTop]), ((InterfaceList)yyVals[-1+yyTop]).getTypeVector(), ((ClassAndParameter)yyVals[-3+yyTop]).getParaVector(), ((Token)yyVals[-4+yyTop]).getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -1396,13 +1396,13 @@ case 89: case 90: // line 854 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { + ((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); yyVal=((FieldDeclaration)yyVals[-1+yyTop]); } break; case 91: - // line 858 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" + // line 859 "./../src/de/dhbwstuttgart/parser/JavaParser.jay" { - ((FieldDeclaration)yyVals[-1+yyTop]).setType(((Type)yyVals[-2+yyTop])); yyVal=((FieldDeclaration)yyVals[-1+yyTop]); } break; @@ -3209,8 +3209,8 @@ case 289: 3, 2, 3, 2, 3, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 3, 3, 1, 0, 3, 1, 1, 1, - 1, 2, 2, 3, 6, 2, 3, 1, 3, 2, - 3, 4, 2, 3, 4, 2, 2, 3, 3, 4, + 1, 2, 2, 3, 6, 2, 3, 1, 3, 3, + 2, 4, 2, 3, 4, 2, 2, 3, 3, 4, 2, 3, 3, 4, 2, 1, 1, 3, 1, 3, 1, 3, 1, 3, 3, 2, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, @@ -3248,7 +3248,7 @@ case 289: 34, 0, 0, 0, 77, 21, 0, 0, 33, 0, 0, 0, 31, 0, 82, 0, 0, 0, 113, 0, 0, 132, 0, 142, 96, 0, 134, 46, 57, 0, - 93, 90, 0, 0, 0, 0, 0, 0, 0, 0, + 93, 91, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 83, 26, 51, 29, 53, 66, 0, 86, 0, 55, 43, 44, 73, 74, 23, 0, 25, 35, 111, 0, 108, 0, 0, 0, 254, 0, @@ -3261,7 +3261,7 @@ case 289: 165, 141, 0, 0, 0, 0, 0, 0, 0, 245, 286, 0, 0, 276, 0, 0, 0, 0, 0, 0, 0, 194, 173, 87, 241, 242, 248, 249, 174, 195, - 255, 259, 99, 0, 119, 94, 91, 0, 0, 0, + 255, 259, 99, 0, 119, 94, 90, 0, 0, 0, 135, 0, 0, 84, 0, 101, 0, 0, 0, 27, 0, 0, 0, 198, 0, 0, 0, 229, 230, 219, 0, 0, 0, 98, 144, 167, 216, 0, 0, 231, diff --git a/src/de/dhbwstuttgart/parser/JavaParser.jay b/src/de/dhbwstuttgart/parser/JavaParser.jay index e163827e..23de6cbf 100755 --- a/src/de/dhbwstuttgart/parser/JavaParser.jay +++ b/src/de/dhbwstuttgart/parser/JavaParser.jay @@ -368,50 +368,50 @@ classdeclaration : CLASS classidentifier classbody // Vector SuperInterfaces, // Vector Parameterliste - $$ = new Class($2.getName(), null, $3, containedTypes, usedIdsToCheck, null, null, $2.getParaVector(), $1.getOffset()); + $$ = new Class($2.getName(), null, $3, containedTypes, 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(), $2.getOffset()); + $$ = new Class($3.getName(), $1, $4, containedTypes, 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(), $1.getOffset()); + $$ = new Class($2.getName(), null, $4, containedTypes, $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(), $2.getOffset()); + $$ = new Class($3.getName(), $1, $5, containedTypes, $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(), $1.getOffset()); + $$ = new Class($2.getName(), null, $4, containedTypes, $3.getTypeVector(), $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(), $2.getOffset()); + $$ = new Class($3.getName(), $1, $5, containedTypes, $4.getTypeVector(), $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(), $1.getOffset()); + $$ = new Class($2.getName(), null, $5, containedTypes, $3, $4.getTypeVector(), $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(), $2.getOffset()); + $$ = new Class($3.getName(), $1, $6, containedTypes, $4, $5.getTypeVector(), $3.getParaVector(), $2.getOffset()); this.initContainedTypes(); this.initUsedIdsToCheck(); } @@ -850,15 +850,15 @@ genericdeclarationlist : '<' boundedMethodParameters '>' } -fielddeclaration : fielddeclarator ';' - { - $$=$1; - } - | type fielddeclarator ';' +fielddeclaration : type fielddeclarator ';' { $2.setType($1); $$=$2; } + | fielddeclarator ';' + { + $$=$1; + } | genericdeclarationlist type fielddeclarator ';' {//angefügt von Andreas Stadelmeier $3.setType($2); diff --git a/src/de/dhbwstuttgart/syntaxtree/Class.java b/src/de/dhbwstuttgart/syntaxtree/Class.java index 7becd842..a2554592 100755 --- a/src/de/dhbwstuttgart/syntaxtree/Class.java +++ b/src/de/dhbwstuttgart/syntaxtree/Class.java @@ -51,7 +51,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit protected Modifiers modifiers; protected String name; - private Vector superif = new Vector(); + private Vector superif = new Vector(); public UsedId getPackageName() { @@ -89,12 +89,13 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit return ret; } - public Vector getSuperInterfaces() + public Vector getSuperInterfaces() { return superif; } - public void setSuperInterfaces(Vector superif) + @Override + public void setSuperInterfaces(Vector superif) { this.superif = superif; } @@ -144,7 +145,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit private Vector fielddecl = new Vector(); private GenericDeclarationList genericClassParameters; private int offset; - private Class superClass; + private Type superClass; // ino.method.Class.23041.definition @@ -158,11 +159,11 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } this.offset = offset; if(!name.equals("Object"))//Alle Klassen außer Object erben von Object: - this.superClass = new Class("Object", -1); + this.superClass = new Class("Object", -1).getType(); } // ino.end - public Class(String name, Class superClass, int offset){ + public Class(String name, RefType superClass, int offset){ this(name,offset); this.superClass = superClass; } @@ -177,15 +178,44 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - // ino.method.Class.23047.defdescription type=javadoc + public Class(String name, Modifiers mod, ClassBody cb, Vector ct, Vector usedIdsToCheck, + UsedId superclass, Vector superif, Vector paralist, int offset){ + this(name, mod, cb, ct, usedIdToRefType(superclass),usedIdToRefType(superif),paralist,offset); + } + public Class(String name, ClassBody cb, Vector ct, + UsedId superclass, Vector superif, Vector paralist, int offset) { + this(name,null,cb,ct,usedIdToRefType(superclass),superif,paralist,offset); + } + public Class(String name2, Modifiers modifiers2, ClassBody classBody, + Vector containedTypes2, UsedId usedId, + Vector typeVector, Vector paraVector, int offset2) { + this(name2, modifiers2, classBody, containedTypes2, usedIdToRefType(usedId),typeVector, paraVector, offset2); + } + public Class(String name2, Modifiers object, ClassBody classBody, + Vector containedTypes2, Vector typeVector, + Vector paraVector, int offset2) { + this(name2, object, classBody, containedTypes2,(Type)null, typeVector, paraVector, offset2); + } + private static Vector usedIdToRefType(Vector superif2) { + Vector ret = new Vector<>(); + for(UsedId id : superif2)ret.add(usedIdToRefType(id)); + return ret; + } + private static Type usedIdToRefType(UsedId superclass2) { + RefType ret = new RefType(superclass2.getSimpleName(), null, superclass2.getOffset()); + ret.set_ParaList(superclass2.get_ParaList()); + return ret; + } + + // ino.method.Class.23047.defdescription type=javadoc /** * Konstruktor, der die Angabe aller Parameter ermoeglicht. * Zur Uebersichtlichkeit in der Grammatik. */ // 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, int offset) + public Class(String name, Modifiers mod, ClassBody cb, Vector ct, + Type superclass, Vector vector, Vector paralist, int offset) // ino.end // ino.method.Class.23047.body { @@ -194,9 +224,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit if (cb != null) set_ClassBody(cb); if (ct != null) setContainedTypes(ct); if (superclass != null){ - this.superClass = new Class(superClass.getName().toString(),-1); + this.superClass = superclass; } - if (superif != null) setSuperInterfaces(superif); + if (vector != null) setSuperInterfaces(vector); if (paralist != null){ this.set_ParaList(paralist); } @@ -214,7 +244,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit } // ino.end - + public Vector getFields() { return fielddecl; @@ -1097,6 +1127,9 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit for(Field f : this.getFields()){ if(f.isPublic())ret.add(f.createTypeAssumptions(this)); } + for(GenericTypeVar gtv : this.getGenericParameter()){ + ret.add(gtv.createAssumptions()); + } return ret; } @@ -1225,7 +1258,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit * Die Super Klasse dieser Klasse. * @return null für Klasse Object */ - public Class getSuperClass(){ + public Type getSuperClass(){ return this.superClass; } } diff --git a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java index 4c7046f9..51387bd8 100755 --- a/src/de/dhbwstuttgart/syntaxtree/SourceFile.java +++ b/src/de/dhbwstuttgart/syntaxtree/SourceFile.java @@ -252,7 +252,7 @@ public class SourceFile */ // ino.end // ino.method.createPairFromClassAndSuperclass.21400.definition - private Pair createPairFromClassAndSuperclass(Class baseClass, Class superclass, Vector classParaOrg, Vector superclassParaOrg) + private Pair createPairFromClassAndSuperclass(Class baseClass, Type superclass, Vector classParaOrg, Vector superclassParaOrg, TypeAssumptions ass) // ino.end // ino.method.createPairFromClassAndSuperclass.21400.body { @@ -269,10 +269,12 @@ public class SourceFile new RefType( superclassName.toString(), superclassParaOrg,-1) ); */ - Pair P = new Pair(baseClass.getType(), superclass.getType()); + Pair P = new Pair(baseClass.getType().TYPE(ass, baseClass).getType(), superclass.TYPE(ass, baseClass).getType()); //PL 04-12-29 freshe Variablen ANFANG RefType r1 = (RefType)P.getTA1Copy(); - RefType r2 = (RefType)P.getTA2Copy(); + RefType r2 = (RefType)P.getTA2Copy(); + r1 = (RefType) r1.TYPE(ass, baseClass).getType(); + r2 = (RefType) r2.TYPE(ass, baseClass).getType(); // #JB# 05.04.2005 // ########################################################### Hashtable substHash = new Hashtable(); //fuer jedes Paar komplett neue Variablen @@ -305,7 +307,8 @@ public class SourceFile // Menge FC bilden Vector vFC = new Vector(); // Menge FC - + TypeAssumptions globalAssumptions = this.makeBasicAssumptionsFromJRE(imports); + globalAssumptions.add(this.getPublicFieldAssumptions()); // 1. Menge <= in FC aufnehmen --> Iteration ueber alle Klassen for( int i = 0; i < KlassenVektor.size(); i++ ) @@ -314,14 +317,14 @@ public class SourceFile inferencelog.debug("Verarbeite "+tempKlasse.getName()); //TODO: SuperKlasse erstellen, dies sollte am besten beim Konstruktoraufruf von Class geschehen. Diese kann dann mit getSuperClass abgefragt werden. if( tempKlasse.superclassid != null ) { // Klasse hat Superklasse - Pair P=createPairFromClassAndSuperclass(tempKlasse,tempKlasse.getSuperClass(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList()); + Pair P=createPairFromClassAndSuperclass(tempKlasse,tempKlasse.getSuperClass(),tempKlasse.get_ParaList(),tempKlasse.superclassid.get_ParaList(), globalAssumptions); vFC.add( P ); } if(tempKlasse.getSuperInterfaces()!=null){ - Iterator interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); + Iterator interfaceIterator=tempKlasse.getSuperInterfaces().iterator(); while(interfaceIterator.hasNext()){ - Interface intf=interfaceIterator.next(); - Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList()); + RefType intf=(RefType) interfaceIterator.next(); + Pair P=createPairFromClassAndSuperclass(tempKlasse,intf,tempKlasse.get_ParaList(),intf.get_ParaList(),globalAssumptions); vFC.add( P ); } @@ -330,10 +333,10 @@ public class SourceFile for(int i=0; i interfaceIterator=intf.getSuperInterfaces().iterator(); + Iterator interfaceIterator=intf.getSuperInterfaces().iterator(); while(interfaceIterator.hasNext()){ - Interface superintf=interfaceIterator.next(); - Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList()); + RefType superintf=(RefType) interfaceIterator.next(); + Pair P=createPairFromClassAndSuperclass(intf,superintf,intf.getParaList(), superintf.get_ParaList(),globalAssumptions); vFC.add( P ); } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java index 405f84b5..229bfaeb 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/GenericTypeVar.java @@ -44,7 +44,7 @@ public class GenericTypeVar extends Type // ino.method.GenericTypeVar.26509.defdescription type=line // private Hashtable> m_TypeErasureList; // ino.end - private static HashMap tph = new HashMap(); + private static HashMap tph = new HashMap<>(); /** * @@ -170,12 +170,14 @@ public class GenericTypeVar extends Type */ return new JavaCodeResult(this.name.toString()); } - - public TypePlaceholder getTypePlaceHolder() { - if(!GenericTypeVar.tph.containsKey(this)){ - GenericTypeVar.tph.put(this, TypePlaceholder.fresh(this.getName().toString(),this)); + + public TypePlaceholder getTypePlaceHolder(SyntaxTreeNode environment) { + String hashValue = this.getName().toString()+environment.hashCode(); + if(!GenericTypeVar.tph.containsKey(hashValue)){ + GenericTypeVar.tph.put(hashValue, TypePlaceholder.fresh(hashValue,this)); } - return GenericTypeVar.tph.get(this); + return GenericTypeVar.tph.get(hashValue); + //return TypePlaceholder.fresh(this.getParent()); //if(this.tph == null)this.tph = TypePlaceholder.fresh(); //return this.tph; } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java index 801eb60f..f010cef6 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/RefType.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/RefType.java @@ -212,12 +212,12 @@ public class RefType extends Type implements IMatchable * Wandelt die Parameter des RefTypes in TPHs um, sofern es sich um Generische Variablen handelt. * @return */ - public void GTV2TPH(){ + public void GTV2TPH(SyntaxTreeNode environment){ Vector paralist = new Vector(); if(this.get_ParaList()!=null)for(Type t : this.get_ParaList()){ - if(t instanceof GenericTypeVar)paralist.add(((GenericTypeVar)t).getTypePlaceHolder()); + if(t instanceof GenericTypeVar)paralist.add(((GenericTypeVar)t).getTypePlaceHolder(environment)); else{ - if(t instanceof RefType)((RefType) t).GTV2TPH(); + if(t instanceof RefType)((RefType) t).GTV2TPH(environment); paralist.add(t); } } diff --git a/src/de/dhbwstuttgart/syntaxtree/type/Type.java b/src/de/dhbwstuttgart/syntaxtree/type/Type.java index 13f22fd7..1c178f2b 100755 --- a/src/de/dhbwstuttgart/syntaxtree/type/Type.java +++ b/src/de/dhbwstuttgart/syntaxtree/type/Type.java @@ -298,7 +298,7 @@ public class Type extends SyntaxTreeNode implements IItemWithOffset */ //TODO: checkType wird nicht mehr gebraucht. TYPE übernimmt dessen Aufgabe. Es muss nur sichergestellt werden, dass jeder Typ in den Constraints landet, dadurch wird für jeden Typ die Methode TYPE aufgerufen. public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent){ - ConstraintType t = ass.getTypeFor(this, this); + ConstraintType t = ass.getTypeFor(this, parent); if(t==null) throw new TypeinferenceException("Der Typ "+this.getName()+" ist nicht korrekt", parent); return t; diff --git a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java index 22759260..2a4d7521 100755 --- a/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java +++ b/src/de/dhbwstuttgart/typeinference/assumptions/TypeAssumptions.java @@ -311,13 +311,28 @@ public class TypeAssumptions { if(ass.getIdentifier().equals(t.getName())){ if(! ass.getAssumedType().getParentClass().getName().equals(this.thisClassName)){ //Ist die Generische Variable nicht aus dieser Klasse, so muss sie zu einem TPH umgewandelt werden: - return new ConstraintType(ass.getAssumedType().getTypePlaceHolder()); + return new ConstraintType(ass.getAssumedType().getTypePlaceHolder(inNode)); } return new ConstraintType(ass.getAssumedType()); } } //Spezialfälle bei char, int, boolean, .... - //TODO + String name = t.getName().toString(); + switch(name){ + case "int": + return new ConstraintType(new RefType("java.lang.Integer",t.getParent(),t.getOffset())); + case "boolean": + return new ConstraintType(new RefType("java.lang.Boolean",t.getParent(),t.getOffset())); + case "double": + return new ConstraintType(new RefType("java.lang.Double",t.getParent(),t.getOffset())); + case "float": + return new ConstraintType(new RefType("java.lang.Float",t.getParent(),t.getOffset())); + case "long": + return new ConstraintType(new RefType("java.lang.Long",t.getParent(),t.getOffset())); + case "char": + return new ConstraintType(new RefType("java.lang.Character",t.getParent(),t.getOffset())); + } + throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode); } diff --git a/test/parser/AntlrTest.jav b/test/parser/AntlrTest.jav index 43c1c252..31ab067d 100644 --- a/test/parser/AntlrTest.jav +++ b/test/parser/AntlrTest.jav @@ -1 +1,6 @@ -class Test{} \ No newline at end of file +class Test{ +method(){ + if(true)i++; + if(true)i--; + else i++; +}} \ No newline at end of file diff --git a/test/parser/FieldVarTest.jav b/test/parser/FieldVarTest.jav new file mode 100644 index 00000000..aeeecdbf --- /dev/null +++ b/test/parser/FieldVarTest.jav @@ -0,0 +1,3 @@ +class Test{ +Typ a; +} \ No newline at end of file diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index 7edd2fb8..6f0985db 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -33,6 +33,7 @@ public class GeneralParserTest{ filenames.add("ImportTest.jav"); filenames.add("BoundedParameter.jav"); filenames.add("GenericFieldVarTest.jav"); + filenames.add("FieldVarTest.jav"); MyCompilerAPI compiler = MyCompiler.getAPI(); try{ for(String filename : filenames) diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav index 6c08eff5..772f649b 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest.jav @@ -8,4 +8,4 @@ methode(){ class GTVTest2{ GTV2 var2; -} \ No newline at end of file +} diff --git a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav index 30a9b171..c1fd0e50 100644 --- a/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav +++ b/test/plugindevelopment/TypeInsertTests/GenericTypeVarTest2.jav @@ -1,8 +1,8 @@ class GTVTest{ GTVTest2 var; -var2; methode(){ + var2; return var.test(var2); } }