forked from JavaTX/JavaCompilerCore
Einsetzen von GenericTypeVars an das Ende einer GenericTypeVarList verbessert
This commit is contained in:
parent
dbf493424e
commit
2925926e58
@ -299,7 +299,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
|
|||||||
%type <SourceFile> typedeclarations
|
%type <SourceFile> typedeclarations
|
||||||
%type <GenericTypeVar> boundedMethodParameter;
|
%type <GenericTypeVar> boundedMethodParameter;
|
||||||
%type <GenericTypeVar> boundedClassParameter;
|
%type <GenericTypeVar> boundedClassParameter;
|
||||||
%type <Vector> boundedclassidentifierlist //Vector<Type>
|
%type <BoundedClassIdentifierList> boundedclassidentifierlist //Vector<Type>
|
||||||
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
|
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
|
||||||
%type <ParaList> boundedClassParameters; // ParaList
|
%type <ParaList> boundedClassParameters; // ParaList
|
||||||
%type <UsedId> packagedeclaration
|
%type <UsedId> packagedeclaration
|
||||||
@ -1048,7 +1048,7 @@ boundedMethodParameter : IDENTIFIER
|
|||||||
}
|
}
|
||||||
| IDENTIFIER EXTENDS boundedclassidentifierlist
|
| 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.setBounds($3);
|
||||||
$$=gtv;
|
$$=gtv;
|
||||||
}
|
}
|
||||||
@ -1058,12 +1058,13 @@ boundedclassidentifierlist : referencetype
|
|||||||
Vector<Type> vec=new Vector<Type>();
|
Vector<Type> vec=new Vector<Type>();
|
||||||
vec.addElement($1);
|
vec.addElement($1);
|
||||||
containedTypes.addElement($1);
|
containedTypes.addElement($1);
|
||||||
$$=vec;
|
$$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().length());
|
||||||
}
|
}
|
||||||
| boundedclassidentifierlist '&' referencetype
|
| boundedclassidentifierlist '&' referencetype
|
||||||
{
|
{
|
||||||
$1.addElement($3);
|
$1.addElement($3);
|
||||||
containedTypes.addElement($3);
|
$1.addOffsetOff($3);
|
||||||
|
containedTypes.addElement($3);
|
||||||
$$=$1;
|
$$=$1;
|
||||||
}
|
}
|
||||||
// returns Vector<Type>
|
// returns Vector<Type>
|
||||||
|
@ -1400,7 +1400,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
|
|||||||
public int getGenericVarDeclarationOffset(){
|
public int getGenericVarDeclarationOffset(){
|
||||||
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
||||||
if(this.genericClassParameters != null){
|
if(this.genericClassParameters != null){
|
||||||
return this.genericClassParameters.getOffsetOfLastElement();
|
return this.genericClassParameters.getEndOffset();
|
||||||
}else{
|
}else{
|
||||||
return this.offset;
|
return this.offset;
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
|
|||||||
public int getGenericVarDeclarationOffset(){
|
public int getGenericVarDeclarationOffset(){
|
||||||
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
// Falls Generische Parameterliste vorhanden, hier Wert der Liste zurückgegebn
|
||||||
if(this.genericParameters != null){
|
if(this.genericParameters != null){
|
||||||
return this.genericParameters.getOffsetOfLastElement();
|
return this.genericParameters.getEndOffset();
|
||||||
}else{
|
}else{
|
||||||
return this.offset;
|
return this.offset;
|
||||||
}
|
}
|
||||||
|
@ -16,12 +16,12 @@ public class GenericDeclarationList extends Vector<GenericTypeVar>{
|
|||||||
|
|
||||||
private int offsetOfLastElement;
|
private int offsetOfLastElement;
|
||||||
|
|
||||||
public GenericDeclarationList(Vector<GenericTypeVar> values, int offset) {
|
public GenericDeclarationList(Vector<GenericTypeVar> values, int endOffset) {
|
||||||
this.addAll(values);
|
this.addAll(values);
|
||||||
this.offsetOfLastElement = offset;
|
this.offsetOfLastElement = endOffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getOffsetOfLastElement(){
|
public int getEndOffset(){
|
||||||
return offsetOfLastElement;
|
return offsetOfLastElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
25
src/mycompiler/myparser/BoundedClassIdentifierList.java
Normal file
25
src/mycompiler/myparser/BoundedClassIdentifierList.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
@ -16,7 +16,7 @@ public class GenericVarDeclarationList {
|
|||||||
public int getEndOffset() {
|
public int getEndOffset() {
|
||||||
int ret;
|
int ret;
|
||||||
if(elements.isEmpty())throw new DebugException("Es wurde eine GenericVarDeclarationList ohne Elemente geparst");
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -299,7 +299,7 @@ public Vector<Pair> testPair = new Vector<Pair>();
|
|||||||
%type <SourceFile> typedeclarations
|
%type <SourceFile> typedeclarations
|
||||||
%type <GenericTypeVar> boundedMethodParameter;
|
%type <GenericTypeVar> boundedMethodParameter;
|
||||||
%type <GenericTypeVar> boundedClassParameter;
|
%type <GenericTypeVar> boundedClassParameter;
|
||||||
%type <Vector> boundedclassidentifierlist //Vector<Type>
|
%type <BoundedClassIdentifierList> boundedclassidentifierlist //Vector<Type>
|
||||||
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
|
%type <GenericVarDeclarationList> boundedMethodParameters; // Vector
|
||||||
%type <ParaList> boundedClassParameters; // ParaList
|
%type <ParaList> boundedClassParameters; // ParaList
|
||||||
%type <UsedId> packagedeclaration
|
%type <UsedId> packagedeclaration
|
||||||
@ -1048,7 +1048,7 @@ boundedMethodParameter : IDENTIFIER
|
|||||||
}
|
}
|
||||||
| IDENTIFIER EXTENDS boundedclassidentifierlist
|
| 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.setBounds($3);
|
||||||
$$=gtv;
|
$$=gtv;
|
||||||
}
|
}
|
||||||
@ -1058,12 +1058,13 @@ boundedclassidentifierlist : referencetype
|
|||||||
Vector<Type> vec=new Vector<Type>();
|
Vector<Type> vec=new Vector<Type>();
|
||||||
vec.addElement($1);
|
vec.addElement($1);
|
||||||
containedTypes.addElement($1);
|
containedTypes.addElement($1);
|
||||||
$$=vec;
|
$$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().length());
|
||||||
}
|
}
|
||||||
| boundedclassidentifierlist '&' referencetype
|
| boundedclassidentifierlist '&' referencetype
|
||||||
{
|
{
|
||||||
$1.addElement($3);
|
$1.addElement($3);
|
||||||
containedTypes.addElement($3);
|
$1.addOffsetOff($3);
|
||||||
|
containedTypes.addElement($3);
|
||||||
$$=$1;
|
$$=$1;
|
||||||
}
|
}
|
||||||
// returns Vector<Type>
|
// returns Vector<Type>
|
||||||
|
@ -38,9 +38,11 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
|||||||
// ino.attribute.bounds.26468.declaration
|
// ino.attribute.bounds.26468.declaration
|
||||||
Vector<Type> bounds=new Vector<Type>();
|
Vector<Type> bounds=new Vector<Type>();
|
||||||
// ino.end
|
// ino.end
|
||||||
|
private int endOffset;
|
||||||
|
|
||||||
|
/*
|
||||||
// ino.method.BoundedGenericTypeVar.26471.definition
|
// 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.end
|
||||||
// ino.method.BoundedGenericTypeVar.26471.body
|
// ino.method.BoundedGenericTypeVar.26471.body
|
||||||
{
|
{
|
||||||
@ -48,9 +50,10 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
*/
|
||||||
|
|
||||||
// ino.method.BoundedGenericTypeVar.29409.definition
|
// 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.end
|
||||||
// ino.method.BoundedGenericTypeVar.29409.body
|
// ino.method.BoundedGenericTypeVar.29409.body
|
||||||
{
|
{
|
||||||
@ -60,9 +63,15 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
|||||||
}
|
}
|
||||||
//this.genericTypeVar = new RefType(s,offset);
|
//this.genericTypeVar = new RefType(s,offset);
|
||||||
this.bounds = bounds;
|
this.bounds = bounds;
|
||||||
|
this.endOffset = endOffset;
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getEndOffset(){
|
||||||
|
return this.endOffset;
|
||||||
|
}
|
||||||
|
|
||||||
// ino.method.getBounds.26474.definition
|
// ino.method.getBounds.26474.definition
|
||||||
public Vector<Type> getBounds()
|
public Vector<Type> getBounds()
|
||||||
// ino.end
|
// ino.end
|
||||||
@ -102,7 +111,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
|||||||
// ino.end
|
// ino.end
|
||||||
// ino.method.clone.26483.body
|
// 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
|
// ino.end
|
||||||
|
|
||||||
|
@ -214,6 +214,10 @@ public class GenericTypeVar extends Type
|
|||||||
ConstraintsSet ret = new ConstraintsSet();
|
ConstraintsSet ret = new ConstraintsSet();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getEndOffset() {
|
||||||
|
return this.getOffset() + this.name.length();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// ino.end
|
// ino.end
|
||||||
|
@ -162,6 +162,11 @@ public class GenericTypeInsertPoint extends SourcePatchPoint {
|
|||||||
public int getInsertLength() {
|
public int getInsertLength() {
|
||||||
return this.getTypeInsertString().length();
|
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);
|
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){
|
public String getInsertString(ResultSet rs){
|
||||||
String ret = "";
|
String ret = "";
|
||||||
Iterator<GenericVarDeclarationPatch> it1 = this.genericVarDeclarations.iterator();
|
Iterator<GenericVarDeclarationPatch> it1 = this.genericVarDeclarations.iterator();
|
||||||
@ -207,6 +207,8 @@ class GenericVarPatch {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void add(TypePlaceholder tph) {
|
public void add(TypePlaceholder tph) {
|
||||||
|
GenericVarDeclarationPatch toAdd = new GenericVarDeclarationPatch(tph);
|
||||||
|
if(!this.genericVarDeclarations.contains(toAdd))this.genericVarDeclarations.add(toAdd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,5 +124,10 @@ public class TypeInsertPoint extends SourcePatchPoint {
|
|||||||
private TypeInsertable getTIP() {
|
private TypeInsertable getTIP() {
|
||||||
return this.point;
|
return this.point;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
return "TIP: "+this.type;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import java.util.HashMap;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Vector;
|
import java.util.Vector;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import typinferenz.JavaCodeResult;
|
import typinferenz.JavaCodeResult;
|
||||||
import typinferenz.ResultSet;
|
import typinferenz.ResultSet;
|
||||||
import typinferenz.TypeInsertable;
|
import typinferenz.TypeInsertable;
|
||||||
@ -33,7 +35,9 @@ import mycompiler.mytype.TypePlaceholder;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TypeInsertSet {
|
public class TypeInsertSet {
|
||||||
|
//Logger:
|
||||||
|
protected Logger typinferenzLog = Logger.getLogger("Typeinference");
|
||||||
|
|
||||||
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
|
public Vector<TypeInsertPoint> points = new Vector<TypeInsertPoint>();
|
||||||
private Vector<GenericTypeInsertPoint> genericTypeInsertPoints = new Vector<GenericTypeInsertPoint>();
|
private Vector<GenericTypeInsertPoint> genericTypeInsertPoints = new Vector<GenericTypeInsertPoint>();
|
||||||
private ResultSet resultSet;
|
private ResultSet resultSet;
|
||||||
@ -87,12 +91,13 @@ public class TypeInsertSet {
|
|||||||
if(! tip.getInsertNode().seesType(pair.TA2)){
|
if(! tip.getInsertNode().seesType(pair.TA2)){
|
||||||
for(TypePlaceholder tph : pair.getTypePlaceholder()){
|
for(TypePlaceholder tph : pair.getTypePlaceholder()){
|
||||||
if(! pairsDeclareTPH(pairs, tph)){
|
if(! pairsDeclareTPH(pairs, tph)){
|
||||||
gPatch.addTPH(tph);
|
gPatch.add(tph);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GenericTypeInsertPoint gip = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(), gPatch, resultSet);
|
GenericTypeInsertPoint gip = new GenericTypeInsertPoint(tip.getGenericTypeVarInsertNode(), gPatch, resultSet);
|
||||||
|
typinferenzLog.debug("Erstellter GenericTypeInsertPoint: "+gip);
|
||||||
tpj.add(tip);
|
tpj.add(tip);
|
||||||
tpj.add(gip);
|
tpj.add(gip);
|
||||||
}
|
}
|
||||||
|
5
test/plugindevelopment/TypeInsertTests/LambdaTest14.jav
Normal file
5
test/plugindevelopment/TypeInsertTests/LambdaTest14.jav
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
class Matrix{
|
||||||
|
<T1, B extends T1> op(B m){
|
||||||
|
return (f) -> f.apply(m,this);
|
||||||
|
}
|
||||||
|
}
|
16
test/plugindevelopment/TypeInsertTests/LambdaTest14.java
Normal file
16
test/plugindevelopment/TypeInsertTests/LambdaTest14.java
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user