package de.dhbwstuttgart.parser.scope; import de.dhbwstuttgart.exceptions.NotImplementedException; import java.util.*; /** * Speichert die Klassen f�r einen bestimmten Projektscope */ public class JavaClassRegistry { final Map existingClasses = new HashMap<>(); public JavaClassRegistry(Map initialNames) { addNames(initialNames); } public JavaClassRegistry() {} public void addNames(Map names) { for (String name : names.keySet()) { existingClasses.put(new JavaClassName(name), names.get(name)); } } public void addName(String className, int numberOfGenerics) { existingClasses.put(new JavaClassName(className), numberOfGenerics); } public JavaClassName getName(String className) { for (JavaClassName name : existingClasses.keySet()) { if (name.equals(new JavaClassName(className))) return name; } throw new NotImplementedException(); } @Override public String toString() { return existingClasses.toString(); } public List getAllFromPackage(String packageName) { List ret = new ArrayList<>(); for (JavaClassName className : this.existingClasses.keySet()) { 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) { return existingClasses.containsKey(new JavaClassName(whole)); } public int getNumberOfGenerics(String name) { return existingClasses.get(new JavaClassName(name)); } }