diff --git a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java index 172cdbcf..e51972ab 100644 --- a/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java +++ b/src/de/dhbwstuttgart/parser/SyntaxTreeGenerator/SyntaxTreeGenerator.java @@ -76,13 +76,13 @@ public class SyntaxTreeGenerator{ newImports.add(convertSingleTypeImportDeclaration(importDeclCtx.singleTypeImportDeclaration())); } else if(importDeclCtx.typeImportOnDemandDeclaration() != null){ - newImports.add(convertTypeImportOnDemandDeclaration(importDeclCtx.typeImportOnDemandDeclaration())); + newImports.addAll(convertTypeImportOnDemandDeclaration(importDeclCtx.typeImportOnDemandDeclaration())); } else if(importDeclCtx.singleStaticImportDeclaration() != null){ newImports.add(convertSingleStaticImportDeclaration(importDeclCtx.singleStaticImportDeclaration())); } else{ - newImports.add(convertStaticImportOnDemandDeclaration(importDeclCtx.staticImportOnDemandDeclaration())); + newImports.addAll(convertStaticImportOnDemandDeclaration(importDeclCtx.staticImportOnDemandDeclaration())); } } this.imports.addAll(newImports); @@ -94,16 +94,16 @@ public class SyntaxTreeGenerator{ return ret; } - private JavaClassName convertTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx){ - return null; + private List convertTypeImportOnDemandDeclaration(Java8Parser.TypeImportOnDemandDeclarationContext ctx){ + return reg.getAllFromPackage(ctx.packageOrTypeName().getText()); } private JavaClassName convertSingleStaticImportDeclaration(Java8Parser.SingleStaticImportDeclarationContext ctx){ - return null; + throw new NotImplementedException(); } - private JavaClassName convertStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx){ - return null; + private List convertStaticImportOnDemandDeclaration(Java8Parser.StaticImportOnDemandDeclarationContext ctx){ + return reg.getAllFromPackage(ctx.typeName().getText()); } private String getPackageFromClass(String cls){ diff --git a/src/de/dhbwstuttgart/parser/scope/JavaClassName.java b/src/de/dhbwstuttgart/parser/scope/JavaClassName.java index 8ea1c51c..6481f057 100644 --- a/src/de/dhbwstuttgart/parser/scope/JavaClassName.java +++ b/src/de/dhbwstuttgart/parser/scope/JavaClassName.java @@ -1,5 +1,7 @@ package de.dhbwstuttgart.parser.scope; +import com.sun.xml.internal.bind.v2.runtime.reflect.Lister; + import java.util.ArrayList; import java.util.List; @@ -35,7 +37,7 @@ public class JavaClassName { } /** - * Gibt von einem Klassennamen nur den Namen der Klasse zurück + * Gibt von einem Klassennamen nur den Namen der Klasse zur�ck * Beispiel: * java.lang.Object wird zu: Object */ diff --git a/src/de/dhbwstuttgart/parser/scope/JavaClassRegistry.java b/src/de/dhbwstuttgart/parser/scope/JavaClassRegistry.java index d2f8bc35..a0cfacbf 100644 --- a/src/de/dhbwstuttgart/parser/scope/JavaClassRegistry.java +++ b/src/de/dhbwstuttgart/parser/scope/JavaClassRegistry.java @@ -1,13 +1,14 @@ package de.dhbwstuttgart.parser.scope; +import de.dhbwstuttgart.exceptions.NotImplementedException; + import java.util.*; /** - * Speichert die Klassen für einen bestimmten Projektscope + * Speichert die Klassen f�r einen bestimmten Projektscope */ public class JavaClassRegistry { final List existingClasses = new ArrayList<>(); - final List importedPackages = new ArrayList<>(); public JavaClassRegistry(List initialNames){ for(String name : initialNames){ @@ -23,13 +24,7 @@ public class JavaClassRegistry { for(JavaClassName name : existingClasses){ if(name.equals(new JavaClassName(className)))return name; } - //Jetzt noch alle importierten Packages durchsuchen: - JavaClassName ret = getClassFromImportedPackages(className); - if(ret == null){ - throw new TypeNotPresentException(className, new Throwable()); - }else{ - return ret; - } + throw new NotImplementedException(); } @Override @@ -37,35 +32,18 @@ public class JavaClassRegistry { return existingClasses.toString(); } + public List getAllFromPackage(String packageName) { + List ret = new ArrayList<>(); + for(JavaClassName className : this.existingClasses){ + JavaClassName toCompare = new JavaClassName(packageName + "." + JavaClassName.stripClassName(className.toString())); + if(toCompare.toString().equals(className.toString())){ + ret.add(className); + } + } + return ret; + } + public boolean contains(String whole) { - boolean ret = existingClasses.contains(new JavaClassName(whole)); - if(ret == false){ - JavaClassName imported = getClassFromImportedPackages(whole); - if(imported != null){ - existingClasses.add(imported); - return true; - }else { - return false; - } - }else { - return true; - } + return existingClasses.contains(new JavaClassName(whole)); } - - private JavaClassName getClassFromImportedPackages(String className){ - ClassLoader loader = Thread.currentThread().getContextClassLoader(); - String shortName = JavaClassName.stripClassName(className); - for(String packageName : importedPackages) { - try { - loader.loadClass(packageName+"."+shortName); - //Keine Exception! Die Klasse existiert: - JavaClassName ret = new JavaClassName(packageName+"."+shortName); - if(ret.equals(new JavaClassName(className)))return ret; - } catch (ClassNotFoundException e) { - //Die Klasse wurde nicht gefunden! - } - } - return null; - } - }