code: public void addClass(ClassNode node) {
          node = node.redirect();
          String name = node.getName();
          ClassNode stored = classes.get(name);
          if (stored != null && stored != node) {
              // we have a duplicate class!
              // One possibility for this is, that we declared 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 definitions of the class " + node.getName() + ".\n";
                  if (node.isScriptBody() || stored.isScriptBody()) {
                      txt += "One of the classes is an 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() + " each contain a class with the name " + node.getName() + ".\n";
              }
              nodeSource.getErrorCollector().addErrorAndContinue(
                      new SyntaxErrorMessage(new SyntaxException(txt, node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()), nodeSource)
              );
          }
          classes.put(name, node);
  
          if (classesToCompile.containsKey(name)) {
              ClassNode cn = classesToCompile.get(name);
              cn.setRedirect(node);
              classesToCompile.remove(name);
          }
      }
docs: Adds a class to the unit.