JavaCompilerCore/test/parser/FeatherWeightJavaTest.java

41 lines
1.4 KiB
Java
Raw Permalink Normal View History

2017-02-17 16:20:50 +00:00
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 org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.Modifier;
2017-02-17 16:20:50 +00:00
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();
2017-03-02 17:16:14 +00:00
SourceFile f = parser.parse(new File(rootDirectory + "Methods.jav"));
2017-02-17 16:20:50 +00:00
String pkgName = f.getPkgName();
System.out.println("package: " + pkgName);
System.out.println("classes:");
2017-03-15 15:17:07 +00:00
for(ClassOrInterface c : f.getClasses()){
int mod = c.getModifiers();
System.out.println(Modifier.toString(mod));
2017-02-17 16:20:50 +00:00
System.out.println(c.getClassName().toString());
System.out.println("{");
for(Field field : c.getFieldDecl()){
System.out.println(field.getName());
if(field instanceof Method){
2017-03-15 15:17:07 +00:00
System.out.println(((Method) field).getParameterList().getFormalparalist().toString());
2017-02-17 16:20:50 +00:00
}
}
System.out.println("}");
}
}
}