forked from JavaTX/JavaCompilerCore
PackageCrawler und CompilationEnvironment implementieren
This commit is contained in:
parent
9b960329fc
commit
b8a5795bb3
@ -2,6 +2,8 @@ package de.dhbwstuttgart.core;
|
|||||||
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.parser.JavaTXParser;
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.UnifyTypeFactory;
|
||||||
@ -71,13 +73,9 @@ public class JavaTXCompiler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
public SourceFile parse(File sourceFile) throws IOException, java.lang.ClassNotFoundException {
|
||||||
SourceFile ret = new JavaTXParser(environment).parse(sourceFile);
|
CompilationUnitContext tree = JavaTXParser.parse(sourceFile);
|
||||||
sourceFiles.add(ret);
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(sourceFile));
|
||||||
return ret;
|
SourceFile ret = generator.convert(tree);
|
||||||
}
|
|
||||||
|
|
||||||
public SourceFile parse(String source) throws IOException, java.lang.ClassNotFoundException {
|
|
||||||
SourceFile ret = new JavaTXParser(environment).parse(source);
|
|
||||||
sourceFiles.add(ret);
|
sourceFiles.add(ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
package de.dhbwstuttgart.environment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
@ -17,10 +18,16 @@ import org.reflections.util.ConfigurationBuilder;
|
|||||||
import org.reflections.util.FilterBuilder;
|
import org.reflections.util.FilterBuilder;
|
||||||
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
|
import de.dhbwstuttgart.parser.JavaTXParser;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java8Parser.CompilationUnitContext;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GatherNames;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
|
* Stellt die Java-Environment dar und speichert alle Binarys, Librarys und Sourcefiles im zu kompilierenden Projekt
|
||||||
* Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
* Sie erstellt anhand dieser Informationen die JavaClassNameRegistry
|
||||||
|
*
|
||||||
|
* TODO: Zur Initialisierung der CompilationEnvironment sollten alle SourceFiles mit ANTLR geparst werden und alle Klassen Generics und Typen herausgefunden werden
|
||||||
*/
|
*/
|
||||||
public class CompilationEnvironment {
|
public class CompilationEnvironment {
|
||||||
private final List<URL> librarys;
|
private final List<URL> librarys;
|
||||||
@ -41,4 +48,10 @@ public class CompilationEnvironment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public JavaClassRegistry getRegistry(File forSourceFile) throws ClassNotFoundException, IOException {
|
||||||
|
List<String> allNames = new ArrayList<>();
|
||||||
|
CompilationUnitContext tree = JavaTXParser.parse(forSourceFile);
|
||||||
|
return new JavaClassRegistry(GatherNames.getNames(tree, new PackageCrawler(librarys)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,8 @@ import org.reflections.scanners.SubTypesScanner;
|
|||||||
import org.reflections.util.ConfigurationBuilder;
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
import org.reflections.util.FilterBuilder;
|
import org.reflections.util.FilterBuilder;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hilft beim Durchsuchen von Packages
|
* Hilft beim Durchsuchen von Packages
|
||||||
* Benutzt die Reflections-Library (https://github.com/ronmamo/reflections)
|
* Benutzt die Reflections-Library (https://github.com/ronmamo/reflections)
|
||||||
@ -52,12 +54,11 @@ public class PackageCrawler {
|
|||||||
return classes;
|
return classes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns a list of JavaClassNames.
|
public List<String> getClassNames(String packageName){
|
||||||
public List<JavaClassName> getClassNames(String packageName){
|
List<String> nameList = new ArrayList();
|
||||||
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(new JavaClassName(c.getName()));
|
nameList.add(c.getName());
|
||||||
}
|
}
|
||||||
return nameList;
|
return nameList;
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package de.dhbwstuttgart.parser;
|
package de.dhbwstuttgart.parser;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
import de.dhbwstuttgart.environment.CompilationEnvironment;
|
||||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
import de.dhbwstuttgart.parser.antlr.Java8Lexer;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
import de.dhbwstuttgart.syntaxtree.SourceFile;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||||
@ -15,32 +15,23 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class JavaTXParser {
|
public class JavaTXParser {
|
||||||
CompilationEnvironment environment;
|
public static Java8Parser.CompilationUnitContext parse(File source) throws IOException, java.lang.ClassNotFoundException {
|
||||||
|
InputStream stream = new FileInputStream(source);
|
||||||
public JavaTXParser(CompilationEnvironment env) {
|
|
||||||
environment = env;
|
|
||||||
}
|
|
||||||
|
|
||||||
public SourceFile parse(InputStream source) throws IOException, java.lang.ClassNotFoundException {
|
|
||||||
InputStream stream = source;//new FileInputStream(sourceFile);
|
|
||||||
ANTLRInputStream input = new ANTLRInputStream(stream);
|
ANTLRInputStream input = new ANTLRInputStream(stream);
|
||||||
Java8Lexer lexer = new Java8Lexer(input);
|
Java8Lexer lexer = new Java8Lexer(input);
|
||||||
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
CommonTokenStream tokens = new CommonTokenStream(lexer);
|
||||||
Java8Parser parser = new Java8Parser(tokens);
|
Java8Parser parser = new Java8Parser(tokens);
|
||||||
Java8Parser.CompilationUnitContext tree = parser.compilationUnit();
|
return parser.compilationUnit();
|
||||||
|
/*
|
||||||
JavaClassRegistry reg = new JavaClassRegistry(new ArrayList<>());
|
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source));
|
||||||
reg.addPackage("java.lang");
|
|
||||||
SyntaxTreeGenerator generator = new SyntaxTreeGenerator(reg);
|
|
||||||
return generator.convert(tree);
|
return generator.convert(tree);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceFile parse(File file) throws IOException, java.lang.ClassNotFoundException {
|
/* Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet:
|
||||||
return this.parse(new FileInputStream(file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException {
|
public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException {
|
||||||
return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
|
return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8)));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
public class GenericContext {
|
public class GenericContext {
|
||||||
public final String parentMethod;
|
public final String parentMethod;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.literal.*;
|
import de.dhbwstuttgart.syntaxtree.statement.literal.*;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import java.lang.ClassNotFoundException;
|
import java.lang.ClassNotFoundException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.*;
|
import de.dhbwstuttgart.syntaxtree.statement.*;
|
||||||
@ -37,59 +37,6 @@ public class SyntaxTreeGenerator{
|
|||||||
this.reg = reg;
|
this.reg = reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPackageName(Java8Parser.CompilationUnitContext ctx){
|
|
||||||
if(ctx.packageDeclaration() != null){
|
|
||||||
for(TerminalNode t : ctx.packageDeclaration().Identifier()){
|
|
||||||
this.pkgName = this.pkgName + "." + t.toString();
|
|
||||||
}
|
|
||||||
this.pkgName = this.pkgName.substring(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getNames(Java8Parser.CompilationUnitContext ctx){
|
|
||||||
if(this.pkgName == "") this.setPackageName(ctx);
|
|
||||||
String nameString = "";
|
|
||||||
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
|
||||||
if(typeDecl.interfaceDeclaration() != null){
|
|
||||||
if(typeDecl.interfaceDeclaration().normalInterfaceDeclaration() != null){
|
|
||||||
if(this.pkgName != ""){
|
|
||||||
nameString = this.pkgName + "." + typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
|
||||||
}
|
|
||||||
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
|
||||||
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
|
||||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
|
||||||
//this.reg.add(tp.Identifier().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
this.reg.add(nameString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration() != null){
|
|
||||||
if(this.pkgName != ""){
|
|
||||||
nameString = this.pkgName + "." + typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
|
||||||
}
|
|
||||||
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
|
||||||
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
|
||||||
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
|
||||||
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
|
||||||
this.reg.add(tp.Identifier().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
this.reg.add(nameString);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public JavaClassRegistry getReg(){
|
public JavaClassRegistry getReg(){
|
||||||
return this.reg;
|
return this.reg;
|
||||||
@ -140,8 +87,6 @@ public class SyntaxTreeGenerator{
|
|||||||
|
|
||||||
private JavaClassName convertSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) throws ClassNotFoundException{
|
private JavaClassName convertSingleTypeImportDeclaration(Java8Parser.SingleTypeImportDeclarationContext ctx) throws ClassNotFoundException{
|
||||||
String typeName = convertTypeName(ctx.typeName());
|
String typeName = convertTypeName(ctx.typeName());
|
||||||
Thread.currentThread().getContextClassLoader().loadClass(typeName);
|
|
||||||
reg.add(typeName);
|
|
||||||
JavaClassName ret = reg.getName(typeName);
|
JavaClassName ret = reg.getName(typeName);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -170,7 +115,6 @@ public class SyntaxTreeGenerator{
|
|||||||
|
|
||||||
public SourceFile convert(Java8Parser.CompilationUnitContext ctx) throws ClassNotFoundException{
|
public SourceFile convert(Java8Parser.CompilationUnitContext ctx) throws ClassNotFoundException{
|
||||||
List<ClassOrInterface> classes = new ArrayList<>();
|
List<ClassOrInterface> classes = new ArrayList<>();
|
||||||
this.getNames(ctx);
|
|
||||||
this.setImports(ctx);
|
this.setImports(ctx);
|
||||||
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
for(Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||||
ClassOrInterface newClass;
|
ClassOrInterface newClass;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
package de.dhbwstuttgart.parser.SyntaxTreeGenerator;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
import de.dhbwstuttgart.exceptions.TypeinferenceException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
import de.dhbwstuttgart.syntaxtree.GenericDeclarationList;
|
||||||
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
import de.dhbwstuttgart.syntaxtree.GenericTypeVar;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
91
src/de/dhbwstuttgart/parser/scope/GatherNames.java
Normal file
91
src/de/dhbwstuttgart/parser/scope/GatherNames.java
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
|
||||||
|
import de.dhbwstuttgart.environment.PackageCrawler;
|
||||||
|
import de.dhbwstuttgart.parser.antlr.Java8Parser;
|
||||||
|
|
||||||
|
public class GatherNames {
|
||||||
|
|
||||||
|
private static String getPackageName(Java8Parser.CompilationUnitContext ctx){
|
||||||
|
String pkgName = "";
|
||||||
|
if(ctx.packageDeclaration() != null){
|
||||||
|
for(TerminalNode t : ctx.packageDeclaration().Identifier()){
|
||||||
|
pkgName = pkgName + "." + t.toString();
|
||||||
|
}
|
||||||
|
pkgName = pkgName.substring(1);
|
||||||
|
}
|
||||||
|
return pkgName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<String> getNames(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException{
|
||||||
|
List<String> ret = new ArrayList<>();
|
||||||
|
String pkgName = getPackageName(ctx);
|
||||||
|
String nameString = "";
|
||||||
|
for (Java8Parser.TypeDeclarationContext typeDecl : ctx.typeDeclaration()){
|
||||||
|
if(typeDecl.interfaceDeclaration() != null){
|
||||||
|
if(typeDecl.interfaceDeclaration().normalInterfaceDeclaration() != null){
|
||||||
|
if(pkgName != ""){
|
||||||
|
nameString = pkgName + "." + typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
nameString = typeDecl.interfaceDeclaration().normalInterfaceDeclaration().Identifier().toString();
|
||||||
|
}
|
||||||
|
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||||
|
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||||
|
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||||
|
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||||
|
//this.reg.add(tp.Identifier().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
ret.add(nameString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
if(typeDecl.classDeclaration().normalClassDeclaration() != null){
|
||||||
|
if(pkgName != ""){
|
||||||
|
nameString = pkgName + "." + typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
nameString = typeDecl.classDeclaration().normalClassDeclaration().Identifier().toString();
|
||||||
|
}
|
||||||
|
//Die Generic TypeParameter Definitionen Nicht! an die JavaClassName-Registry anfügen:
|
||||||
|
/* //Diese gelängen dadurch in den globalen Scope, was sie schließlich nicht sind
|
||||||
|
if(typeDecl.classDeclaration().normalClassDeclaration().typeParameters() != null){
|
||||||
|
for(Java8Parser.TypeParameterContext tp : typeDecl.classDeclaration().normalClassDeclaration().typeParameters().typeParameterList().typeParameter()){
|
||||||
|
this.reg.add(tp.Identifier().toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
ret.add(nameString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret.addAll(getImports(ctx, packages));
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static List<String> getImports(Java8Parser.CompilationUnitContext ctx, PackageCrawler packages) throws ClassNotFoundException {
|
||||||
|
List<String> ret = new ArrayList();
|
||||||
|
for(Java8Parser.ImportDeclarationContext importDeclCtx : ctx.importDeclaration()){
|
||||||
|
if(importDeclCtx.singleTypeImportDeclaration() != null){
|
||||||
|
ret.add(importDeclCtx.singleTypeImportDeclaration().typeName().getText());
|
||||||
|
}
|
||||||
|
else if(importDeclCtx.typeImportOnDemandDeclaration() != null){
|
||||||
|
ret.addAll(packages.getClassNames(importDeclCtx.typeImportOnDemandDeclaration().packageOrTypeName().getText()));
|
||||||
|
}
|
||||||
|
else if(importDeclCtx.singleStaticImportDeclaration() != null){
|
||||||
|
ret.add(importDeclCtx.singleStaticImportDeclaration().typeName().getText()+"."+importDeclCtx.singleStaticImportDeclaration().Identifier().getText());
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
ret.addAll(packages.getClassNames(importDeclCtx.staticImportOnDemandDeclaration().typeName().getText()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,6 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||||
//import jdk.nashorn.internal.ir.Node;
|
|
||||||
|
|
||||||
public class GenericTypeName extends JavaClassName {
|
public class GenericTypeName extends JavaClassName {
|
||||||
private final static String DELIMITER = "%";
|
private final static String DELIMITER = "%";
|
@ -1,4 +1,4 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
@ -1,4 +1,4 @@
|
|||||||
package de.dhbwstuttgart.environment;
|
package de.dhbwstuttgart.parser.scope;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
package de.dhbwstuttgart.parser.scope;
|
|
||||||
|
|
||||||
public class sad {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,7 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import de.dhbwstuttgart.core.IItemWithOffset;
|
import de.dhbwstuttgart.core.IItemWithOffset;
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
import de.dhbwstuttgart.syntaxtree.visual.ASTPrinter;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree;
|
package de.dhbwstuttgart.syntaxtree;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
import de.dhbwstuttgart.syntaxtree.type.RefTypeOrTPHOrWildcardOrGeneric;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
@ -2,8 +2,8 @@ package de.dhbwstuttgart.syntaxtree;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
//import sun.security.x509.X509CertInfo;
|
//import sun.security.x509.X509CertInfo;
|
||||||
|
@ -5,11 +5,11 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassRegistry;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
import de.dhbwstuttgart.parser.SyntaxTreeGenerator.GenericContext;
|
||||||
|
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassRegistry;
|
||||||
import de.dhbwstuttgart.syntaxtree.Field;
|
import de.dhbwstuttgart.syntaxtree.Field;
|
||||||
import de.dhbwstuttgart.syntaxtree.Method;
|
import de.dhbwstuttgart.syntaxtree.Method;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
|
@ -3,9 +3,9 @@ package de.dhbwstuttgart.syntaxtree.factory;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
import de.dhbwstuttgart.exceptions.NotImplementedException;
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.*;
|
import de.dhbwstuttgart.syntaxtree.type.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.Void;
|
import de.dhbwstuttgart.syntaxtree.type.Void;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.statement;
|
package de.dhbwstuttgart.syntaxtree.statement;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
import de.dhbwstuttgart.syntaxtree.StatementVisitor;
|
||||||
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
import de.dhbwstuttgart.syntaxtree.type.RefType;
|
||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceBlockInformation;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.type;
|
package de.dhbwstuttgart.syntaxtree.type;
|
||||||
|
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.parser.NullToken;
|
import de.dhbwstuttgart.parser.NullToken;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.type;
|
package de.dhbwstuttgart.syntaxtree.type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.GenericTypeName;
|
import de.dhbwstuttgart.parser.scope.GenericTypeName;
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package de.dhbwstuttgart.syntaxtree.type;
|
package de.dhbwstuttgart.syntaxtree.type;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
import de.dhbwstuttgart.syntaxtree.ASTVisitor;
|
||||||
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
import de.dhbwstuttgart.typeinference.result.ResultSetVisitor;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
@ -2,7 +2,7 @@ package de.dhbwstuttgart.syntaxtree.type;
|
|||||||
|
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
|
|
||||||
|
|
||||||
public class Void extends RefType
|
public class Void extends RefType
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package de.dhbwstuttgart.typeinference.typeAlgo;
|
package de.dhbwstuttgart.typeinference.typeAlgo;
|
||||||
|
|
||||||
import de.dhbwstuttgart.environment.JavaClassName;
|
|
||||||
import de.dhbwstuttgart.exceptions.DebugException;
|
import de.dhbwstuttgart.exceptions.DebugException;
|
||||||
|
import de.dhbwstuttgart.parser.scope.JavaClassName;
|
||||||
import de.dhbwstuttgart.syntaxtree.*;
|
import de.dhbwstuttgart.syntaxtree.*;
|
||||||
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
import de.dhbwstuttgart.syntaxtree.statement.Statement;
|
||||||
|
Loading…
Reference in New Issue
Block a user