public void call(SourceUnit source) throws CompilationFailedException {
          List<ClassNode> classes = source.ast.getClasses();
          for (ClassNode node : classes) {
            CompileUnit cu = node.getCompileUnit();
            for (Iterator iter = cu.iterateClassNodeToCompile(); iter.hasNext(); ) {
              String name = (String) iter.next();
              SourceUnit su = ast.getScriptSourceLocation(name);
              List<ClassNode> classesInSourceUnit = su.ast.getClasses();
              StringBuffer message = new StringBuffer();
              message
                  .append("Compilation incomplete: expected to find the class ")
                  .append(name)
                  .append(" in ")
                  .append(su.getName());
              if (classesInSourceUnit.isEmpty()) {
                message.append(", but the file seems not to contain any classes");
              } else {
                message.append(", but the file contains the classes: ");
                boolean first = true;
                for (ClassNode cn : classesInSourceUnit) {
                  if (!first) {
                    message.append(", ");
                  } else {
                    first = false;
                  }
                  message.append(cn.getName());
                }
              }

              getErrorCollector()
                  .addErrorAndContinue(new SimpleMessage(message.toString(), CompilationUnit.this));
              iter.remove();
            }
          }
        }
 protected CompileUnit getCompileUnit() {
   CompileUnit answer = classNode.getCompileUnit();
   if (answer == null) {
     answer = context.getCompileUnit();
   }
   return answer;
 }
 public static boolean isBeingCompiled(ClassNode node) {
   return node.getCompileUnit() != null;
 }
Esempio n. 4
0
 /**
  * Returns true if the two classes share the same compilation unit.
  *
  * @param a class a
  * @param b class b
  * @return true if both classes share the same compilation unit
  */
 public static boolean isSameCompilationUnit(ClassNode a, ClassNode b) {
   CompileUnit cu1 = a.getCompileUnit();
   CompileUnit cu2 = b.getCompileUnit();
   return cu1 != null && cu2 != null && cu1 == cu2;
 }