diff --git a/src/de/dhbwstuttgart/parser/PackageCrawler.java b/src/de/dhbwstuttgart/parser/PackageCrawler.java index 007b4736..18bcd444 100644 --- a/src/de/dhbwstuttgart/parser/PackageCrawler.java +++ b/src/de/dhbwstuttgart/parser/PackageCrawler.java @@ -1,5 +1,6 @@ package de.dhbwstuttgart.parser; +import de.dhbwstuttgart.typecheck.JavaClassName; import org.reflections.Reflections; import org.reflections.scanners.ResourcesScanner; import org.reflections.scanners.SubTypesScanner; @@ -34,11 +35,12 @@ public class PackageCrawler { return classes; } - public static List getClassNames(String packageName){ - List nameList = new ArrayList(); + // Returns a list of JavaClassNames. + public static List getClassNames(String packageName){ + List nameList = new ArrayList(); Set> classes = getClassesInPackage(packageName); for(Class c : classes){ - nameList.add(c.getName()); + nameList.add(new JavaClassName(c.getName())); } return nameList; } diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java index c5cdbb47..c6fbf871 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.typecheck.*; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.lang.ClassNotFoundException; import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.tree.TerminalNode; @@ -82,6 +83,65 @@ public class SyntaxTreeGenerator{ return this.reg; } + // Converts type name to String. + public String convertTypeName(Java8Parser.TypeNameContext ctx){ + String ret; + if(ctx.packageOrTypeName() == null){ + ret = ctx.Identifier().toString(); + } + else{ + ret = convertPackageOrTypeName(ctx.packageOrTypeName()) + "." + ctx.Identifier().toString(); + } + return ret; + } + + // Converts PackageOrTypeName to String. + public String convertPackageOrTypeName(Java8Parser.PackageOrTypeNameContext ctx){ + String ret; + if(ctx.packageOrTypeName() == null){ + ret = ctx.Identifier().toString(); + } + else{ + ret = convertPackageOrTypeName(ctx.packageOrTypeName()) + "." + ctx.Identifier().toString(); + } + return ret; + } + + public void setImports(Java8Parser.CompilationUnitContext ctx){ + List newImports = new ArrayList(); + for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){ + if(importDeclCtx.singleTypeImportDeclaration() != null){ + newImports.add(convertSingleTypeImportDeclaration(importDeclCtx.singleTypeImportDeclaration())); + } + else if(importDeclCtx.typeImportOnDemandDeclaration() != null){ + newImports.add(convertTypeImportOnDemandDeclaration(importDeclCtx.typeImportOnDemandDeclaration())); + } + else if(importDeclCtx.singleStaticImportDeclaration() != null){ + newImports.add(convertSingleStaticImportDeclaration(importDeclCtx.singleStaticImportDeclaration())); + } + else{ + newImports.add(convertStaticImportOnDemandDeclaration(importDeclCtx.staticImportOnDemandDeclaration())); + } + } + this.imports.addAll(newImports); + } + + private JavaClassName convertSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx){ + return null; + } + + private JavaClassName convertTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx){ + return null; + } + + private JavaClassName convertSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx){ + return null; + } + + private JavaClassName convertStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx){ + return null; + } + public SourceFile convert(Java8Parser.CompilationUnitContext ctx){ List classes = new ArrayList<>(); this.getNames(ctx); diff --git a/src/de/dhbwstuttgart/typecheck/JavaClassName.java b/src/de/dhbwstuttgart/typecheck/JavaClassName.java index f037a5ba..669cd469 100644 --- a/src/de/dhbwstuttgart/typecheck/JavaClassName.java +++ b/src/de/dhbwstuttgart/typecheck/JavaClassName.java @@ -15,7 +15,7 @@ public class JavaClassName { private String name; private PackageName packageName; - JavaClassName(String name){ + public JavaClassName(String name){ if(name == null)throw new NullPointerException(); String[] names = name.split("[.]");