New Aufruf im Parser anfügen
This commit is contained in:
parent
f920269e51
commit
af1f7f28e2
@ -710,46 +710,48 @@ public class StatementGenerator {
|
|||||||
return convert(expression.expression());
|
return convert(expression.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());
|
||||||
|
}else if(expression.classInstanceCreationExpression_lfno_primary() != null) {
|
||||||
|
return convert(expression.classInstanceCreationExpression_lfno_primary());
|
||||||
}else{
|
}else{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Expression convert(Java8Parser.LiteralContext literal) {
|
private Expression convert(Java8Parser.ClassInstanceCreationExpression_lfno_primaryContext newExpression) {
|
||||||
/*if(literal.IntegerLiteral() != null){
|
if(newExpression.expressionName()!= null)throw new NotImplementedException();
|
||||||
|
|
||||||
RefType type = new RefType(reg.getName("java.lang.Integer"),literal.getStart());
|
TerminalNode identifier = newExpression.Identifier(0);
|
||||||
return new IntLiteral(type,
|
RefType newClass = (RefType) TypeGenerator.convertTypeName(identifier.getText(),identifier.getSymbol(),reg,generics);
|
||||||
Integer.parseInt(literal.toString()),
|
|
||||||
literal.getStart());
|
ArgumentList args = convert(newExpression.argumentList());
|
||||||
}else if(literal.FloatingPointLiteral() != null){
|
return new NewClass(newClass, args, newExpression.getStart());
|
||||||
RefType type = new RefType(reg.getName("java.lang.Float"),literal.getStart());
|
}
|
||||||
return new FloatLiteral(type,
|
|
||||||
Float.parseFloat(literal.toString()),
|
private Expression convert(Java8Parser.LiteralContext literal) {
|
||||||
literal.getStart());
|
if(literal.IntegerLiteral() != null || literal.FloatingPointLiteral()!= null){
|
||||||
*/
|
Number value = Double.parseDouble(literal.IntegerLiteral().getText());
|
||||||
if(literal.IntegerLiteral() != null){
|
|
||||||
Number value = Double.parseDouble(literal.toString());
|
|
||||||
return new NumberLiteral(TypePlaceholder.fresh(literal.getStart()),
|
return new NumberLiteral(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 BoolLiteral(type,
|
return new BoolLiteral(type,
|
||||||
Boolean.parseBoolean(literal.toString()),
|
Boolean.parseBoolean(literal.BooleanLiteral().getText()),
|
||||||
literal.getStart());
|
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 CharLiteral(type,
|
return new CharLiteral(type,
|
||||||
literal.toString().charAt(0),
|
literal.CharacterLiteral().getText().charAt(0),
|
||||||
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 StringLiteral(type,
|
return new StringLiteral(type,
|
||||||
literal.toString(),
|
literal.StringLiteral().getText(),
|
||||||
literal.getStart());
|
literal.getStart());
|
||||||
}else {// if(literal.NullLiteral() != null){
|
}else if(literal.NullLiteral() != null){
|
||||||
return new Null(TypePlaceholder.fresh(literal.getStart()),
|
return new Null(TypePlaceholder.fresh(literal.getStart()),
|
||||||
literal.getStart());
|
literal.getStart());
|
||||||
|
}else {
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public class TypeGenerator {
|
|||||||
return convertTypeName(referenceTypeContext.getText(), referenceTypeContext.getStart(), reg, generics);
|
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(!reg.contains(name)){ //Dann könnte es ein Generische Type sein:
|
||||||
if(generics.keySet().contains(name)){
|
if(generics.keySet().contains(name)){
|
||||||
return new GenericRefType(new GenericTypeName(generics.get(name),name), offset);
|
return new GenericRefType(new GenericTypeName(generics.get(name),name), offset);
|
||||||
@ -87,4 +87,5 @@ public class TypeGenerator {
|
|||||||
}
|
}
|
||||||
return new RefType(reg.getName(name), offset);
|
return new RefType(reg.getName(name), offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,11 @@ package de.dhbwstuttgart.syntaxtree.statement;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
|
import org.antlr.v4.runtime.Token;
|
||||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||||
|
|
||||||
|
|
||||||
@ -17,9 +19,19 @@ public class NewClass extends Statement
|
|||||||
|
|
||||||
private ArgumentList arglist;
|
private ArgumentList arglist;
|
||||||
private boolean isStatement = false;
|
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()
|
public ArgumentList getArgumentList()
|
||||||
{
|
{
|
||||||
return this.arglist;
|
return this.arglist;
|
||||||
|
@ -25,6 +25,7 @@ public class GeneralParserTest{
|
|||||||
|
|
||||||
|
|
||||||
List<String> filenames = new ArrayList<String>();
|
List<String> filenames = new ArrayList<String>();
|
||||||
|
filenames.add("NewTest.jav");
|
||||||
filenames.add("FieldInitializationTest.jav");
|
filenames.add("FieldInitializationTest.jav");
|
||||||
filenames.add("ImportTest.jav");
|
filenames.add("ImportTest.jav");
|
||||||
filenames.add("CastTest.jav");
|
filenames.add("CastTest.jav");
|
||||||
|
5
test/parser/NewTest.jav
Normal file
5
test/parser/NewTest.jav
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
class NewTest {
|
||||||
|
main() { return new NewTest<>().mt(new NewTest(1) , new NewTest(2) , new
|
||||||
|
NewTest(3)); }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user