code: public final boolean stringIsCompilableUnit(String source) {
          boolean errorseen = false;
          CompilerEnvirons compilerEnv = new CompilerEnvirons();
          compilerEnv.initFromContext(this);
          // no source name or source text manager, because we're just
          // going to throw away the result.
          compilerEnv.setGeneratingSource(false);
          Parser p = new Parser(compilerEnv, DefaultErrorReporter.instance);
          try {
              p.parse(source, null, 1);
          } catch (EvaluatorException ee) {
              errorseen = true;
          }
          // Return false only if an error occurred as a result of reading past
          // the end of the file, i.e. if the source could be fixed by
          // appending more source.
          return !(errorseen && p.eof());
      }
docs: Check whether a string is ready to be compiled.
  <p>
  stringIsCompilableUnit is intended to support interactive compilation of
  JavaScript.  If compiling the string would result in an error
  that might be fixed by appending more source, this method
  returns false.  In every other case, it returns true.
  <p>
  Interactive shells may accumulate source lines, using this
  method after each new line is appended to check whether the
  statement being entered is complete.
  
  @param source the source buffer to check
  @return whether the source is ready for compilation
  @since 1.4 Release 2