New Aufruf im Parser anfügen

This commit is contained in:
JanUlrich 2017-04-07 02:33:20 +02:00
parent f920269e51
commit af1f7f28e2
5 changed files with 43 additions and 22 deletions

View File

@ -710,46 +710,48 @@ public class StatementGenerator {
return convert(expression.expression());
}else if(expression.methodInvocation_lfno_primary() != null){
return convert(expression.methodInvocation_lfno_primary());
}else if(expression.classInstanceCreationExpression_lfno_primary() != null) {
return convert(expression.classInstanceCreationExpression_lfno_primary());
}else{
throw new NotImplementedException();
}
}
private Expression convert(Java8Parser.LiteralContext literal) {
/*if(literal.IntegerLiteral() != null){
private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
if(newExpression.expressionName()!= null)throw new NotImplementedException();
RefType type = new RefType(reg.getName("java.lang.Integer"),literal.getStart());
return new IntLiteral(type,
Integer.parseInt(literal.toString()),
literal.getStart());
}else if(literal.FloatingPointLiteral() != null){
RefType type = new RefType(reg.getName("java.lang.Float"),literal.getStart());
return new FloatLiteral(type,
Float.parseFloat(literal.toString()),
literal.getStart());
*/
if(literal.IntegerLiteral() != null){
Number value = Double.parseDouble(literal.toString());
TerminalNode identifier = newExpression.Identifier(0);
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),identifier.getSymbol(),reg,generics);
ArgumentList args = convert(newExpression.argumentList());
return new NewClass(newClass, args, newExpression.getStart());
}
private Expression convert(Java8Parser.LiteralContext literal) {
if(literal.IntegerLiteral() != null || literal.FloatingPointLiteral()!= null){
Number value = Double.parseDouble(literal.IntegerLiteral().getText());
return new NumberLiteral(TypePlaceholder.fresh(literal.getStart()),
value, literal.getStart());
}else if(literal.BooleanLiteral() != null){
RefType type = new RefType(reg.getName("java.lang.Boolean"),literal.getStart());
return new BoolLiteral(type,
Boolean.parseBoolean(literal.toString()),
Boolean.parseBoolean(literal.BooleanLiteral().getText()),
literal.getStart());
}else if(literal.CharacterLiteral() != null){
RefType type = new RefType(reg.getName("java.lang.Character"),literal.getStart());
return new CharLiteral(type,
literal.toString().charAt(0),
literal.CharacterLiteral().getText().charAt(0),
literal.getStart());
}else if(literal.StringLiteral()!=null){
RefType type = new RefType(reg.getName("java.lang.String"),literal.getStart());
return new StringLiteral(type,
literal.toString(),
literal.StringLiteral().getText(),
literal.getStart());
}else {// if(literal.NullLiteral() != null){
}else if(literal.NullLiteral() != null){
return new Null(TypePlaceholder.fresh(literal.getStart()),
literal.getStart());
}else {
throw new NotImplementedException();
}
}

View File

@ -77,7 +77,7 @@ public class TypeGenerator {
return convertTypeName(referenceTypeContext.getText(), referenceTypeContext.getStart(), reg, generics);
}
private static RefTypeOrTPHOrWildcardOrGeneric convertTypeName(String name, Token offset, JavaClassRegistry reg, GenericsRegistry generics){
public 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);
@ -87,4 +87,5 @@ public class TypeGenerator {
}
return new RefType(reg.getName(name), offset);
}
}

View File

@ -2,9 +2,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
import java.util.ArrayList;
import java.util.List;
import de.dhbwstuttgart.syntaxtree.type.RefType;
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;
@ -17,9 +19,19 @@ public class NewClass extends Statement
private ArgumentList arglist;
private boolean isStatement = false;
private List<RefTypeOrTPHOrWildcardOrGeneric> parameterList = new ArrayList<>();
/**
*
* @param newClass Typ der Instanzierten Klasse
* @param args Argumente mit denen der New-Call aufgerufen wurde
* @param start
*/
public NewClass(RefType newClass, ArgumentList args, Token start) {
super(newClass, start);
this.arglist = args;
}
public ArgumentList getArgumentList()
{
return this.arglist;

View File

@ -25,6 +25,7 @@ public class GeneralParserTest{
List<String> filenames = new ArrayList<String>();
filenames.add("NewTest.jav");
filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav");
filenames.add("CastTest.jav");

5
test/parser/NewTest.jav Normal file
View File

@ -0,0 +1,5 @@
class NewTest {
main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new
NewTest(3)); }
}