forked from JavaTX/JavaCompilerCore
Einsetzen von Generics geändert. Unvollständiger Zustand
This commit is contained in:
parent
eec8e4d1a8
commit
edfa85df7f
6
.project
6
.project
@ -7,12 +7,16 @@
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
|
||||
<triggers>clean,incremental,</triggers>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>LaunchConfigHandle</key>
|
||||
<value><project>/.externalToolBuilders/JavaParserBuilder.launch</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>incclean</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
|
@ -211,6 +211,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
|
||||
%type <ClassAndParameter> classidentifier
|
||||
%type <InterfaceAndParameter> interfaceidentifier
|
||||
%type <Constant> constantdeclaration
|
||||
%type <GenericDeclarationList> genericdeclarationlist
|
||||
%type <Field> fielddeclaration
|
||||
%type <Method> methodheader
|
||||
%type <Method> methoddeclaration
|
||||
@ -901,6 +902,14 @@ fielddeclarator :
|
||||
$$=ret;
|
||||
}
|
||||
|
||||
|
||||
genericdeclarationlist : '<' boundedMethodParameters '>'
|
||||
{
|
||||
GenericDeclarationList ret = new GenericDeclarationList($2);
|
||||
ret.setOffset($3.getOffset());
|
||||
$$ = ret;
|
||||
}
|
||||
|
||||
fielddeclaration : fielddeclarator ';'
|
||||
{
|
||||
$$=$1;
|
||||
@ -910,11 +919,11 @@ fielddeclaration : fielddeclarator ';'
|
||||
$2.setType($1);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type fielddeclarator ';'
|
||||
| genericdeclarationlist type fielddeclarator ';'
|
||||
{//angefügt von Andreas Stadelmeier
|
||||
$5.setType($4);
|
||||
$5.setGenericParameter($2);
|
||||
$$=$5;
|
||||
$3.setType($2);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
|
|
||||
variabledeclarators ';'
|
||||
@ -1065,11 +1074,11 @@ boundedMethodParameters : boundedMethodParameter
|
||||
|
||||
|
||||
// returns Method
|
||||
methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
methodheader :genericdeclarationlist type methoddeclarator
|
||||
{
|
||||
$5.setType($4);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
$3.setType($2);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| type methoddeclarator
|
||||
{
|
||||
@ -1082,12 +1091,12 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.setType($2);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' type methoddeclarator
|
||||
| modifiers genericdeclarationlist type methoddeclarator
|
||||
{
|
||||
$6.set_Modifiers($1);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$6.setType($5);
|
||||
$$=$6;
|
||||
$4.set_Modifiers($1);
|
||||
$4.setGenericParameter($2);
|
||||
$4.setType($3);
|
||||
$$=$4;
|
||||
}
|
||||
| type methoddeclarator throws
|
||||
{
|
||||
@ -1095,12 +1104,12 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$2.set_ExceptionList($3);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type methoddeclarator throws
|
||||
| genericdeclarationlist type methoddeclarator throws
|
||||
{
|
||||
$5.setGenericMethodParameters($2);
|
||||
$5.setType($4);
|
||||
$5.set_ExceptionList($6);
|
||||
$$=$5;
|
||||
$3.setGenericParameter($1);
|
||||
$3.setType($2);
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers type methoddeclarator throws
|
||||
{
|
||||
@ -1109,13 +1118,13 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' type methoddeclarator throws
|
||||
| modifiers genericdeclarationlist type methoddeclarator throws
|
||||
{
|
||||
$6.set_Modifiers($1);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$6.setType($5);
|
||||
$6.set_ExceptionList($7);
|
||||
$$=$6;
|
||||
$4.set_Modifiers($1);
|
||||
$4.setGenericParameter($2);
|
||||
$4.setType($3);
|
||||
$4.set_ExceptionList($5);
|
||||
$$=$4;
|
||||
}
|
||||
| VOID methoddeclarator
|
||||
{
|
||||
@ -1145,37 +1154,37 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' VOID methoddeclarator
|
||||
| genericdeclarationlist VOID methoddeclarator
|
||||
{
|
||||
Void Voit = new Void($4.getOffset());
|
||||
$5.setType(Voit);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
Void Voit = new Void($2.getOffset());
|
||||
$3.setType(Voit);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' VOID methoddeclarator
|
||||
| modifiers genericdeclarationlist VOID methoddeclarator
|
||||
{
|
||||
Void voit = new Void($5.getOffset());
|
||||
$6.set_Modifiers($1);
|
||||
$6.setType(voit);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$$=$6;
|
||||
Void voit = new Void($3.getOffset());
|
||||
$4.set_Modifiers($1);
|
||||
$4.setType(voit);
|
||||
$4.setGenericParameter($2);
|
||||
$$=$4;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' VOID methoddeclarator throws
|
||||
| genericdeclarationlist VOID methoddeclarator throws
|
||||
{
|
||||
Void voyt = new Void($4.getOffset());
|
||||
$5.setType(voyt);
|
||||
$5.set_ExceptionList($6);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
Void voyt = new Void($2.getOffset());
|
||||
$3.setType(voyt);
|
||||
$3.set_ExceptionList($4);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' VOID methoddeclarator throws
|
||||
| modifiers genericdeclarationlist VOID methoddeclarator throws
|
||||
{
|
||||
Void voyd = new Void($5.getOffset());
|
||||
$6.set_Modifiers($1);
|
||||
$6.setType(voyd);
|
||||
$6.set_ExceptionList($7);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$$=$6;
|
||||
Void voyd = new Void($3.getOffset());
|
||||
$4.set_Modifiers($1);
|
||||
$4.setType(voyd);
|
||||
$4.set_ExceptionList($5);
|
||||
$4.setGenericParameter($2);
|
||||
$$=$4;
|
||||
}
|
||||
|
||||
| methoddeclarator
|
||||
@ -1183,11 +1192,11 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) $1.setType(TypePlaceholder.fresh());
|
||||
$$=$1;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' methoddeclarator
|
||||
| genericdeclarationlist methoddeclarator
|
||||
{
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) $4.setType(TypePlaceholder.fresh());
|
||||
$4.setGenericMethodParameters($2);
|
||||
$$=$4;
|
||||
$2.setGenericParameter($1);
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
| modifiers methoddeclarator
|
||||
|
@ -2,11 +2,11 @@ package mycompiler;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.GenericTypeInsertPoint;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.exceptions.TypeinferenceException;
|
||||
import typinferenz.typedeployment.GenericTypeInsertPoint;
|
||||
import typinferenz.typedeployment.TypeInsertPoint;
|
||||
import typinferenz.typedeployment.TypeInsertSet;
|
||||
import mycompiler.myclass.Class;
|
||||
@ -86,17 +86,12 @@ public abstract class SyntaxTreeNode{
|
||||
tip = that.createTypeInsertPoint((TypePlaceholder) t, result);
|
||||
insertSet.add(tip);//ret.addAll(((TypePlaceholder)t).getTypeInsertPoints(result));
|
||||
}
|
||||
|
||||
/*
|
||||
//Für den Fall, dass dieser Knoten Generische Variablen halten kann.
|
||||
if(that instanceof Generic && that.getOffset()>=0){
|
||||
//Alle unresolvedTPHs ermitteln und GenericTypeVarInsertPoints bilden:
|
||||
Vector<TypePlaceholder> uTPHs = insertSet.getUnresolvedTPHs();
|
||||
/*
|
||||
for(TypePlaceholder tph : uTPHs){//GenericInsertPoints für diese TPHs bilden:
|
||||
GenericTypeInsertPoint genericTIP = new GenericTypeInsertPoint(that,tph,result);
|
||||
insertSet.add(genericTIP);
|
||||
}
|
||||
*/
|
||||
|
||||
if(uTPHs.size()>0){//Nur wenn es auch unresolvedTPHs gibt:
|
||||
Vector<Pair> gPairs = result.getConstraintsFor(uTPHs);
|
||||
if(gPairs.size()>0){
|
||||
@ -105,7 +100,7 @@ public abstract class SyntaxTreeNode{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -64,6 +64,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.ConstraintsSet;
|
||||
import typinferenz.JavaCodeResult;
|
||||
@ -162,7 +163,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
|
||||
public static boolean isFirstLocalVarDecl; //Hilfsvariable fuer Offsets, hoth
|
||||
// ino.end
|
||||
|
||||
private Vector<GenericTypeVar> genericClassParameters=new Vector<GenericTypeVar>();
|
||||
//private Vector<GenericTypeVar> genericClassParameters=new Vector<GenericTypeVar>();
|
||||
|
||||
// ino.attribute.containedTypes.23032.decldescription type=line
|
||||
// PL 05-07-30 eingefuegt. Vektor aller Typdeklarationen, die in der Klasse
|
||||
@ -183,6 +184,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
|
||||
protected Logger typinferenzLog = Logger.getLogger("Typeinference");
|
||||
private SyntaxTreeNode parent;
|
||||
private Vector<Field> fielddecl = new Vector<Field>();
|
||||
private GenericDeclarationList genericClassParameters;
|
||||
|
||||
|
||||
// ino.method.Class.23041.definition
|
||||
@ -1218,7 +1220,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
|
||||
* @param tphs : Alle übriggebliebenen TypePLaceholder
|
||||
*/
|
||||
private void createGenericTypeVars(Vector<TypePlaceholder> tphs){
|
||||
this.genericClassParameters = new Vector<GenericTypeVar>();
|
||||
this.genericClassParameters = new GenericDeclarationList(new Vector<GenericTypeVar>());
|
||||
for(TypePlaceholder tph : tphs){
|
||||
GenericTypeVar toAdd = new GenericTypeVar(tph,this.getOffset());
|
||||
if(!this.genericClassParameters.contains(toAdd))this.genericClassParameters.add(toAdd);
|
||||
@ -1362,10 +1364,17 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params) {
|
||||
public void setGenericParameter(GenericDeclarationList params) {
|
||||
this.genericClassParameters = params;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGenericDeclOffset() {
|
||||
//TODO: Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -26,6 +26,8 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
|
||||
|
||||
private int offset;
|
||||
|
||||
private GenericDeclarationList genericParameters;
|
||||
|
||||
public Field(int offset){
|
||||
this.offset = offset;
|
||||
}
|
||||
@ -128,6 +130,14 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getGenericDeclOffset() {
|
||||
//TODO: Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(GenericDeclarationList params) {
|
||||
this.genericParameters = params;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class FieldDeclaration extends Field{
|
||||
|
||||
private Expr wert;
|
||||
//private Type type;
|
||||
private Vector<GenericTypeVar> parameter;
|
||||
//private Vector<GenericTypeVar> parameter;
|
||||
|
||||
/**
|
||||
* Dieser Konstruktor der FieldDeclaration erstellt den Syntaxknoten vollständig.
|
||||
@ -164,9 +164,4 @@ public class FieldDeclaration extends Field{
|
||||
if(this.getWert()!=null)this.getWert().wandleRefTypeAttributes2GenericAttributes(paralist, new Vector<GenericTypeVar>()); //FieldDeclaration hat keine Generischen Variablen, daher leere Liste übergeben
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params) {
|
||||
this.parameter = params;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,10 @@ import mycompiler.mytype.GenericTypeVar;
|
||||
*
|
||||
*/
|
||||
public interface Generic {
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params);
|
||||
//public int getGenericParameterOffset();
|
||||
public void setGenericParameter(GenericDeclarationList params);
|
||||
/**
|
||||
* Gibt den Offset im Quellcode an, an dem neue Deklarationen von generischen Variablen eingesetzt werden können.
|
||||
* @return
|
||||
*/
|
||||
public int getGenericDeclOffset();
|
||||
}
|
@ -753,10 +753,7 @@ public class Method extends Field implements IItemWithOffset, TypeInsertable
|
||||
return super.equals(obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setGenericParameter(Vector<GenericTypeVar> params) {
|
||||
this.genericMethodParameters = params;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -211,6 +211,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
|
||||
%type <ClassAndParameter> classidentifier
|
||||
%type <InterfaceAndParameter> interfaceidentifier
|
||||
%type <Constant> constantdeclaration
|
||||
%type <GenericDeclarationList> genericdeclarationlist
|
||||
%type <Field> fielddeclaration
|
||||
%type <Method> methodheader
|
||||
%type <Method> methoddeclaration
|
||||
@ -901,6 +902,14 @@ fielddeclarator :
|
||||
$$=ret;
|
||||
}
|
||||
|
||||
|
||||
genericdeclarationlist : '<' boundedMethodParameters '>'
|
||||
{
|
||||
GenericDeclarationList ret = new GenericDeclarationList($2);
|
||||
ret.setOffset($3.getOffset());
|
||||
$$ = ret;
|
||||
}
|
||||
|
||||
fielddeclaration : fielddeclarator ';'
|
||||
{
|
||||
$$=$1;
|
||||
@ -910,11 +919,11 @@ fielddeclaration : fielddeclarator ';'
|
||||
$2.setType($1);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type fielddeclarator ';'
|
||||
| genericdeclarationlist type fielddeclarator ';'
|
||||
{//angefügt von Andreas Stadelmeier
|
||||
$5.setType($4);
|
||||
$5.setGenericParameter($2);
|
||||
$$=$5;
|
||||
$3.setType($2);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
|
|
||||
variabledeclarators ';'
|
||||
@ -1065,11 +1074,11 @@ boundedMethodParameters : boundedMethodParameter
|
||||
|
||||
|
||||
// returns Method
|
||||
methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
methodheader :genericdeclarationlist type methoddeclarator
|
||||
{
|
||||
$5.setType($4);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
$3.setType($2);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| type methoddeclarator
|
||||
{
|
||||
@ -1082,12 +1091,12 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.setType($2);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' type methoddeclarator
|
||||
| modifiers genericdeclarationlist type methoddeclarator
|
||||
{
|
||||
$6.set_Modifiers($1);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$6.setType($5);
|
||||
$$=$6;
|
||||
$4.set_Modifiers($1);
|
||||
$4.setGenericParameter($2);
|
||||
$4.setType($3);
|
||||
$$=$4;
|
||||
}
|
||||
| type methoddeclarator throws
|
||||
{
|
||||
@ -1095,12 +1104,12 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$2.set_ExceptionList($3);
|
||||
$$=$2;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' type methoddeclarator throws
|
||||
| genericdeclarationlist type methoddeclarator throws
|
||||
{
|
||||
$5.setGenericMethodParameters($2);
|
||||
$5.setType($4);
|
||||
$5.set_ExceptionList($6);
|
||||
$$=$5;
|
||||
$3.setGenericParameter($1);
|
||||
$3.setType($2);
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers type methoddeclarator throws
|
||||
{
|
||||
@ -1109,13 +1118,13 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' type methoddeclarator throws
|
||||
| modifiers genericdeclarationlist type methoddeclarator throws
|
||||
{
|
||||
$6.set_Modifiers($1);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$6.setType($5);
|
||||
$6.set_ExceptionList($7);
|
||||
$$=$6;
|
||||
$4.set_Modifiers($1);
|
||||
$4.setGenericParameter($2);
|
||||
$4.setType($3);
|
||||
$4.set_ExceptionList($5);
|
||||
$$=$4;
|
||||
}
|
||||
| VOID methoddeclarator
|
||||
{
|
||||
@ -1145,37 +1154,37 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
$3.set_ExceptionList($4);
|
||||
$$=$3;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' VOID methoddeclarator
|
||||
| genericdeclarationlist VOID methoddeclarator
|
||||
{
|
||||
Void Voit = new Void($4.getOffset());
|
||||
$5.setType(Voit);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
Void Voit = new Void($2.getOffset());
|
||||
$3.setType(Voit);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' VOID methoddeclarator
|
||||
| modifiers genericdeclarationlist VOID methoddeclarator
|
||||
{
|
||||
Void voit = new Void($5.getOffset());
|
||||
$6.set_Modifiers($1);
|
||||
$6.setType(voit);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$$=$6;
|
||||
Void voit = new Void($3.getOffset());
|
||||
$4.set_Modifiers($1);
|
||||
$4.setType(voit);
|
||||
$4.setGenericParameter($2);
|
||||
$$=$4;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' VOID methoddeclarator throws
|
||||
| genericdeclarationlist VOID methoddeclarator throws
|
||||
{
|
||||
Void voyt = new Void($4.getOffset());
|
||||
$5.setType(voyt);
|
||||
$5.set_ExceptionList($6);
|
||||
$5.setGenericMethodParameters($2);
|
||||
$$=$5;
|
||||
Void voyt = new Void($2.getOffset());
|
||||
$3.setType(voyt);
|
||||
$3.set_ExceptionList($4);
|
||||
$3.setGenericParameter($1);
|
||||
$$=$3;
|
||||
}
|
||||
| modifiers '<' boundedMethodParameters '>' VOID methoddeclarator throws
|
||||
| modifiers genericdeclarationlist VOID methoddeclarator throws
|
||||
{
|
||||
Void voyd = new Void($5.getOffset());
|
||||
$6.set_Modifiers($1);
|
||||
$6.setType(voyd);
|
||||
$6.set_ExceptionList($7);
|
||||
$6.setGenericMethodParameters($3);
|
||||
$$=$6;
|
||||
Void voyd = new Void($3.getOffset());
|
||||
$4.set_Modifiers($1);
|
||||
$4.setType(voyd);
|
||||
$4.set_ExceptionList($5);
|
||||
$4.setGenericParameter($2);
|
||||
$$=$4;
|
||||
}
|
||||
|
||||
| methoddeclarator
|
||||
@ -1183,11 +1192,11 @@ methodheader :'<' boundedMethodParameters '>' type methoddeclarator
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) $1.setType(TypePlaceholder.fresh());
|
||||
$$=$1;
|
||||
}
|
||||
| '<' boundedMethodParameters '>' methoddeclarator
|
||||
| genericdeclarationlist methoddeclarator
|
||||
{
|
||||
//auskommentiert von Andreas Stadelmeier (a10023) $4.setType(TypePlaceholder.fresh());
|
||||
$4.setGenericMethodParameters($2);
|
||||
$$=$4;
|
||||
$2.setGenericParameter($1);
|
||||
$$=$2;
|
||||
}
|
||||
|
||||
| modifiers methoddeclarator
|
||||
|
@ -20,6 +20,7 @@ import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
@ -770,6 +771,15 @@ public class RefType extends Type implements IMatchable
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<TypePlaceholder> getInvolvedTypePlaceholder() {
|
||||
Vector<TypePlaceholder> ret = super.getInvolvedTypePlaceholder();
|
||||
for(Type param : this.parameter){
|
||||
ret.addAll(param.getInvolvedTypePlaceholder());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
||||
|
@ -291,5 +291,14 @@ public class Type implements IItemWithOffset
|
||||
return t;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sammelt alle TypePlaceholder, welche in diesem Typ vorkommen.
|
||||
* @return
|
||||
*/
|
||||
public Vector<TypePlaceholder> getInvolvedTypePlaceholder(){
|
||||
Vector<TypePlaceholder> ret = new Vector<>();
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
// ino.end
|
||||
|
@ -115,6 +115,13 @@ public class TypePlaceholder extends Type implements IReplaceTypeEventProvider
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Vector<TypePlaceholder> getInvolvedTypePlaceholder() {
|
||||
Vector<TypePlaceholder> ret = super.getInvolvedTypePlaceholder();
|
||||
ret.add(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ino.method.makeNewName.26803.defdescription type=javadoc
|
||||
/**
|
||||
* Berechnet einen neuen, eindeutigen Namen f<EFBFBD>r eine neue
|
||||
|
@ -9,6 +9,7 @@ import mycompiler.mytype.TypePlaceholder;
|
||||
public class JavaCodeResult{
|
||||
|
||||
private String javaCode = "";
|
||||
//TODO: unresolvedTPHs entfernen. BROKEN!
|
||||
private Vector<TypePlaceholder> unresolvedTPHs = new Vector<TypePlaceholder>();
|
||||
|
||||
public JavaCodeResult(){
|
||||
|
@ -1,10 +1,12 @@
|
||||
package typinferenz;
|
||||
package typinferenz.typedeployment;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertable;
|
||||
import typinferenz.exceptions.DebugException;
|
||||
import typinferenz.typedeployment.TypeInsertPoint;
|
||||
import mycompiler.IItemWithOffset;
|
||||
import mycompiler.SyntaxTreeNode;
|
||||
import mycompiler.mytype.GenericTypeVar;
|
||||
@ -18,41 +20,38 @@ import mycompiler.mytype.TypePlaceholder;
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
public class GenericTypeInsertPoint extends SourcePatchPoint {
|
||||
|
||||
|
||||
private Vector<Pair> genericPairs = new Vector<Pair>();
|
||||
|
||||
public GenericTypeInsertPoint(TypeInsertPoint p) {
|
||||
super(p.point, p.type, p.resultSet);
|
||||
}
|
||||
private GenericVarPatch patch;
|
||||
|
||||
/*
|
||||
* TODO: Der Generic Type Insert Point sollte mit Generics konstruiert werden.
|
||||
* Dabei hält jeder InsertPoint nur ein Generic. Die <>-Klammern fügt das insertSet in den Quellcode ein.
|
||||
* Die Reihenfolge der GenericTIPs ist beim Einsetzen dann egal.
|
||||
*/
|
||||
public GenericTypeInsertPoint(TypeInsertable syntaxTreeNode,
|
||||
TypePlaceholder tph ,ResultSet resultSet) {
|
||||
super(syntaxTreeNode, tph, resultSet);
|
||||
GenericVarPatch gtv ,ResultSet resultSet) {
|
||||
this.patch = gtv;
|
||||
this.point = syntaxTreeNode;
|
||||
}
|
||||
|
||||
/*
|
||||
public GenericTypeInsertPoint(TypeInsertable syntaxTreeNode,
|
||||
Vector<Pair> pairs,ResultSet resultSet) {
|
||||
super(syntaxTreeNode, null, resultSet);
|
||||
this.genericPairs = pairs;
|
||||
if(this.genericPairs.size() == 0)throw new DebugException("Menge der generischen Paare ist leer");
|
||||
}
|
||||
|
||||
/**
|
||||
* Fügt eine generische Variable in Form eines Pairs an.
|
||||
* @param p
|
||||
*/
|
||||
public void addGenericPair(Pair p){
|
||||
if(!this.genericPairs.contains(p))this.genericPairs.add(p);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public JavaCodeResult getTypeInsertString() {
|
||||
//if(genericPairs.size()==0)return new JavaCodeResult();
|
||||
return super.getTypeInsertString();
|
||||
return this.patch.getInsertString();
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
protected Type getInsertType(){
|
||||
if(genericPairs.size()==0){
|
||||
@ -83,6 +82,7 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
this.type = new RefType(genericTypeParameters,0);
|
||||
return this.type;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
@ -91,19 +91,15 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeInsertPoint arg0) {
|
||||
int ret = new Integer(this.getOffset()).compareTo(new Integer(arg0.getOffset()));
|
||||
if(ret == 0){
|
||||
if(! (arg0 instanceof GenericTypeInsertPoint)){
|
||||
ret = new Integer(this.getOffset()-1).compareTo(new Integer(arg0.getOffset()));
|
||||
}
|
||||
}
|
||||
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.
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
public TypeInsertable getInsertNode(){
|
||||
return super.getGenericTypeVarInsertNode();
|
||||
return this.point;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +107,7 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
* basierend auf ihren insertPoints.
|
||||
* @param p2
|
||||
* @return - Die bei der Zusammenf<FC>hrung entstandene GenericTypeInser
|
||||
*/
|
||||
|
||||
public Vector<GenericTypeInsertPoint> merge(GenericTypeInsertPoint p2) {
|
||||
Vector<GenericTypeInsertPoint> ret = new Vector<GenericTypeInsertPoint>();
|
||||
if(this.getInsertNode().equals(p2.getInsertNode())){
|
||||
@ -123,14 +119,15 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
*/
|
||||
@Override
|
||||
public JavaCodeResult insertType(String fileContent, int additionalOffset) {
|
||||
public JavaCodeResult patch(String fileContent, int additionalOffset) {
|
||||
//TODO: Es kann sein, dass eine Methode bereits Generische Variablen hat, diese müssen dann an diese Liste angefügt werden.
|
||||
|
||||
return super.insertType(fileContent, additionalOffset);
|
||||
return super.patch(fileContent, additionalOffset);
|
||||
}
|
||||
|
||||
/*
|
||||
public boolean associatedWith(TypeInsertPoint tip, ResultSet resultSet) {
|
||||
if((tip.type instanceof TypePlaceholder)){
|
||||
Vector<TypePlaceholder> tphs = new Vector<>();
|
||||
@ -144,4 +141,9 @@ public class GenericTypeInsertPoint extends TypeInsertPoint {
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public int getOffset() {
|
||||
return point.getOffset();
|
||||
}
|
||||
}
|
@ -19,11 +19,10 @@ import mycompiler.mytypereconstruction.replacementlistener.ITypeReplacementListe
|
||||
* @author janulrich
|
||||
*
|
||||
*/
|
||||
public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
|
||||
public class TypeInsertPoint extends SourcePatchPoint {
|
||||
|
||||
|
||||
public TypeInsertable point;
|
||||
public Type type;
|
||||
public ResultSet resultSet;
|
||||
|
||||
/**
|
||||
* Dieser Konstruktor erstellt einen TypInsertPoint
|
||||
@ -44,7 +43,7 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
|
||||
* @param additionalOffset - Falls mehrere Typen in einen Quellcode eingesetzet werden muss die Verschiebung der Offsets mit einbezogen werden.
|
||||
* @return
|
||||
*/
|
||||
public JavaCodeResult insertType(String fileContent, int additionalOffset) {
|
||||
public JavaCodeResult patch(String fileContent, int additionalOffset) {
|
||||
String anfang = fileContent.substring(0, this.getInsertNode().getOffset()+additionalOffset);
|
||||
JavaCodeResult mitte = this.getTypeInsertString();
|
||||
String ende = fileContent.substring(this.getInsertNode().getOffset()+additionalOffset);
|
||||
@ -94,23 +93,16 @@ public class TypeInsertPoint implements Comparable<TypeInsertPoint>{
|
||||
if(! (obj instanceof TypeInsertPoint))return false;
|
||||
TypeInsertPoint equals = (TypeInsertPoint) obj;
|
||||
if(!(equals.getInsertNode().equals(this.getInsertNode())))return false;
|
||||
if(!(equals.resultSet.equals(this.resultSet)))return false; //ResultSet spielt bei Equals keine Rolle
|
||||
if(!(equals.getResultSet().equals(this.getResultSet())))return false; //ResultSet spielt bei Equals keine Rolle
|
||||
if(!(equals.getInsertType().equals(this.getInsertType())))return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TypeInsertPoint arg0) {
|
||||
return new Integer(this.getOffset()).compareTo(new Integer(arg0.getOffset()));
|
||||
}
|
||||
|
||||
public ResultSet getResultSet() {
|
||||
return resultSet;
|
||||
}
|
||||
|
||||
public TypeInsertable getGenericTypeVarInsertNode() {
|
||||
SyntaxTreeNode ret = (SyntaxTreeNode)this.point;
|
||||
SyntaxTreeNode ret = (SyntaxTreeNode)this.getTIP();
|
||||
while(!(ret instanceof Field || ret instanceof Class)){
|
||||
ret = ret.getParent();
|
||||
if(ret == null){
|
||||
|
@ -5,7 +5,6 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import typinferenz.GenericTypeInsertPoint;
|
||||
import typinferenz.JavaCodeResult;
|
||||
import typinferenz.ResultSet;
|
||||
import typinferenz.TypeInsertable;
|
||||
@ -19,8 +18,7 @@ import mycompiler.mytype.TypePlaceholder;
|
||||
/*
|
||||
* Der Plan:
|
||||
* SyntaxTreeNode generiert die TypeInsertPoints.
|
||||
* Beim Einsetzen eines TIP werden die ebenfalls von den SyntaxTreeNodes berechneten GenericInsertPoints durchsucht nach den Punkten
|
||||
* die mit dem einzusetzenden TIP zusammenhängen.
|
||||
* SyntaxTreeNode berechnet nicht die GenericInsertPoints. Das wird vom InsertSet übernommen.
|
||||
* Das funktioniert mithilfe des ResultSets. Denn es müssen alle Constraints mit einbezogen werden, da der Unify
|
||||
* Algorithmus als Ergebnis nur die zu einem RefType aufgelösten TPHs ausgibt.
|
||||
*/
|
||||
@ -68,13 +66,16 @@ public class TypeInsertSet {
|
||||
*/
|
||||
public String insertType(TypeInsertPoint tip, String fileContent){
|
||||
TypePatchJob tpj = new TypePatchJob();
|
||||
/*
|
||||
int additionalOffset = 0;
|
||||
String ret = fileContent;
|
||||
JavaCodeResult unresolvedTPHs = tip.insertType(ret, additionalOffset);
|
||||
JavaCodeResult unresolvedTPHs = tip.patch(ret, additionalOffset);
|
||||
for(TypePlaceholder tph : unresolvedTPHs.getUnresolvedTPH()){
|
||||
GenericTypeInsertPoint genericTIP = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(),tph,tip.getResultSet());
|
||||
tpj.add(genericTIP);
|
||||
}
|
||||
|
||||
*/
|
||||
tpj.add(tip);
|
||||
|
||||
return tpj.run(fileContent);
|
||||
@ -86,12 +87,13 @@ public class TypeInsertSet {
|
||||
* @param tpj
|
||||
*/
|
||||
public void insertType(TypeInsertPoint tip, TypePatchJob tpj){
|
||||
for(GenericTypeInsertPoint gip : this.genericTypeInsertPoints){
|
||||
if(gip.associatedWith(tip, this.resultSet)){
|
||||
tpj.add(gip);
|
||||
}
|
||||
GenericVarPatch gPatch = new GenericVarPatch();//Set der Einzusetzenden generischen Variablendeklarationen
|
||||
for(Pair pair : this.resultSet.getConstraintsFor(tip.getInsertType().getInvolvedTypePlaceholder())){
|
||||
gPatch.add(pair);
|
||||
}
|
||||
GenericTypeInsertPoint gip = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(), gPatch, resultSet);
|
||||
tpj.add(tip);
|
||||
tpj.add(gip);
|
||||
}
|
||||
|
||||
|
||||
@ -208,17 +210,17 @@ public class TypeInsertSet {
|
||||
* Stellt eine Reihe von TypeInsertions dar
|
||||
*/
|
||||
class TypePatchJob{
|
||||
private Vector<TypeInsertPoint> points = new Vector<>();
|
||||
void add(TypeInsertPoint tip){
|
||||
private Vector<SourcePatchPoint> points = new Vector<>();
|
||||
void add(SourcePatchPoint tip){
|
||||
points.add(tip);
|
||||
}
|
||||
String run(String fileContent){
|
||||
//sortieren (nach dem Offset der InsertPoints):
|
||||
Collections.sort(points);
|
||||
int additionalOffset = 0;
|
||||
for(TypeInsertPoint p : points){
|
||||
for(SourcePatchPoint p : points){
|
||||
//Zuerst den Typ einsetzen
|
||||
JavaCodeResult insertCode = p.insertType(fileContent, additionalOffset);
|
||||
JavaCodeResult insertCode = p.patch(fileContent, additionalOffset);
|
||||
fileContent = insertCode.toString();
|
||||
//Dann Additional Offset korrigieren:
|
||||
additionalOffset += p.getInsertLength();
|
||||
|
Loading…
Reference in New Issue
Block a user