Represents the entire contents of a compilation step which consists of one
or more
| Method from org.codehaus.groovy.ast.CompileUnit Detail: |
public void addClass(ClassNode node) {
node = node.redirect();
String name = node.getName();
ClassNode stored = (ClassNode) classes.get(name);
if (stored != null && stored != node) {
// we have a duplicate class!
// One possibility for this is, that we delcared a script and a
// class in the same file and named the class like the file
SourceUnit nodeSource = node.getModule().getContext();
SourceUnit storedSource = stored.getModule().getContext();
String txt = "Invalid duplicate class definition of class "+node.getName()+" : ";
if (nodeSource==storedSource) {
// same class in same source
txt += "The source "+nodeSource.getName()+" contains at least two defintions of the class "+node.getName()+".\n";
if (node.isScriptBody() || stored.isScriptBody()) {
txt += "One of the classes is a explicit generated class using the class statement, the other is a class generated from"+
" the script body based on the file name. Solutions are to change the file name or to change the class name.\n";
}
} else {
txt += "The sources "+nodeSource.getName()+" and "+storedSource.getName()+" are containing both a class of the name "+node.getName()+".\n";
}
nodeSource.getErrorCollector().addErrorAndContinue(
new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber()), nodeSource)
);
}
classes.put(name, node);
if (classesToCompile.containsKey(name)) {
ClassNode cn = (ClassNode) classesToCompile.get(name);
cn.setRedirect(node);
classesToCompile.remove(name);
}
}
Adds a class to the unit. |
public void addClassNodeToCompile(ClassNode node,
SourceUnit location) {
classesToCompile.put(node.getName(),node);
classNameToSource.put(node.getName(),location);
}
this emthod actually does not compile a class. It's only
a marker that this type has to be compiled by the CompilationUnit
at the end of a parse step no node should be be left. |
void addClasses(List classList) {
for (Iterator iter = classList.iterator(); iter.hasNext();) {
addClass((ClassNode) iter.next());
}
}
Appends all of the fully qualified class names in this
module into the given map |
public void addModule(ModuleNode node) {
// node==null means a compilation error prevented
// groovy from building an ast
if (node==null) return;
modules.add(node);
node.setUnit(this);
addClasses(node.getClasses());
}
|
public ClassNode getClass(String name) {
ClassNode cn = (ClassNode) classes.get(name);
if (cn!=null) return cn;
return (ClassNode) classesToCompile.get(name);
}
|
public GroovyClassLoader getClassLoader() {
return classLoader;
}
|
public List getClasses() {
List answer = new ArrayList();
for (Iterator iter = modules.iterator(); iter.hasNext();) {
ModuleNode module = (ModuleNode) iter.next();
answer.addAll(module.getClasses());
}
return answer;
}
|
public CodeSource getCodeSource() {
return codeSource;
}
|
public CompilerConfiguration getConfig() {
return config;
}
|
public List getModules() {
return modules;
}
|
public SourceUnit getScriptSourceLocation(String className) {
return (SourceUnit) classNameToSource.get(className);
}
|
public boolean hasClassNodeToCompile() {
return !classesToCompile.isEmpty();
}
|
public Iterator iterateClassNodeToCompile() {
return classesToCompile.keySet().iterator();
}
|