forked from JavaTX/JavaCompilerCore
Method Parsen verbessert
This commit is contained in:
parent
fb629b417f
commit
40d87c8636
@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
|
||||
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
|
||||
import de.dhbwstuttgart.typecheck.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.Token;
|
||||
@ -249,17 +250,24 @@ public class SyntaxTreeGenerator{
|
||||
|
||||
private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
|
||||
List<FormalParameter> ret = new ArrayList<>();
|
||||
if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null && formalParameterListContext.formalParameters().formalParameter() != 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()));
|
||||
List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
|
||||
if(formalParameterListContext.lastFormalParameter().formalParameter() == null)throw new NotImplementedException();
|
||||
|
||||
if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null
|
||||
&& formalParameterListContext.formalParameters().formalParameter() != null){
|
||||
fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter());
|
||||
}
|
||||
fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
|
||||
|
||||
for(Java8Parser.FormalParameterContext fp : fps){
|
||||
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);
|
||||
}
|
||||
|
11
test/parser/FeatherWeightJava.jav
Normal file
11
test/parser/FeatherWeightJava.jav
Normal file
@ -0,0 +1,11 @@
|
||||
|
||||
class FeatherWeightJava {
|
||||
mt4(a,b,c) { return a.add(b).sub(c) ; }
|
||||
|
||||
mt1(a) {return a; }
|
||||
|
||||
mt2(a) {return a.f; }
|
||||
|
||||
mt3(a) {return a.add(); }
|
||||
}
|
||||
|
41
test/parser/FeatherWeightJavaTest.java
Normal file
41
test/parser/FeatherWeightJavaTest.java
Normal file
@ -0,0 +1,41 @@
|
||||
package parser;
|
||||
|
||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||
import de.dhbwstuttgart.syntaxtree.Field;
|
||||
import de.dhbwstuttgart.syntaxtree.Method;
|
||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||
import de.dhbwstuttgart.syntaxtree.modifier.Modifier;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public class FeatherWeightJavaTest {
|
||||
private static final String rootDirectory = System.getProperty("user.dir")+"/test/parser/";
|
||||
|
||||
@Test
|
||||
public void test() throws IOException, ClassNotFoundException {
|
||||
|
||||
JavaTXParser parser = new JavaTXParser();
|
||||
SourceFile f = parser.parse(new File(rootDirectory + "FeatherWeightJava.jav"));
|
||||
|
||||
String pkgName = f.getPkgName();
|
||||
System.out.println("package: " + pkgName);
|
||||
System.out.println("classes:");
|
||||
for(ClassOrInterface c : f.KlassenVektor){
|
||||
for(Modifier mod : c.getModifiers().getModifierList()){
|
||||
System.out.println(mod.getClass().getName());
|
||||
}
|
||||
System.out.println(c.getClassName().toString());
|
||||
System.out.println("{");
|
||||
for(Field field : c.getFieldDecl()){
|
||||
System.out.println(field.getName());
|
||||
if(field instanceof Method){
|
||||
System.out.println(((Method) field).parameterlist.formalparameter.toString());
|
||||
}
|
||||
}
|
||||
System.out.println("}");
|
||||
}
|
||||
}
|
||||
}
|
@ -28,6 +28,7 @@ public class GeneralParserTest{
|
||||
filenames.add("FieldInitializationTest.jav");
|
||||
filenames.add("ImportTest.jav");
|
||||
filenames.add("StatementsTest.jav");
|
||||
filenames.add("FeatherWeightJava.jav");
|
||||
filenames.add("ImportTestGeneric.jav");
|
||||
//filenames.add("BoundedParameter.jav");
|
||||
//filenames.add("GenericFieldVarTest.jav");
|
||||
|
Loading…
Reference in New Issue
Block a user