Merge branch 'antlr' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into bigRefactoring

This commit is contained in:
JanUlrich 2017-02-22 14:47:53 +01:00
commit fbcb369f1c
3 changed files with 66 additions and 4 deletions

View File

@ -1,5 +1,6 @@
package de.dhbwstuttgart.parser; package de.dhbwstuttgart.parser;
import de.dhbwstuttgart.typecheck.JavaClassName;
import org.reflections.Reflections; import org.reflections.Reflections;
import org.reflections.scanners.ResourcesScanner; import org.reflections.scanners.ResourcesScanner;
import org.reflections.scanners.SubTypesScanner; import org.reflections.scanners.SubTypesScanner;
@ -34,11 +35,12 @@ public class PackageCrawler {
return classes; return classes;
} }
public static List<String> getClassNames(String packageName){ // Returns a list of JavaClassNames.
List<String> nameList = new ArrayList(); public static List<JavaClassName> getClassNames(String packageName){
List<JavaClassName> nameList = new ArrayList();
Set<Class<?>> classes = getClassesInPackage(packageName); Set<Class<?>> classes = getClassesInPackage(packageName);
for(Class c : classes){ for(Class c : classes){
nameList.add(c.getName()); nameList.add(new JavaClassName(c.getName()));
} }
return nameList; return nameList;
} }

View File

@ -14,6 +14,7 @@ import de.dhbwstuttgart.typecheck.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.lang.ClassNotFoundException;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.tree.TerminalNode;
@ -82,6 +83,65 @@ public class SyntaxTreeGenerator{
return this.reg; 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<JavaClassName> 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){ public SourceFile convert(Java8Parser.CompilationUnitContext ctx){
List<ClassOrInterface> classes = new ArrayList<>(); List<ClassOrInterface> classes = new ArrayList<>();
this.getNames(ctx); this.getNames(ctx);

View File

@ -15,7 +15,7 @@ public class JavaClassName {
private String name; private String name;
private PackageName packageName; private PackageName packageName;
JavaClassName(String name){ public JavaClassName(String name){
if(name == null)throw new NullPointerException(); if(name == null)throw new NullPointerException();
String[] names = name.split("[.]"); String[] names = name.split("[.]");