Fixed parser bug that caused TestComplete to fail

This commit is contained in:
luca9913 2023-06-06 19:43:56 +02:00
parent 03b7f12541
commit 7556b9f590

View File

@ -39,10 +39,10 @@ public class StatementGenerator {
if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null) if (formalParameterListContext == null || formalParameterListContext.lastFormalParameter() == null)
return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer return new ParameterList(ret, new NullToken()); // Dann ist die Parameterliste leer
if(formalParameterListContext.lastFormalParameter().formalParameter() == null)throw new NotImplementedException(); if (formalParameterListContext.lastFormalParameter().formalParameter() == null)
throw new NotImplementedException();
if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null if (formalParameterListContext != null && formalParameterListContext.formalParameters() != null && formalParameterListContext.formalParameters().formalParameter() != null) {
&& formalParameterListContext.formalParameters().formalParameter() != null){
fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter()); fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter());
} }
fps.add(formalParameterListContext.lastFormalParameter().formalParameter()); fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
@ -78,7 +78,8 @@ public class StatementGenerator {
return convert(stmt.ifThenStatement()); return convert(stmt.ifThenStatement());
} else if (stmt.labeledStatement() != null) { } else if (stmt.labeledStatement() != null) {
return convert(stmt.labeledStatement()); return convert(stmt.labeledStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java8Parser.StatementNoShortIfContext stmt) { private Statement convert(Java8Parser.StatementNoShortIfContext stmt) {
@ -92,7 +93,8 @@ public class StatementGenerator {
return convert(stmt.whileStatementNoShortIf()); return convert(stmt.whileStatementNoShortIf());
} else if (stmt.forStatementNoShortIf() != null) { } else if (stmt.forStatementNoShortIf() != null) {
return convert(stmt.forStatementNoShortIf()); return convert(stmt.forStatementNoShortIf());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) { private Statement convert(Java8Parser.StatementWithoutTrailingSubstatementContext stmt) {
@ -120,7 +122,8 @@ public class StatementGenerator {
return convert(stmt.throwStatement()); return convert(stmt.throwStatement());
} else if (stmt.tryStatement() != null) { } else if (stmt.tryStatement() != null) {
return convert(stmt.tryStatement()); return convert(stmt.tryStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) { public Block convert(Java8Parser.BlockContext block, boolean addTrailingReturn) {
@ -130,7 +133,8 @@ public class StatementGenerator {
List<Statement> stmt = convert(statementContext); List<Statement> stmt = convert(statementContext);
statements.addAll(stmt); statements.addAll(stmt);
} }
if(addTrailingReturn)statements = SyntacticSugar.addTrailingReturn(statements); if (addTrailingReturn)
statements = SyntacticSugar.addTrailingReturn(statements);
return new Block(statements, block.getStart()); return new Block(statements, block.getStart());
} }
@ -178,7 +182,8 @@ public class StatementGenerator {
return convert(stmt.methodInvocation()); return convert(stmt.methodInvocation());
} else if (stmt.classInstanceCreationExpression() != null) { } else if (stmt.classInstanceCreationExpression() != null) {
return convert(stmt.classInstanceCreationExpression()); return convert(stmt.classInstanceCreationExpression());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
public Receiver getReceiver(Expression expr) { public Receiver getReceiver(Expression expr) {
@ -207,36 +212,35 @@ public class StatementGenerator {
receiver = new Super(methodInvocationContext.getStart()); receiver = new Super(methodInvocationContext.getStart());
} else if (methodInvocationContext.methodName() != null) { } else if (methodInvocationContext.methodName() != null) {
receiver = new This(methodInvocationContext.getStart()); receiver = new This(methodInvocationContext.getStart());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
ArgumentList argumentList = convert(methodInvocationContext.argumentList()); ArgumentList argumentList = convert(methodInvocationContext.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream().map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())).collect(Collectors.toCollection(ArrayList::new));
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
.collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(methodInvocationContext.getStart())); // ReturnType signature.add(TypePlaceholder.fresh(methodInvocationContext.getStart())); // ReturnType
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), signature, methodInvocationContext.getStart());
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
signature, methodInvocationContext.getStart());
ret.setStatement(); ret.setStatement();
return ret; return ret;
} }
private ArgumentList convert(Java8Parser.ArgumentListContext argumentListContext) { private ArgumentList convert(Java8Parser.ArgumentListContext argumentListContext) {
if(argumentListContext == null)return new ArgumentList(new ArrayList<>(), new NullToken()); if (argumentListContext == null)
return new ArgumentList(new ArrayList<>(), new NullToken());
List<Expression> args = new ArrayList<>(); List<Expression> args = new ArrayList<>();
Token offset = new NullToken(); Token offset = new NullToken();
for (Java8Parser.ExpressionContext expr : argumentListContext.expression()) { for (Java8Parser.ExpressionContext expr : argumentListContext.expression()) {
args.add(convert(expr)); args.add(convert(expr));
} }
if(args.size()>0)offset = args.get(0).getOffset(); if (args.size() > 0)
offset = args.get(0).getOffset();
return new ArgumentList(args, offset); return new ArgumentList(args, offset);
} }
/** /**
* Der Parser kann nicht zwischen einer lokalen Variable, einem Feldzugriff und * Der Parser kann nicht zwischen einer lokalen Variable, einem Feldzugriff und einer Klassenangabe unterscheiden.
* einer Klassenangabe unterscheiden. *
* @param expression * @param expression
* @param offset * @param offset
* @return * @return
@ -255,7 +259,8 @@ public class StatementGenerator {
// kann eigentlich nicht vorkommen // kann eigentlich nicht vorkommen
// Dann Muss es ein Feld sein! // Dann Muss es ein Feld sein!
return new FieldVar(new This(offset), expression, TypePlaceholder.fresh(offset), offset); return new FieldVar(new This(offset), expression, TypePlaceholder.fresh(offset), offset);
}} }
}
} }
return generateFieldVarOrClassname(expression, offset); return generateFieldVarOrClassname(expression, offset);
} }
@ -288,24 +293,23 @@ public class StatementGenerator {
return generateLocalOrFieldVarOrClassName(expressionNameContext.getText(), expressionNameContext.getStart()); return generateLocalOrFieldVarOrClassName(expressionNameContext.getText(), expressionNameContext.getStart());
} }
private Statement convert(Java8Parser.ClassInstanceCreationExpressionContext newExpression) { private Statement convert(Java8Parser.ClassInstanceCreationExpressionContext newExpression) {
Java8Parser.TypeArgumentsContext genericArgs = null; Java8Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException(); if (newExpression.expressionName() != null)
throw new NotImplementedException();
if (newExpression.typeArgumentsOrDiamond() != null) { if (newExpression.typeArgumentsOrDiamond() != null) {
if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) { if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) {
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments(); genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
} }
} }
if(newExpression.typeArguments()!= null)throw new NotImplementedException(); if (newExpression.typeArguments() != null)
throw new NotImplementedException();
TerminalNode identifier = newExpression.Identifier(0); TerminalNode identifier = newExpression.Identifier(0);
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs, identifier.getSymbol(), reg, generics); RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs, identifier.getSymbol(), reg, generics);
ArgumentList args = convert(newExpression.argumentList()); ArgumentList args = convert(newExpression.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = args.getArguments().stream().map(x -> TypePlaceholder.fresh(newExpression.getStart())).collect(Collectors.toCollection(ArrayList::new));
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
.collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(newExpression.getStart())); // ReturnType signature.add(TypePlaceholder.fresh(newExpression.getStart())); // ReturnType
Statement ret = new NewClass(newClass, args, null, signature, newExpression.getStart()); Statement ret = new NewClass(newClass, args, null, signature, newExpression.getStart());
ret.setStatement(); ret.setStatement();
@ -321,22 +325,19 @@ public class StatementGenerator {
} }
private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PreDecrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.PREDECREMENT, convert(stmt.unaryExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement(); ret.setStatement();
return ret; return ret;
} }
private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) { private Statement convert(Java8Parser.PostIncrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTINCREMENT, convert(stmt.postfixExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement(); ret.setStatement();
return ret; return ret;
} }
private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) { private Statement convert(Java8Parser.PostDecrementExpressionContext stmt) {
Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), Statement ret = new UnaryExpr(UnaryExpr.Operation.POSTDECREMENT, convert(stmt.postfixExpression()), TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
TypePlaceholder.fresh(stmt.getStart()), stmt.getStart());
ret.setStatement(); ret.setStatement();
return ret; return ret;
} }
@ -350,9 +351,12 @@ public class StatementGenerator {
private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) { private AssignLeftSide convert(Java8Parser.LeftHandSideContext leftHandSide) {
Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart()); Expression leftSide = generateLocalOrFieldVarOrClassName(leftHandSide.getText(), leftHandSide.getStart());
if(leftSide instanceof FieldVar)return new AssignToField((FieldVar) leftSide); if (leftSide instanceof FieldVar)
else if (leftSide instanceof LocalVar)return new AssignToLocal((LocalVar) leftSide); return new AssignToField((FieldVar) leftSide);
else throw new NotImplementedException(); else if (leftSide instanceof LocalVar)
return new AssignToLocal((LocalVar) leftSide);
else
throw new NotImplementedException();
} }
private Statement convert(Java8Parser.IfThenStatementContext stmt) { private Statement convert(Java8Parser.IfThenStatementContext stmt) {
@ -414,7 +418,8 @@ public class StatementGenerator {
return convert(stmt.basicForStatement()); return convert(stmt.basicForStatement());
} else if (stmt.enhancedForStatement() != null) { } else if (stmt.enhancedForStatement() != null) {
return convert(stmt.enhancedForStatement()); return convert(stmt.enhancedForStatement());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java8Parser.ForStatementNoShortIfContext stmt) { private Statement convert(Java8Parser.ForStatementNoShortIfContext stmt) {
@ -422,7 +427,8 @@ public class StatementGenerator {
return convert(stmt.basicForStatementNoShortIf()); return convert(stmt.basicForStatementNoShortIf());
} else if (stmt.enhancedForStatementNoShortIf() != null) { } else if (stmt.enhancedForStatementNoShortIf() != null) {
return convert(stmt.enhancedForStatementNoShortIf()); return convert(stmt.enhancedForStatementNoShortIf());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private Statement convert(Java8Parser.BasicForStatementContext stmt) { private Statement convert(Java8Parser.BasicForStatementContext stmt) {
@ -440,7 +446,8 @@ public class StatementGenerator {
return Arrays.asList(convert(stmt.statementExpressionList())); return Arrays.asList(convert(stmt.statementExpressionList()));
} else if (stmt.localVariableDeclaration() != null) { } else if (stmt.localVariableDeclaration() != null) {
return convert(stmt.localVariableDeclaration()); return convert(stmt.localVariableDeclaration());
}else throw new NotImplementedException(); } else
throw new NotImplementedException();
} }
private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) { private List<Statement> convert(Java8Parser.LocalVariableDeclarationContext declaration) {
@ -473,8 +480,7 @@ public class StatementGenerator {
} else { } else {
initValue = convert(varDecl.variableInitializer().expression()); initValue = convert(varDecl.variableInitializer().expression());
} }
ret.add(new Assign(new AssignToLocal(new LocalVar(name.getText(), type, name.getSymbol())) ret.add(new Assign(new AssignToLocal(new LocalVar(name.getText(), type, name.getSymbol())), initValue, name.getSymbol()));
, initValue, name.getSymbol()));
} }
} }
return ret; return ret;
@ -488,10 +494,7 @@ public class StatementGenerator {
} else { } else {
initValue = convert(varDecl.variableInitializer().expression()); initValue = convert(varDecl.variableInitializer().expression());
} }
return (new Assign(new AssignToField( return (new Assign(new AssignToField(new FieldVar(new This(varDecl.getStart()), name.getText(), type, varDecl.getStart())), initValue, name.getSymbol()));
new FieldVar(new This(varDecl.getStart()), name.getText(),
type, varDecl.getStart())),
initValue, name.getSymbol()));
} }
private Statement convert(Java8Parser.ForUpdateContext stmt) { private Statement convert(Java8Parser.ForUpdateContext stmt) {
@ -640,9 +643,7 @@ public class StatementGenerator {
return convert(expression.shiftExpression()); return convert(expression.shiftExpression());
} else { } else {
String operator = expression.getChild(1).getText(); String operator = expression.getChild(1).getText();
return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()), return new BinaryExpr(convertBinaryOperator(operator), TypePlaceholder.fresh(expression.getStart()), convert(expression.relationalExpression()), convert(expression.shiftExpression()), expression.getStart());
convert(expression.relationalExpression()),
convert(expression.shiftExpression()), expression.getStart());
} }
// }else throw new NotImplementedException(); // }else throw new NotImplementedException();
} }
@ -720,11 +721,9 @@ public class StatementGenerator {
} else if (expression.unaryExpressionNotPlusMinus() != null) { } else if (expression.unaryExpressionNotPlusMinus() != null) {
return convert(expression.unaryExpressionNotPlusMinus()); return convert(expression.unaryExpressionNotPlusMinus());
} else if (expression.getText().startsWith("+")) { } else if (expression.getText().startsWith("+")) {
return new UnaryExpr(UnaryExpr.Operation.PLUS, convert(expression.unaryExpression()), return new UnaryExpr(UnaryExpr.Operation.PLUS, convert(expression.unaryExpression()), TypePlaceholder.fresh(expression.getStart()), expression.getStart());
TypePlaceholder.fresh(expression.getStart()), expression.getStart());
} else if (expression.getText().startsWith("-")) { } else if (expression.getText().startsWith("-")) {
return new UnaryExpr(UnaryExpr.Operation.MINUS, convert(expression.unaryExpression()), return new UnaryExpr(UnaryExpr.Operation.MINUS, convert(expression.unaryExpression()), TypePlaceholder.fresh(expression.getStart()), expression.getStart());
TypePlaceholder.fresh(expression.getStart()), expression.getStart());
} else { } else {
// Diese Exceptions sollte nie geworfen werden. // Diese Exceptions sollte nie geworfen werden.
// Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben. // Der Code wurde nur noch nicht getestet. Sollte zur Sicherheit drin bleiben.
@ -761,8 +760,7 @@ public class StatementGenerator {
} else { } else {
expr = convert(expression.expressionName()); expr = convert(expression.expressionName());
} }
if(expression.postDecrementExpression_lf_postfixExpression() == null && if (expression.postDecrementExpression_lf_postfixExpression() == null && expression.postIncrementExpression_lf_postfixExpression() == null) {
expression.postIncrementExpression_lf_postfixExpression() == null){
return expr; return expr;
} }
@ -805,12 +803,9 @@ public class StatementGenerator {
} else { } else {
Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary(); Java8Parser.MethodInvocation_lf_primaryContext ctxt = e.methodInvocation_lf_primary();
String methodName = ctxt.Identifier().toString(); String methodName = ctxt.Identifier().toString();
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = ctxt.argumentList().expression().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = ctxt.argumentList().expression().stream().map(x -> TypePlaceholder.fresh(e.getStart())).collect(Collectors.toCollection(ArrayList::new));
.map(x -> TypePlaceholder.fresh(e.getStart()))
.collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(e.getStart())); // ReturnType signature.add(TypePlaceholder.fresh(e.getStart())); // ReturnType
return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName, return new MethodCall(TypePlaceholder.fresh(e.getStart()), getReceiver(expr), methodName, convert(ctxt.argumentList()), TypePlaceholder.fresh(e.getStart()), signature, e.getStart());
convert(ctxt.argumentList()), TypePlaceholder.fresh(e.getStart()), signature, e.getStart());
} }
} }
@ -821,7 +816,7 @@ public class StatementGenerator {
private Expression convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) { private Expression convert(Java8Parser.PrimaryNoNewArray_lfno_primaryContext expression) {
if (expression.literal() != null) { if (expression.literal() != null) {
return convert(expression.literal()); return convert(expression.literal());
}else if(expression.parExpression().expression()!=null){ } else if (expression.parExpression() != null) {
return convert(expression.parExpression().expression()); return convert(expression.parExpression().expression());
} else if (expression.methodInvocation_lfno_primary() != null) { } else if (expression.methodInvocation_lfno_primary() != null) {
return convert(expression.methodInvocation_lfno_primary()); return convert(expression.methodInvocation_lfno_primary());
@ -852,21 +847,21 @@ public class StatementGenerator {
private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) { private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
Java8Parser.TypeArgumentsContext genericArgs = null; Java8Parser.TypeArgumentsContext genericArgs = null;
if(newExpression.expressionName()!= null)throw new NotImplementedException(); if (newExpression.expressionName() != null)
throw new NotImplementedException();
if (newExpression.typeArgumentsOrDiamond() != null) { if (newExpression.typeArgumentsOrDiamond() != null) {
if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) { if (newExpression.typeArgumentsOrDiamond().typeArguments() != null) {
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments(); genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
} }
} }
if(newExpression.typeArguments()!= null)throw new NotImplementedException(); if (newExpression.typeArguments() != null)
throw new NotImplementedException();
TerminalNode identifier = newExpression.Identifier(0); TerminalNode identifier = newExpression.Identifier(0);
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs, identifier.getSymbol(), reg, generics); RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(), genericArgs, identifier.getSymbol(), reg, generics);
ArgumentList args = convert(newExpression.argumentList()); ArgumentList args = convert(newExpression.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = args.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = args.getArguments().stream().map(x -> TypePlaceholder.fresh(newExpression.getStart())).collect(Collectors.toCollection(ArrayList::new));
.map(x -> TypePlaceholder.fresh(newExpression.getStart()))
.collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(newExpression.getStart())); // ReturnType signature.add(TypePlaceholder.fresh(newExpression.getStart())); // ReturnType
return new NewClass(newClass, args, null, signature, newExpression.getStart()); return new NewClass(newClass, args, null, signature, newExpression.getStart());
} }
@ -874,32 +869,24 @@ public class StatementGenerator {
private Expression convert(Java8Parser.LiteralContext literal) { private Expression convert(Java8Parser.LiteralContext literal) {
if (literal.IntegerLiteral() != null) { if (literal.IntegerLiteral() != null) {
Number value = Integer.parseInt(literal.IntegerLiteral().getText()); Number value = Integer.parseInt(literal.IntegerLiteral().getText());
return new Literal(TypePlaceholder.fresh(literal.getStart()), return new Literal(TypePlaceholder.fresh(literal.getStart()), value, literal.getStart());
value, literal.getStart());
} else if (literal.FloatingPointLiteral() != null) { } else if (literal.FloatingPointLiteral() != null) {
Number value = Double.parseDouble(literal.FloatingPointLiteral().getText()); Number value = Double.parseDouble(literal.FloatingPointLiteral().getText());
return new Literal(TypePlaceholder.fresh(literal.getStart()), return new Literal(TypePlaceholder.fresh(literal.getStart()), value, literal.getStart());
value, literal.getStart());
} else if (literal.BooleanLiteral() != null) { } else if (literal.BooleanLiteral() != null) {
RefType type = new RefType(reg.getName("java.lang.Boolean"), literal.getStart()); RefType type = new RefType(reg.getName("java.lang.Boolean"), literal.getStart());
return new Literal(type, return new Literal(type, Boolean.parseBoolean(literal.BooleanLiteral().getText()), literal.getStart());
Boolean.parseBoolean(literal.BooleanLiteral().getText()),
literal.getStart());
} else if (literal.CharacterLiteral() != null) { } else if (literal.CharacterLiteral() != null) {
RefType type = new RefType(reg.getName("java.lang.Character"), literal.getStart()); RefType type = new RefType(reg.getName("java.lang.Character"), literal.getStart());
return new Literal(type, return new Literal(type,
// das gibt immer ' zurück, der Char befindet sich in Position 1 // das gibt immer ' zurück, der Char befindet sich in Position 1
// literal.CharacterLiteral().getText().charAt(0), // literal.CharacterLiteral().getText().charAt(0),
literal.CharacterLiteral().getText().charAt(1), literal.CharacterLiteral().getText().charAt(1), literal.getStart());
literal.getStart());
} else if (literal.StringLiteral() != null) { } else if (literal.StringLiteral() != null) {
RefType type = new RefType(reg.getName("java.lang.String"), literal.getStart()); RefType type = new RefType(reg.getName("java.lang.String"), literal.getStart());
return new Literal(type, return new Literal(type, literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length() - 1), literal.getStart());
literal.StringLiteral().getText().substring(1, literal.StringLiteral().getText().length()-1),
literal.getStart());
} else if (literal.NullLiteral() != null) { } else if (literal.NullLiteral() != null) {
return new Literal(TypePlaceholder.fresh(literal.getStart()), null, return new Literal(TypePlaceholder.fresh(literal.getStart()), null, literal.getStart());
literal.getStart());
} else { } else {
throw new NotImplementedException(); throw new NotImplementedException();
} }
@ -926,13 +913,9 @@ public class StatementGenerator {
} }
ArgumentList argumentList = convert(methodInvocationContext.argumentList()); ArgumentList argumentList = convert(methodInvocationContext.argumentList());
ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream() ArrayList<RefTypeOrTPHOrWildcardOrGeneric> signature = argumentList.getArguments().stream().map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart())).collect(Collectors.toCollection(ArrayList::new));
.map(x -> TypePlaceholder.fresh(methodInvocationContext.getStart()))
.collect(Collectors.toCollection(ArrayList::new));
signature.add(TypePlaceholder.fresh(methodInvocationContext.getStart())); // ReturnType signature.add(TypePlaceholder.fresh(methodInvocationContext.getStart())); // ReturnType
MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), MethodCall ret = new MethodCall(TypePlaceholder.fresh(methodInvocationContext.getStart()), getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()), signature, methodInvocationContext.getStart());
getReceiver(receiver), name, argumentList, TypePlaceholder.fresh(methodInvocationContext.getStart()),
signature, methodInvocationContext.getStart());
return ret; return ret;
} }
@ -941,8 +924,7 @@ public class StatementGenerator {
ParameterList params; ParameterList params;
if (lambdaParams.Identifier() != null) { if (lambdaParams.Identifier() != null) {
List<FormalParameter> parameterList = new ArrayList<>(); List<FormalParameter> parameterList = new ArrayList<>();
parameterList.add(new FormalParameter(lambdaParams.Identifier().getText(), parameterList.add(new FormalParameter(lambdaParams.Identifier().getText(), TypePlaceholder.fresh(lambdaParams.getStart()), lambdaParams.getStart()));
TypePlaceholder.fresh(lambdaParams.getStart()), lambdaParams.getStart()));
params = new ParameterList(parameterList, lambdaParams.getStart()); params = new ParameterList(parameterList, lambdaParams.getStart());
} else if (lambdaParams.formalParameterList() != null) { } else if (lambdaParams.formalParameterList() != null) {
params = convert(lambdaParams.formalParameterList()); params = convert(lambdaParams.formalParameterList());
@ -961,8 +943,7 @@ public class StatementGenerator {
Block block; Block block;
if (expression.lambdaBody().expression() != null) { if (expression.lambdaBody().expression() != null) {
List<Statement> statements = new ArrayList<>(); List<Statement> statements = new ArrayList<>();
statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), statements.add(new Return(lambdaGenerator.convert(expression.lambdaBody().expression()), expression.lambdaBody().expression().getStart()));
expression.lambdaBody().expression().getStart()));
block = new Block(statements, expression.lambdaBody().getStart()); block = new Block(statements, expression.lambdaBody().getStart());
} else { } else {
block = lambdaGenerator.convert(expression.lambdaBody().block(), true); block = lambdaGenerator.convert(expression.lambdaBody().block(), true);