diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java index 5f244256c..ecb095d12 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/StatementGenerator.java @@ -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) { diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java index fa37c0319..dc0d71af2 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/TypeGenerator.java @@ -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); + } } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java index 6145a8261..145433bd0 100755 --- a/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/CastExpr.java @@ -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; diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index c26640b3f..9cb20ac68 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -27,9 +27,11 @@ public class GeneralParserTest{ List filenames = new ArrayList(); 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");