Method Parsen verbessert

This commit is contained in:
JanUlrich 2017-02-17 17:20:50 +01:00
parent fb629b417f
commit 40d87c8636
4 changed files with 71 additions and 10 deletions

View File

@ -12,6 +12,7 @@ import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPH;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder; import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.typecheck.*; import de.dhbwstuttgart.typecheck.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
@ -249,17 +250,24 @@ public class SyntaxTreeGenerator{
private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) { private ParameterList convert(Java8Parser.FormalParameterListContext formalParameterListContext) {
List<FormalParameter> ret = new ArrayList<>(); List<FormalParameter> ret = new ArrayList<>();
if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null && formalParameterListContext.formalParameters().formalParameter() != null){ List<Java8Parser.FormalParameterContext> fps = new ArrayList<>();
for(Java8Parser.FormalParameterContext fp : formalParameterListContext.formalParameters().formalParameter()){ if(formalParameterListContext.lastFormalParameter().formalParameter() == null)throw new NotImplementedException();
String paramName = convert(fp.variableDeclaratorId());
RefTypeOrTPH type; if(formalParameterListContext != null && formalParameterListContext.formalParameters() != null
if(fp.unannType() != null){ && formalParameterListContext.formalParameters().formalParameter() != null){
type = convert(fp.unannType()); fps = new ArrayList<>(formalParameterListContext.formalParameters().formalParameter());
}else{ }
type = TypePlaceholder.fresh(fp.getStart()); fps.add(formalParameterListContext.lastFormalParameter().formalParameter());
}
ret.add(new FormalParameter(paramName, type, fp.getStart())); 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); return new ParameterList(ret);
} }

View 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(); }
}

View 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("}");
}
}
}

View File

@ -28,6 +28,7 @@ public class GeneralParserTest{
filenames.add("FieldInitializationTest.jav"); filenames.add("FieldInitializationTest.jav");
filenames.add("ImportTest.jav"); filenames.add("ImportTest.jav");
filenames.add("StatementsTest.jav"); filenames.add("StatementsTest.jav");
filenames.add("FeatherWeightJava.jav");
filenames.add("ImportTestGeneric.jav"); filenames.add("ImportTestGeneric.jav");
//filenames.add("BoundedParameter.jav"); //filenames.add("BoundedParameter.jav");
//filenames.add("GenericFieldVarTest.jav"); //filenames.add("GenericFieldVarTest.jav");