Parser um Cast erweitern

This commit is contained in:
JanUlrich 2017-04-06 11:23:25 +02:00
parent de91e49bcc
commit 30099f5e50
4 changed files with 30 additions and 11 deletions

View File

@ -632,7 +632,15 @@ public class StatementGenerator {
}
private Expression convert(Java8Parser.CastExpressionContext expressionContext) {
throw new NotImplementedException();
Expression expr = null;
if(expressionContext.unaryExpression() != null){
throw new NotImplementedException();
}else if(expressionContext.unaryExpressionNotPlusMinus() != null){
expr = convert(expressionContext.unaryExpressionNotPlusMinus());
}else if(expressionContext.lambdaExpression() != null){
expr = convert(expressionContext.lambdaExpression());
}
return new CastExpr(TypeGenerator.convert(expressionContext.referenceType(), reg, generics),expr, expressionContext.getStart());
}
private Expression convert(Java8Parser.PostfixExpressionContext expression) {

View File

@ -24,14 +24,7 @@ public class TypeGenerator {
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannClassOrInterfaceTypeContext unannClassOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
String name = unannClassOrInterfaceTypeContext.getText();
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein:
if(generics.keySet().contains(name)){
return new GenericRefType(new GenericTypeName(generics.get(name),name), unannClassOrInterfaceTypeContext.getStart());
}else{
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",unannClassOrInterfaceTypeContext.getStart());
}
}
return new RefType(reg.getName(name), unannClassOrInterfaceTypeContext.getStart());
return convertTypeName(name,unannClassOrInterfaceTypeContext.getStart(), reg, generics);
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.UnannTypeContext unannTypeContext, JavaClassRegistry reg, GenericsRegistry genericsRegistry) {
@ -79,4 +72,19 @@ public class TypeGenerator {
throw new de.dhbwstuttgart.exceptions.NotImplementedException();
}
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
return convertTypeName(referenceTypeContext.getText(), referenceTypeContext.getStart(), reg, generics);
}
private static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(String name, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
if(!reg.contains(name)){ //Dann könnte es ein Generische Type sein:
if(generics.keySet().contains(name)){
return new GenericRefType(new GenericTypeName(generics.get(name),name), offset);
}else{
throw new TypeinferenceException("Der Typ "+ name + " ist nicht vorhanden",offset);
}
}
return new RefType(reg.getName(name), offset);
}
}

View File

@ -3,14 +3,15 @@ package de.dhbwstuttgart.syntaxtree.statement;
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
import org.antlr.v4.runtime.Token;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
public class CastExpr extends Expression
{
public CastExpr(RefTypeOrTPHOrWildcardOrGeneric castType, Expression expr, int offset)
public CastExpr(RefTypeOrTPHOrWildcardOrGeneric castType, Expression expr, Token offset)
{
super(null, null);
super(castType, offset);
}
public Expression expr;

View File

@ -27,9 +27,11 @@ public class GeneralParserTest{
List<String> filenames = new ArrayList<String>();
filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");
filenames.add("StatementsTest.jav");
filenames.add("Methods.jav");
filenames.add("ImportTestGeneric.jav");
filenames.add("CastTest.jav");
//filenames.add("BoundedParameter.jav");
//filenames.add("GenericFieldVarTest.jav");
filenames.add("FieldVarTest.jav");