diff --git a/lib/annotations-2.0.1.jar b/lib/annotations-2.0.1.jar new file mode 100644 index 00000000..8a0204fc Binary files /dev/null and b/lib/annotations-2.0.1.jar differ diff --git a/lib/guava-15.0.jar b/lib/guava-15.0.jar new file mode 100644 index 00000000..eb9ef8ad Binary files /dev/null and b/lib/guava-15.0.jar differ diff --git a/lib/javassist-3.19.0-GA.jar b/lib/javassist-3.19.0-GA.jar new file mode 100644 index 00000000..7ac42641 Binary files /dev/null and b/lib/javassist-3.19.0-GA.jar differ diff --git a/lib/reflections-0.9.10-javadoc.jar b/lib/reflections-0.9.10-javadoc.jar new file mode 100644 index 00000000..d0186c09 Binary files /dev/null and b/lib/reflections-0.9.10-javadoc.jar differ diff --git a/lib/reflections-0.9.10-sources.jar b/lib/reflections-0.9.10-sources.jar new file mode 100644 index 00000000..8412a624 Binary files /dev/null and b/lib/reflections-0.9.10-sources.jar differ diff --git a/lib/reflections-0.9.10.jar b/lib/reflections-0.9.10.jar new file mode 100644 index 00000000..c2556418 Binary files /dev/null and b/lib/reflections-0.9.10.jar differ diff --git a/src/de/dhbwstuttgart/core/JavaTXCompiler.java b/src/de/dhbwstuttgart/core/JavaTXCompiler.java index c3f17a51..854357ed 100644 --- a/src/de/dhbwstuttgart/core/JavaTXCompiler.java +++ b/src/de/dhbwstuttgart/core/JavaTXCompiler.java @@ -7,7 +7,7 @@ import java.io.IOException; public class JavaTXCompiler { - public void parse(File sourceFile) throws IOException { + public void parse(File sourceFile) throws IOException, ClassNotFoundException { new JavaTXParser().parse(sourceFile); } diff --git a/src/de/dhbwstuttgart/parser/JavaTXParser.java b/src/de/dhbwstuttgart/parser/JavaTXParser.java index 5931ef6f..f829c3d5 100644 --- a/src/de/dhbwstuttgart/parser/JavaTXParser.java +++ b/src/de/dhbwstuttgart/parser/JavaTXParser.java @@ -14,7 +14,7 @@ import java.util.ArrayList; import java.util.List; public class JavaTXParser { - public SourceFile parse(File sourceFile) throws IOException { + public SourceFile parse(File sourceFile) throws IOException, ClassNotFoundException { InputStream stream = new FileInputStream(sourceFile); ANTLRInputStream input = new ANTLRInputStream(stream); Java8Lexer lexer = new Java8Lexer(input); @@ -27,17 +27,12 @@ public class JavaTXParser { return generator.convert(tree); } - private List generateJavaLangNames(){ + private List generateJavaLangNames() throws IOException, ClassNotFoundException { List ret = new ArrayList<>(); - //TODO: Eigentlich sind es noch viele mehr: - ret.add("java.lang.String"); - ret.add("java.lang.Boolean"); - ret.add("java.lang.Integer"); - ret.add("java.lang.Double"); - ret.add("java.lang.Float"); - ret.add("java.lang.Long"); - ret.add("java.lang.Byte"); + for(Class cl : PackageCrawler.getClassesInPackage("java.lang")){ + ret.add(cl.getName()); + } return ret; } diff --git a/src/de/dhbwstuttgart/parser/PackageCrawler.java b/src/de/dhbwstuttgart/parser/PackageCrawler.java new file mode 100644 index 00000000..bef0d6c7 --- /dev/null +++ b/src/de/dhbwstuttgart/parser/PackageCrawler.java @@ -0,0 +1,35 @@ +package de.dhbwstuttgart.parser; + +import org.reflections.Reflections; +import org.reflections.scanners.ResourcesScanner; +import org.reflections.scanners.SubTypesScanner; +import org.reflections.util.ClasspathHelper; +import org.reflections.util.ConfigurationBuilder; +import org.reflections.util.FilterBuilder; + +import java.util.LinkedList; +import java.util.List; +import java.util.Set; + +/** + * Hilft beim Durchsuchen von Packages + * Benutzt die Reflections-Library (https://github.com/ronmamo/reflections) + * Hilfe dazu: http://stackoverflow.com/a/9571146 + */ +public class PackageCrawler { + + public static Set> getClassesInPackage(String packageName) { + List classLoadersList = new LinkedList(); + classLoadersList.add(ClasspathHelper.contextClassLoader()); + classLoadersList.add(ClasspathHelper.staticClassLoader()); + + Reflections reflections = new Reflections(new ConfigurationBuilder() + .setScanners(new SubTypesScanner(false /* don't exclude Object.class */), new ResourcesScanner()) + .setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))) + .filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix(packageName)))); + + Set> classes = reflections.getSubTypesOf(Object.class); + + return classes; + } +} diff --git a/test/parser/FieldTest.java b/test/parser/FieldTest.java new file mode 100644 index 00000000..a51aa5b1 --- /dev/null +++ b/test/parser/FieldTest.java @@ -0,0 +1,37 @@ +package parser; + +import de.dhbwstuttgart.parser.JavaTXParser; +import de.dhbwstuttgart.syntaxtree.ClassOrInterface; +import de.dhbwstuttgart.syntaxtree.Field; +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 FieldTest { + 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 + "FieldVarTest.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()); + } + System.out.println("}"); + } + } +} diff --git a/test/parser/FieldVarTest.jav b/test/parser/FieldVarTest.jav index aeeecdbf..6e897824 100644 --- a/test/parser/FieldVarTest.jav +++ b/test/parser/FieldVarTest.jav @@ -1,3 +1,5 @@ +package test; + class Test{ Typ a; } \ No newline at end of file diff --git a/test/parser/GeneralParserTest.java b/test/parser/GeneralParserTest.java index 386426b3..4a6aeaf6 100644 --- a/test/parser/GeneralParserTest.java +++ b/test/parser/GeneralParserTest.java @@ -3,22 +3,13 @@ package parser; import static org.junit.Assert.*; import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; -import de.dhbwstuttgart.core.JavaTXCompiler; import de.dhbwstuttgart.parser.JavaTXParser; -import junit.framework.TestCase; import org.junit.Test; -import de.dhbwstuttgart.core.MyCompiler; -import de.dhbwstuttgart.core.MyCompilerAPI; /** * Dieser Test pr�ft nur, ob .java-Dateien fehlerfrei geparst werden. @@ -36,6 +27,7 @@ public class GeneralParserTest{ List filenames = new ArrayList(); filenames.add("FieldInitializationTest.jav"); filenames.add("ImportTest.jav"); + filenames.add("ImportTestGeneric.jav"); //filenames.add("BoundedParameter.jav"); //filenames.add("GenericFieldVarTest.jav"); filenames.add("FieldVarTest.jav"); diff --git a/test/parser/ImportTestGeneric.jav b/test/parser/ImportTestGeneric.jav new file mode 100644 index 00000000..094f4c5e --- /dev/null +++ b/test/parser/ImportTestGeneric.jav @@ -0,0 +1,5 @@ +import java.util.List; + +class ImportTest{ + List test; +} \ No newline at end of file