code: public static boolean exists(Compiler c, String name, CompilationUnit from) {
          String fqName = getFullyQualifiedName(resolveName(name, from));
          try {
              c.loadClass(fqName);
              return true;
          }
          catch (ClassNotFoundException nx) {
              try {
                  c.loadClass(resolveName(name, from));  // Try standard path as a last resort
                  return true;
              }
              catch (ClassNotFoundException nx2) {
                  return false;
              }
          }
      }
docs: Test to see of the template can be loaded before CompiledTemplate can be
  constructed.