/* * Checks to make sure that all types in a package are defined by files in the same directory. */ private void checkPackageDirectories(Package _package) { Collection<Type> types = _package.getTypes(); Type firstType = null; File path1 = null; /* Gets the directory of the first type and compares all others to it. */ if (types.size() > 1) { for (Type type : types) { if (firstType == null) { firstType = type; path1 = typeTable.get(type).getFile().getParentFile(); } else { File path2 = typeTable.get(type).getFile().getParentFile(); if (!path1.equals(path2)) addWarning( Error.MISMATCHED_PACKAGE, "Type " + firstType + " and " + type + " both belong to package " + _package + " but are defined in different directories"); } } } // Recursively check child packages. for (Package child : _package.getChildren().values()) checkPackageDirectories(child); }
/* * Calls the full <code>collectTypes</code> and might call it a second time * if needed to determine what should be recompiled. */ private Map<Type, Node> collectTypes(List<File> files, boolean hasMain) throws ParseException, ShadowException, TypeCheckException, IOException, ConfigurationException { Set<String> mustRecompile = new HashSet<String>(); Map<String, TreeSet<String>> dependencies = new HashMap<String, TreeSet<String>>(); // Initial type collection collectTypes(files, hasMain, mustRecompile, dependencies); // Files needing recompilation may trigger other files to get recompiled. // Figure out which ones and redo the whole type collection process. if (errorList.size() == 0 && !useSourceFiles && mustRecompile.size() > 0) { // Create a new set, otherwise adding new recompilations can trigger unnecessary ones. Set<String> updatedMustRecompile = new HashSet<String>(mustRecompile); // For all files that do not already need to be recompiled, // check to see if their dependencies do. for (Map.Entry<String, TreeSet<String>> entry : dependencies.entrySet()) if (!updatedMustRecompile.contains(entry.getKey())) for (String dependency : entry.getValue()) if (mustRecompile.contains(dependency)) { updatedMustRecompile.add(entry.getKey()); break; } mustRecompile = updatedMustRecompile; clear(); // Clears out all internal representations and types. // Collect types again with updated recompilation requirements. collectTypes(files, hasMain, mustRecompile, null); } // Check packages for errors. checkPackageDirectories(packageTree); if (errorList.size() > 0) { printErrors(); printWarnings(); throw errorList.get(0); } printWarnings(); // Return a table of all the types and their corresponding nodes. return typeTable; }