Package com.google.gwt.dev.js

Examples of com.google.gwt.dev.js.JsParser


    return false;
  }

  private void findJsniRefsAccurately(MethodDeclaration methodDeclaration,
      String jsniCode) throws InternalCompilerException {
    JsParser jsParser = new JsParser();
    JsProgram jsProgram = new JsProgram();

    String syntheticFnHeader = "function(";
    boolean first = true;
    if (methodDeclaration.arguments != null) {
      for (int i = 0, c = methodDeclaration.arguments.length; i < c; ++i) {
        Argument arg = methodDeclaration.arguments[i];
        if (first) {
          first = false;
        } else {
          syntheticFnHeader += ',';
        }
        syntheticFnHeader += String.valueOf(arg.name);
      }
    }
    syntheticFnHeader += ')';
    StringReader sr = new StringReader(syntheticFnHeader + '\n' + jsniCode);
    try {
      // start at -1 to avoid counting our synthetic header
    List<JsStatement> result = jsParser.parse(jsProgram.getScope(), sr, -1);
      new JsVisitor() {
        public void endVisit(JsNameRef x, JsContext<JsExpression> ctx) {
          String ident = x.getIdent();
          if (ident.charAt(0) == '@') {
            jsniRefs.add(ident.substring(1));
View Full Code Here


  private JsBlock parseFunction(String jsniSrc) {
    Throwable caught = null;
    try {
      JsProgram jsPgm = new JsProgram();
      JsParser jsParser = new JsParser();
      StringReader r = new StringReader(jsniSrc);
      List<JsStatement> stmts = jsParser.parse(jsPgm.getScope(), r, 1);
      JsFunction fn = (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
      return fn.getBody();
    } catch (IOException e) {
      caught = e;
    } catch (JsParserException e) {
View Full Code Here

  }

  public String optimizeJavaScript(TreeLogger logger, String program)
      throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Attempting to optimize JS", null);
    JsParser parser = new JsParser();
    Reader r = new StringReader(program);
    JsProgram jsProgram = new JsProgram();
    JsScope topScope = jsProgram.getScope();
    JsName funcName = topScope.declareName(getModuleFunctionName());
    funcName.setObfuscatable(false);

    try {
      parser.parseInto(topScope, jsProgram.getGlobalBlock(), r, 1);
    } catch (IOException e) {
      logger.log(TreeLogger.ERROR, "Unable to parse JavaScript", e);
      throw new UnableToCompleteException();
    } catch (JsParserException e) {
      logger.log(TreeLogger.ERROR, "Unable to parse JavaScript", e);
View Full Code Here

      sb.append('}');
      r = new StringReader(sb.toString());
    }

    try {
      List<JsStatement> stmts = new JsParser().parse(program.getScope(), r,
          startLine);

      return (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
    } catch (IOException e) {
      // Should never happen.
View Full Code Here

  }

  public String optimizeJavaScript(TreeLogger logger, String program)
      throws UnableToCompleteException {
    logger = logger.branch(TreeLogger.DEBUG, "Attempting to optimize JS", null);
    JsParser parser = new JsParser();
    Reader r = new StringReader(program);
    JsProgram jsProgram = new JsProgram();
    JsScope topScope = jsProgram.getScope();
    JsName funcName = topScope.declareName(getModuleFunctionName());
    funcName.setObfuscatable(false);

    try {
      parser.parseInto(topScope, jsProgram.getGlobalBlock(), r, 1);
    } catch (IOException e) {
      logger.log(TreeLogger.ERROR, "Unable to parse JavaScript", e);
      throw new UnableToCompleteException();
    } catch (JsParserException e) {
      logger.log(TreeLogger.ERROR, "Unable to parse JavaScript", e);
View Full Code Here

      sb.append('}');
      r = new StringReader(sb.toString());
    }

    try {
      List<JsStatement> stmts = new JsParser().parse(program.getScope(), r,
          startLine);

      return (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
    } catch (IOException e) {
      // Should never happen.
View Full Code Here

  private JsBlock parseFunction(String jsniSrc) {
    Throwable caught = null;
    try {
      JsProgram jsPgm = new JsProgram();
      JsParser jsParser = new JsParser();
      StringReader r = new StringReader(jsniSrc);
      JsStatements stmts = jsParser.parse(jsPgm.getScope(), r, 1);
      JsFunction fn = (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
      return fn.getBody();
    } catch (IOException e) {
      caught = e;
    } catch (JsParserException e) {
View Full Code Here

  public static JsBlock parseAsFunctionBody(TreeLogger logger, String js,
      String location, int startLine) throws UnableToCompleteException {
    // Wrap it in fake function and parse it.
    js = "function(){ " + js + " }";

    JsParser jsParser = new JsParser();
    JsProgram jsPgm = new JsProgram();
    StringReader r = new StringReader(js);

    try {
      JsStatements stmts = jsParser.parse(jsPgm.getScope(), r, startLine);

      // Rip the body out of the parsed function and attach the JavaScript
      // AST to the method.
      //
      JsFunction fn = (JsFunction) ((JsExprStmt) stmts.get(0)).getExpression();
View Full Code Here

        pw.close();
        rawSource = sw.toString();
      }

      {
        JsParser parser = new JsParser();
        Reader r = new StringReader(rawSource);
        JsProgram jsProgram = new JsProgram();
        JsScope topScope = jsProgram.getScope();
        JsName funcName = topScope.declareName(moduleFunction);
        funcName.setObfuscatable(false);

        parser.parseInto(topScope, jsProgram.getGlobalBlock(), r, 1);
        JsSymbolResolver.exec(jsProgram);
        if (obfuscate) {
          JsObfuscateNamer.exec(jsProgram);
        } else {
          JsVerboseNamer.exec(jsProgram);
View Full Code Here

TOP

Related Classes of com.google.gwt.dev.js.JsParser

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.