GenericVarDeclarationList extends SyntaxTreeNode

This commit is contained in:
JanUlrich 2014-09-16 17:34:04 +02:00
parent 18e7b68927
commit 49917239c1
5 changed files with 76 additions and 5 deletions

View File

@ -12,9 +12,13 @@ import org.junit.Test;
import de.dhbwstuttgart.antlr.Java8Parser.ClassDeclarationContext;
import de.dhbwstuttgart.antlr.Java8Parser.CompilationUnitContext;
import de.dhbwstuttgart.antlr.Java8Parser.TypeDeclarationContext;
import de.dhbwstuttgart.antlr.Java8Parser.TypeParameterContext;
import de.dhbwstuttgart.antlr.Java8Parser.TypeParametersContext;
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
import de.dhbwstuttgart.syntaxtree.SourceFile;
import de.dhbwstuttgart.syntaxtree.SyntaxTreeNode;
import de.dhbwstuttgart.syntaxtree.Class;
import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
public class VisitorTest {
@ -62,7 +66,28 @@ class EvalVisitor extends Java8BaseVisitor<SyntaxTreeNode> {
public Class visitClassDeclaration(ClassDeclarationContext ctx) {
String name = ctx.Identifier().getText();
int offset = ctx.Identifier().getSymbol().getStartIndex();
TypeParametersContext tpctx = ctx.typeParameters();
GenericDeclarationList gtvList = (GenericDeclarationList) visit(tpctx);
return new Class(name, offset);
}
@Override
public GenericDeclarationList visitTypeParameters(TypeParametersContext ctx) {
Vector<GenericTypeVar> list = new Vector<>();
int endOffset = 0;
for(TypeParameterContext tpctx : ctx.typeParameter()){
tpctx.Identifier();
}
GenericDeclarationList ret = new GenericDeclarationList(list, endOffset);
return ret;
}
@Override
public GenericTypeVar visitTypeParameter(TypeParameterContext ctx) {
GenericTypeVar ret = new GenericTypeVar(name, parent, offset);
return ret;
}
}

View File

@ -1184,7 +1184,7 @@ public class Class extends SyntaxTreeNode implements AClassOrInterface, IItemWit
@Override
public Vector<GenericTypeVar> getGenericParameter() {
if(this.genericClassParameters == null)return new Vector<GenericTypeVar>();
return this.genericClassParameters;
return this.genericClassParameters.getVector();
}
@Override

View File

@ -57,7 +57,7 @@ public abstract class Field extends SyntaxTreeNode implements TypeInsertable, Ty
public Vector<GenericTypeVar> getGenericParameter() {
Vector<GenericTypeVar> ret = new Vector<>();
if(this.genericParameters == null)return ret;
ret.addAll(this.genericParameters);
ret.addAll(this.genericParameters.getVector());
return ret;
}

View File

@ -1,5 +1,9 @@
package de.dhbwstuttgart.syntaxtree;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Vector;
import de.dhbwstuttgart.parser.GenericVarDeclarationList;
@ -12,16 +16,57 @@ import de.dhbwstuttgart.syntaxtree.type.GenericTypeVar;
* @author janulrich
*
*/
public class GenericDeclarationList extends Vector<GenericTypeVar>{
public class GenericDeclarationList extends SyntaxTreeNode implements Iterable<GenericTypeVar>{
private int offsetOfLastElement;
private Vector<GenericTypeVar> gtvs = new Vector<>();
public GenericDeclarationList(Vector<GenericTypeVar> values, int endOffset) {
this.addAll(values);
this.offsetOfLastElement = endOffset;
}
private void addAll(Vector<GenericTypeVar> values) {
this.gtvs.addAll(values);
}
public int getEndOffset(){
return offsetOfLastElement;
}
@Override
public int getOffset() {
return getEndOffset();
}
@Override
public int getVariableLength() {
return 0;
}
@Override
public Iterator<GenericTypeVar> iterator() {
return this.gtvs.iterator();
}
@Override
public Vector<SyntaxTreeNode> getChildren() {
Vector<SyntaxTreeNode> ret = new Vector<>();
for(GenericTypeVar gtv : gtvs){
ret.add(gtv);
}
return ret;
}
public int size() {
return gtvs.size();
}
public Vector<GenericTypeVar> getVector() {
return this.gtvs;
}
public void add(GenericTypeVar t) {
this.gtvs.add(t);
}
}

View File

@ -316,7 +316,8 @@ public class TypeAssumptions {
return new ConstraintType(ass.getAssumedType());
}
}
//return null;
//Spezialfälle bei char, int, boolean, ....
//TODO
throw new TypeinferenceException("Der Typ "+t.getName()+" ist nicht korrekt",inNode);
}