forked from JavaTX/JavaCompilerCore
Object Type implementieren
This commit is contained in:
parent
40bfc79948
commit
3b258c3880
@ -2,15 +2,16 @@ package de.dhbwstuttgart.parser;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import de.dhbwstuttgart.syntaxtree.type.ObjectType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||
import de.dhbwstuttgart.syntaxtree.type.Type;
|
||||
|
||||
public class BoundedClassIdentifierList extends Vector<Type>{
|
||||
public class BoundedClassIdentifierList extends Vector<ObjectType>{
|
||||
|
||||
private int endOffset;
|
||||
private Vector<Type> list;
|
||||
private Vector<ObjectType> list;
|
||||
|
||||
public BoundedClassIdentifierList(Vector<Type> list, int endOffset){
|
||||
public BoundedClassIdentifierList(Vector<ObjectType> list, int endOffset){
|
||||
this.endOffset = endOffset;
|
||||
this.addAll(list);
|
||||
}
|
||||
|
@ -1561,7 +1561,7 @@ case 110:
|
||||
case 111:
|
||||
// line 990 "./../src/de/dhbwstuttgart/parser/JavaParser.jay"
|
||||
{
|
||||
Vector<Type> vec=new Vector<Type>();
|
||||
Vector<ObjectType> vec=new Vector<ObjectType>();
|
||||
vec.addElement(((RefType)yyVals[0+yyTop]));
|
||||
containedTypes.addElement(((RefType)yyVals[0+yyTop]));
|
||||
yyVal=new BoundedClassIdentifierList(vec, ((RefType)yyVals[0+yyTop]).getOffset()+((RefType)yyVals[0+yyTop]).getName().toString().length());
|
||||
|
@ -988,7 +988,7 @@ boundedMethodParameter : IDENTIFIER
|
||||
// returns Vector<Type>
|
||||
boundedclassidentifierlist : referencetype
|
||||
{
|
||||
Vector<Type> vec=new Vector<Type>();
|
||||
Vector<ObjectType> vec=new Vector<ObjectType>();
|
||||
vec.addElement($1);
|
||||
containedTypes.addElement($1);
|
||||
$$=new BoundedClassIdentifierList(vec, $1.getOffset()+$1.getName().toString().length());
|
||||
|
@ -152,19 +152,24 @@ public class LambdaExpression extends Expr{
|
||||
//ArgumentAssumptions + assumptions ergeben die Assumptions für die Statements innerhalb des Lambda-Bodys:
|
||||
ret.add(method_body.TYPEStmt(ArgumentAssumptions.add(assumptions))); //Es gibt die LambdaExpression nur mit einem Block als Method Body, nicht mit einer einzelnen Expression
|
||||
|
||||
//TODO: OderConstraint erstellen mit normalem Typ und ? extemds/super Type
|
||||
//Die Typen innerhalb von FunN anpassen:
|
||||
Vector<Type> superParamTypes = new Vector<>();
|
||||
for(Type pT : paramTypes){
|
||||
if(pT instanceof ObjectType){
|
||||
superParamTypes.add(new SuperWildcardType(pT.getOffset(), (ObjectType) pT));
|
||||
}else{
|
||||
}else{ //pT ist weder Void noch ein ObjectType (TPH, GTV, RefType)
|
||||
superParamTypes.add(pT);
|
||||
}
|
||||
}
|
||||
Type retType = method_body.getType();
|
||||
Type extRetType = retType;
|
||||
if(!(retType instanceof de.dhbwstuttgart.syntaxtree.type.Void)){
|
||||
extRetType = new ExtendsWildcardType(retType.getOffset(), retType);
|
||||
if(retType instanceof ObjectType){
|
||||
extRetType = new ExtendsWildcardType(retType.getOffset(), (ObjectType) retType);
|
||||
}else{ //retType ist weder Void noch ein ObjectType (TPH, GTV, RefType)
|
||||
extRetType = retType;
|
||||
}
|
||||
}
|
||||
|
||||
ret.add(new SingleConstraint(new FunN(extRetType, superParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
|
||||
|
@ -94,7 +94,7 @@ public class BoundedGenericTypeVar extends GenericTypeVar
|
||||
ConstraintType extendsType = ass.getTypeFor(ev, this);
|
||||
if(extendsType == null)throw new TypeinferenceException("Der Typ "+ev.getName()+" ist nicht korrekt", this);
|
||||
|
||||
??? stimmt der Cast???
|
||||
//TODO: ??? stimmt der Cast???
|
||||
tempBounds.add((ObjectType)extendsType.getType());
|
||||
//ret.add(new SingleConstraint(ass.getTypeFor(this, this), extendsType ));
|
||||
}
|
||||
|
@ -152,7 +152,8 @@ public class ExtendsWildcardType extends WildcardType implements ITypeContainer,
|
||||
|
||||
@Override
|
||||
public ConstraintType TYPE(TypeAssumptions ass, SyntaxTreeNode parent) {
|
||||
this.extendsType = this.extendsType.TYPE(ass, parent).getType();
|
||||
//Folgender TypeCast ist sicher. Wird ein ObjectType in einen ConstraintType umgewandelt und wieder zurück, kann kein Fehler auftreten.
|
||||
this.extendsType = (ObjectType) this.extendsType.TYPE(ass, parent).getType();
|
||||
return super.TYPE(ass, parent);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,3 @@
|
||||
class GenericParaListInsertTest{
|
||||
<A, ABH extends A, C extends ABH, D, E extends D> A methode(a){return a;}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GenericParaListInsertTest2 {
|
||||
private static final String TEST_FILE = "GenericParaListInsertTest2.jav";
|
||||
|
||||
@Test
|
||||
public void run(){
|
||||
Vector<String> mustContain = new Vector<String>();
|
||||
mustContain.add("<"); //Es muss eine Parameterliste generiert werden.
|
||||
MultipleTypesInsertTester.test(this.TEST_FILE, mustContain);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package plugindevelopment.TypeInsertTests;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class GenericTypeVarTest2 {
|
||||
|
||||
private static final String TEST_FILE2 = "GenericTypeVarTest2.jav";
|
||||
|
||||
@Test
|
||||
public void run2(){
|
||||
Vector<String> mustContain = new Vector<String>();
|
||||
mustContain.add("String var2");
|
||||
MultipleTypesInsertTester.test(TEST_FILE2, mustContain);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user