Einsetzen von GenericTypeVars an das Ende einer GenericTypeVarList verbessert

This commit is contained in:
JanUlrich 2014-07-31 15:15:33 +02:00
parent dbf493424e
commit 2925926e58
15 changed files with 279 additions and 205 deletions

View File

@ -299,7 +299,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%type <SourceFile> typedeclarations
%type <GenericTypeVar> boundedMethodParameter;
%type <GenericTypeVar> boundedClassParameter;
%type <Vector> boundedclassidentifierlist //Vector<Type>
%type <BoundedClassIdentifierList> boundedclassidentifierlist //Vector<Type>
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
%type <ParaList> boundedClassParameters; // ParaList
%type <UsedId> packagedeclaration
@ -1048,7 +1048,7 @@ boundedMethodParameter : IDENTIFIER
}
| IDENTIFIER EXTENDS boundedclassidentifierlist
{
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$3,$1.getOffset());
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(), $3, $1.getOffset() ,$3.getEndOffset());
//gtv.setBounds($3);
$$=gtv;
}
@ -1058,12 +1058,13 @@ boundedclassidentifierlist : referencetype
Vector<Type> vec=new Vector<Type>();
vec.addElement($1);
containedTypes.addElement($1);
$$=vec;
$$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().length());
}
| boundedclassidentifierlist '&' referencetype
{
$1.addElement($3);
containedTypes.addElement($3);
$1.addOffsetOff($3);
containedTypes.addElement($3);
$$=$1;
}
// returns Vector<Type>

View File

@ -1400,7 +1400,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
public int getGenericVarDeclarationOffset(){
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
if(this.genericClassParameters != null){
return this.genericClassParameters.getOffsetOfLastElement();
return this.genericClassParameters.getEndOffset();
}else{
return this.offset;
}

View File

@ -149,7 +149,7 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
public int getGenericVarDeclarationOffset(){
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
if(this.genericParameters != null){
return this.genericParameters.getOffsetOfLastElement();
return this.genericParameters.getEndOffset();
}else{
return this.offset;
}

View File

@ -16,12 +16,12 @@ public class GenericDeclarationList extends Vector<GenericTypeVar>{
private int offsetOfLastElement;
public GenericDeclarationList(Vector<GenericTypeVar> values, int offset) {
public GenericDeclarationList(Vector<GenericTypeVar> values, int endOffset) {
this.addAll(values);
this.offsetOfLastElement = offset;
this.offsetOfLastElement = endOffset;
}
public int getOffsetOfLastElement(){
public int getEndOffset(){
return offsetOfLastElement;
}
}

View File

@ -0,0 +1,25 @@
package mycompiler.myparser;
import java.util.Vector;
import mycompiler.mytype.RefType;
import mycompiler.mytype.Type;
public class BoundedClassIdentifierList extends Vector<Type>{
private int endOffset;
private Vector<Type> list;
public BoundedClassIdentifierList(Vector<Type> list, int endOffset){
this.endOffset = endOffset;
this.addAll(list);
}
public int getEndOffset() {
return endOffset;
}
public void addOffsetOff(RefType refType) {
this.endOffset = refType.getOffset() + refType.getName().length();
}
}

View File

@ -16,7 +16,7 @@ public class GenericVarDeclarationList {
public int getEndOffset() {
int ret;
if(elements.isEmpty())throw new DebugException("Es wurde eine GenericVarDeclarationList ohne Elemente geparst");
ret = elements.lastElement().getOffset() + elements.lastElement().getName().length();
ret = elements.lastElement().getEndOffset();
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@ -299,7 +299,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
%type <SourceFile> typedeclarations
%type <GenericTypeVar> boundedMethodParameter;
%type <GenericTypeVar> boundedClassParameter;
%type <Vector> boundedclassidentifierlist //Vector<Type>
%type <BoundedClassIdentifierList> boundedclassidentifierlist //Vector<Type>
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
%type <ParaList> boundedClassParameters; // ParaList
%type <UsedId> packagedeclaration
@ -1048,7 +1048,7 @@ boundedMethodParameter : IDENTIFIER
}
| IDENTIFIER EXTENDS boundedclassidentifierlist
{
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(),$3,$1.getOffset());
BoundedGenericTypeVar gtv=new BoundedGenericTypeVar($1.getLexem(), $3, $1.getOffset() ,$3.getEndOffset());
//gtv.setBounds($3);
$$=gtv;
}
@ -1058,12 +1058,13 @@ boundedclassidentifierlist : referencetype
Vector<Type> vec=new Vector<Type>();
vec.addElement($1);
containedTypes.addElement($1);
$$=vec;
$$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().length());
}
| boundedclassidentifierlist '&' referencetype
{
$1.addElement($3);
containedTypes.addElement($3);
$1.addOffsetOff($3);
containedTypes.addElement($3);
$$=$1;
}
// returns Vector<Type>

View File

@ -38,9 +38,11 @@ public class BoundedGenericTypeVar extends GenericTypeVar
// ino.attribute.bounds.26468.declaration
Vector<Type> bounds=new Vector<Type>();
// ino.end
private int endOffset;
/*
// ino.method.BoundedGenericTypeVar.26471.definition
public BoundedGenericTypeVar(String s, int offset, Vector<Type> t)
public BoundedGenericTypeVar(String s, int offset, Vector<Type> t, int endOffset)
// ino.end
// ino.method.BoundedGenericTypeVar.26471.body
{
@ -48,9 +50,10 @@ public class BoundedGenericTypeVar extends GenericTypeVar
throw new NotImplementedException();
}
// ino.end
*/
// ino.method.BoundedGenericTypeVar.29409.definition
public BoundedGenericTypeVar(String s, Vector<Type> bounds, int offset)
public BoundedGenericTypeVar(String s, Vector<Type> bounds, int offset, int endOffset)
// ino.end
// ino.method.BoundedGenericTypeVar.29409.body
{
@ -60,9 +63,15 @@ public class BoundedGenericTypeVar extends GenericTypeVar
}
//this.genericTypeVar = new RefType(s,offset);
this.bounds = bounds;
this.endOffset = endOffset;
}
// ino.end
@Override
public int getEndOffset(){
return this.endOffset;
}
// ino.method.getBounds.26474.definition
public Vector<Type> getBounds()
// ino.end
@ -102,7 +111,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
// ino.end
// ino.method.clone.26483.body
{
return new BoundedGenericTypeVar(this.getName(), this.getBounds(), getOffset());
return new BoundedGenericTypeVar(this.getName(), this.getBounds(), getOffset(), this.getEndOffset());
}
// ino.end

View File

@ -214,6 +214,10 @@ public class GenericTypeVar extends Type
ConstraintsSet ret = new ConstraintsSet();
return ret;
}
public int getEndOffset() {
return this.getOffset() + this.name.length();
}
}
// ino.end

View File

@ -162,6 +162,11 @@ public class GenericTypeInsertPoint extends SourcePatchPoint {
public int getInsertLength() {
return this.getTypeInsertString().length();
}
@Override
public String toString(){
return "GVIP: "+this.getTypeInsertString();
}
}
/**
@ -183,11 +188,6 @@ class GenericVarPatch {
if(!this.genericVarExtendDeclarations.contains(toAdd))this.genericVarExtendDeclarations.add(toAdd);
}
public void addTPH(TypePlaceholder tph){
GenericVarDeclarationPatch toAdd = new GenericVarDeclarationPatch(tph);
if(!this.genericVarDeclarations.contains(toAdd))this.genericVarDeclarations.add(toAdd);
}
public String getInsertString(ResultSet rs){
String ret = "";
Iterator<GenericVarDeclarationPatch> it1 = this.genericVarDeclarations.iterator();
@ -207,6 +207,8 @@ class GenericVarPatch {
}
public void add(TypePlaceholder tph) {
GenericVarDeclarationPatch toAdd = new GenericVarDeclarationPatch(tph);
if(!this.genericVarDeclarations.contains(toAdd))this.genericVarDeclarations.add(toAdd);
}
}

View File

@ -124,5 +124,10 @@ public class TypeInsertPoint extends SourcePatchPoint {
private TypeInsertable getTIP() {
return this.point;
}
@Override
public String toString(){
return "TIP: "+this.type;
}
}

View File

@ -5,6 +5,8 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Vector;
import org.apache.log4j.Logger;
import typinferenz.JavaCodeResult;
import typinferenz.ResultSet;
import typinferenz.TypeInsertable;
@ -33,7 +35,9 @@ import mycompiler.mytype.TypePlaceholder;
*
*/
public class TypeInsertSet {
//Logger:
protected Logger typinferenzLog = Logger.getLogger("Typeinference");
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
private Vector<GenericTypeInsertPoint> genericTypeInsertPoints = new Vector<GenericTypeInsertPoint>();
private ResultSet resultSet;
@ -87,12 +91,13 @@ public class TypeInsertSet {
if(! tip.getInsertNode().seesType(pair.TA2)){
for(TypePlaceholder tph : pair.getTypePlaceholder()){
if(! pairsDeclareTPH(pairs, tph)){
gPatch.addTPH(tph);
gPatch.add(tph);
}
}
}
}
GenericTypeInsertPoint gip = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(), gPatch, resultSet);
typinferenzLog.debug("Erstellter GenericTypeInsertPoint: "+gip);
tpj.add(tip);
tpj.add(gip);
}

View File

@ -0,0 +1,5 @@
class Matrix{
<T1, B extends T1> op(B m){
return (f) -> f.apply(m,this);
}
}

View File

@ -0,0 +1,16 @@
package plugindevelopment.TypeInsertTests;
import java.util.Vector;
import org.junit.Test;
public class LambdaTest14 {
private static final String TEST_FILE = "LambdaTest14.jav";
@Test
public void run(){
Vector<String> mustContain = new Vector<String>();
//mustContain.add("A a");
MultipleTypesInsertTester.testSingleInsert(this.TEST_FILE, mustContain);
}
}