From 3299f329eaa90e7a57611e03c892da07b2c1c013 Mon Sep 17 00:00:00 2001 From: JanUlrich Date: Fri, 17 Feb 2017 16:58:19 +0100 Subject: [PATCH] Method Parameter parsen --- .../parser/SyntaxTreeGenerator.java | 19 ++++++++++++++++--- .../syntaxtree/FormalParameter.java | 3 ++- .../syntaxtree/statement/LambdaParameter.java | 2 +- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index 8339e717..db5cc9fd 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -250,7 +250,16 @@ public class SyntaxTreeGenerator{ private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) { List ret = new ArrayList<>(); if(formalParameterListContext != null){ - + for(Java8Parser.FormalParameterContext fp : formalParameterListContext.formalParameters().formalParameter()){ + String paramName = convert(fp.variableDeclaratorId()); + RefTypeOrTPH type; + if(fp.unannType() != null){ + type = convert(fp.unannType()); + }else{ + type = TypePlaceholder.fresh(fp.getStart()); + } + ret.add(new FormalParameter(paramName, type, fp.getStart())); + } } return new ParameterList(ret); } @@ -268,7 +277,7 @@ public class SyntaxTreeGenerator{ } RefTypeOrTPH fieldType = convert(fieldDeclarationContext.unannType()); for(Java8Parser.VariableDeclaratorContext varCtx : fieldDeclarationContext.variableDeclaratorList().variableDeclarator()){ - String fieldName = varCtx.variableDeclaratorId().getText(); + String fieldName = convert(varCtx.variableDeclaratorId()); if(varCtx.variableInitializer() != null){ initializeField(fieldDeclarationContext); } @@ -278,7 +287,11 @@ public class SyntaxTreeGenerator{ } return ret; } - + + private String convert(Java8Parser.VariableDeclaratorIdContext variableDeclaratorIdContext) { + return variableDeclaratorIdContext.getText(); + } + // Initialize a field by creating implicit constructor. private void initializeField(Java8Parser.FieldDeclarationContext ctx){ //TODO diff --git a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java index 8fc1132a..767bb14e 100755 --- a/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/FormalParameter.java @@ -1,13 +1,14 @@ package de.dhbwstuttgart.syntaxtree; import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH; +import org.antlr.v4.runtime.Token; public class FormalParameter extends SyntaxTreeNode { private RefTypeOrTPH type; private String name; - public FormalParameter(String name, RefTypeOrTPH type, int offset){ + public FormalParameter(String name, RefTypeOrTPH type, Token offset){ this.name = name; this.type = type; } diff --git a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaParameter.java b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaParameter.java index 8607f8af..b2bf4228 100644 --- a/src/de/dhbwstuttgart/syntaxtree/statement/LambdaParameter.java +++ b/src/de/dhbwstuttgart/syntaxtree/statement/LambdaParameter.java @@ -10,7 +10,7 @@ import de.dhbwstuttgart.syntaxtree.FormalParameter; public class LambdaParameter extends FormalParameter { public LambdaParameter(FormalParameter fp) { - super(null,null,0); + super(null,null,null); }