Package org.stjs.generator

Examples of org.stjs.generator.STJSRuntimeException


  static void compile(final String path, final List<File> sourceFiles, List<File> dependencies) {
    try {
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      if (compiler == null) {
        throw new STJSRuntimeException("A Java compiler is not available for this project. "
            + "You may have configured your environment to run with a JRE instead of a JDK");
      }
      StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
      fileManager.setLocation(StandardLocation.CLASS_PATH, dependencies);
View Full Code Here


  private <T extends AstNode> T cast(AstNode node, Class<T> clazz) {
    if (node == null) {
      return null;
    }
    if (!clazz.isAssignableFrom(node.getClass())) {
      throw new STJSRuntimeException("Received wrong JavaScript node type:" + node.getClass().getName() + " instead of " + clazz.getName()
          + ". This is probably a ST-JS bug. Please report it to our website");
    }
    return (T) node;
  }
View Full Code Here

      contents = Resources.toString(url, Charsets.UTF_8);
      SourceMapping mapping = SourceMapConsumerFactory.parse(contents);
      return mapping.getMappingForLine(lineNumber, 1).getLineNumber();
    }
    catch (IOException e) {
      throw new STJSRuntimeException(e);
    }
    catch (SourceMapParseException e) {
      throw new STJSRuntimeException(e);
    }
  }
View Full Code Here

      Properties p = new Properties();
      p.load(in);
      return p.getProperty(STJSClass.CLASS_PROP);
    }
    catch (IOException e) {
      throw new STJSRuntimeException(e);
    }
    finally {
      if (in != null) {
        Closeables.closeQuietly(in);
      }
View Full Code Here

  private StackTraceElement buildStacktraceElement(String stacktraceLine) {

    Matcher m = STACKTRACE_UNIVERSAL_JS_PATTERN.matcher(stacktraceLine);
    if (!m.matches()) {
      // wrong pattern !?
      throw new STJSRuntimeException("Unknown location format:" + stacktraceLine);
    }
    try {

      String methodName = m.group(STACKTRACE_GROUP_METHOD);

      URL url = new URL(m.group(STACKTRACE_GROUP_LOCATION));
      String file = url.getFile();
      String[] fileParts = file.split(":");

      // source file
      String jsSourceFile = fileParts[0];
      String sourceFile = jsSourceFile.replaceAll("\\.js$", ".java");

      // java line
      String cleanJsPath = url.getPath().split(":")[0];
      int jsLineNumber = Integer.valueOf(fileParts[1]);
      int line = getJavaLine(cleanJsPath, jsLineNumber);
      String stjsPropertyFile = cleanJsPath.replaceAll("\\.js$", ".stjs");

      // class name
      String className = getClassName(stjsPropertyFile);
      if (className == null) {
        className = "<Unknown class>";
        sourceFile = jsSourceFile;
      }
      return new StackTraceElement(className, methodName, sourceFile, line);

    }
    catch (MalformedURLException e) {
      throw new STJSRuntimeException(e);
    }
  }
View Full Code Here

    for (int i = 0; i < level; i++) {
      try {
        writer.append(INDENT);
      }
      catch (IOException e) {
        throw new STJSRuntimeException("Writing problem:" + e, e);
      }
      currentColumn += INDENT.length();
    }
  }
View Full Code Here

    }
    try {
      writer.append(arg);
    }
    catch (IOException e) {
      throw new STJSRuntimeException("Writing problem:" + e, e);
    }
    // TODO check for newlines in the string
    currentColumn += arg.length();
    return this;
  }
View Full Code Here

  public RhinoJavaScriptWriter println() {
    try {
      writer.append('\n');
    }
    catch (IOException e) {
      throw new STJSRuntimeException("Writing problem:" + e, e);
    }
    indented = false;
    currentLine++;
    currentColumn = 0;
    addMapping();
View Full Code Here

      for (Method m : obj.getClass().getMethods()) {
        if (m.getName().equals(method) && m.getParameterTypes().length == argCount) {
          return m.invoke(obj, args);
        }
      }
      throw new STJSRuntimeException("Method " + method + " not found in class " + obj.getClass());
    }
    catch (InvocationTargetException e) {
      throw new STJSRuntimeException(e);
    }
    catch (IllegalArgumentException e) {
      throw new STJSRuntimeException(e);
    }
    catch (IllegalAccessException e) {
      throw new STJSRuntimeException(e);
    }
  }
View Full Code Here

    catch (ScriptException ex) {
      // display the generated code in case of exception
      for (File file : javascriptFiles) {
        displayWithLines(file);
      }
      throw new STJSRuntimeException(ex);
    }
    finally {
      Timers.end("js-exec");
    }
  }
View Full Code Here

TOP

Related Classes of org.stjs.generator.STJSRuntimeException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.