Java Code Examples for com.google.javascript.rhino.Node#setInputId()

The following examples show how to use com.google.javascript.rhino.Node#setInputId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LiveVariableAnalysisTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
private static LiveVariablesAnalysis computeLiveness(String src) {
  Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  options.setCodingConvention(new GoogleCodingConvention());
  compiler.initOptions(options);
  src = "function _FUNCTION(param1, param2){" + src + "}";
  Node n = compiler.parseTestCode(src).removeFirstChild();
  Node script = new Node(Token.SCRIPT, n);
  script.setInputId(new InputId("test"));
  assertEquals(0, compiler.getErrorCount());
  Scope scope = new SyntacticScopeCreator(compiler).createScope(
      n, Scope.createGlobalScope(script));
  ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
  cfa.process(null, n);
  ControlFlowGraph<Node> cfg = cfa.getCfg();
  LiveVariablesAnalysis analysis =
      new LiveVariablesAnalysis(cfg, scope, compiler);
  analysis.analyze();
  return analysis;
}
 
Example 2
Source File: CodePrinterTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
Node parse(String js, boolean checkTypes) {
  Compiler compiler = new Compiler();
  CompilerOptions options = new CompilerOptions();
  options.setTrustedStrings(trustedStrings);

  // Allow getters and setters.
  options.setLanguageIn(LanguageMode.ECMASCRIPT5);
  compiler.initOptions(options);
  Node n = compiler.parseTestCode(js);

  if (checkTypes) {
    DefaultPassConfig passConfig = new DefaultPassConfig(null);
    CompilerPass typeResolver = passConfig.resolveTypes.create(compiler);
    Node externs = new Node(Token.SCRIPT);
    externs.setInputId(new InputId("externs"));
    Node externAndJsRoot = new Node(Token.BLOCK, externs, n);
    externAndJsRoot.setIsSyntheticBlock(true);
    typeResolver.process(externs, n);
    CompilerPass inferTypes = passConfig.inferTypes.create(compiler);
    inferTypes.process(externs, n);
  }

  checkUnexpectedErrorsOrWarnings(compiler, 0);
  return n;
}
 
Example 3
Source File: Closure_18_Compiler_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds a new Script AST to the compile state. If a script for the same file
 * already exists the script will not be added, instead a call to
 * #replaceScript should be used.
 *
 * @param ast the ast of the new file
 */
public void addNewScript(JsAst ast) {
  if (!addNewSourceAst(ast)) {
    return;
  }
  Node emptyScript = new Node(Token.SCRIPT);
  InputId inputId = ast.getInputId();
  emptyScript.setInputId(inputId);
  emptyScript.setStaticSourceFile(
      SourceFile.fromCode(inputId.getIdName(), ""));

  processNewScript(ast, emptyScript);
}
 
Example 4
Source File: Closure_18_Compiler_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds a new Script AST to the compile state. If a script for the same file
 * already exists the script will not be added, instead a call to
 * #replaceScript should be used.
 *
 * @param ast the ast of the new file
 */
public void addNewScript(JsAst ast) {
  if (!addNewSourceAst(ast)) {
    return;
  }
  Node emptyScript = new Node(Token.SCRIPT);
  InputId inputId = ast.getInputId();
  emptyScript.setInputId(inputId);
  emptyScript.setStaticSourceFile(
      SourceFile.fromCode(inputId.getIdName(), ""));

  processNewScript(ast, emptyScript);
}
 
Example 5
Source File: Closure_31_Compiler_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds a new Script AST to the compile state. If a script for the same file
 * already exists the script will not be added, instead a call to
 * #replaceScript should be used.
 *
 * @param ast the ast of the new file
 */
public void addNewScript(JsAst ast) {
  if (!addNewSourceAst(ast)) {
    return;
  }
  Node emptyScript = new Node(Token.SCRIPT);
  InputId inputId = ast.getInputId();
  emptyScript.setInputId(inputId);
  emptyScript.setStaticSourceFile(
      SourceFile.fromCode(inputId.getIdName(), ""));

  processNewScript(ast, emptyScript);
}
 
Example 6
Source File: Closure_31_Compiler_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Adds a new Script AST to the compile state. If a script for the same file
 * already exists the script will not be added, instead a call to
 * #replaceScript should be used.
 *
 * @param ast the ast of the new file
 */
public void addNewScript(JsAst ast) {
  if (!addNewSourceAst(ast)) {
    return;
  }
  Node emptyScript = new Node(Token.SCRIPT);
  InputId inputId = ast.getInputId();
  emptyScript.setInputId(inputId);
  emptyScript.setStaticSourceFile(
      SourceFile.fromCode(inputId.getIdName(), ""));

  processNewScript(ast, emptyScript);
}
 
Example 7
Source File: Compiler.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Adds a new Script AST to the compile state. If a script for the same file
 * already exists the script will not be added, instead a call to
 * #replaceScript should be used.
 *
 * @param ast the ast of the new file
 */
public void addNewScript(JsAst ast) {
  if (!addNewSourceAst(ast)) {
    return;
  }
  Node emptyScript = new Node(Token.SCRIPT);
  InputId inputId = ast.getInputId();
  emptyScript.setInputId(inputId);
  emptyScript.setStaticSourceFile(
      SourceFile.fromCode(inputId.getIdName(), ""));

  processNewScript(ast, emptyScript);
}
 
Example 8
Source File: AstValidatorTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testValidScript() {
  Node n = new Node(Token.SCRIPT);
  expectInvalid(n, Check.SCRIPT);
  n.setInputId(new InputId("something_input"));
  n.setStaticSourceFile(new SimpleSourceFile("something", false));
  expectValid(n, Check.SCRIPT);
  expectInvalid(n, Check.STATEMENT);
  expectInvalid(n, Check.EXPRESSION);
}
 
Example 9
Source File: JsDocInfoParserTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private JSDocInfo parse(String comment, boolean parseDocumentation,
    boolean parseFileOverview, String... warnings) {
  TestErrorReporter errorReporter = new TestErrorReporter(null, warnings);

  Config config = new Config(extraAnnotations, extraSuppressions,
      parseDocumentation, LanguageMode.ECMASCRIPT3, false);
  StaticSourceFile file = new SimpleSourceFile("testcode", false);
  Node associatedNode = new Node(Token.SCRIPT);
  associatedNode.setInputId(new InputId(file.getName()));
  associatedNode.setStaticSourceFile(file);
  JsDocInfoParser jsdocParser = new JsDocInfoParser(
      stream(comment),
      new Comment(0, 0, CommentType.JSDOC, comment),
      associatedNode,
      config, errorReporter);

  if (fileLevelJsDocBuilder != null) {
    jsdocParser.setFileLevelJsDocBuilder(fileLevelJsDocBuilder);
  }

  jsdocParser.parse();

  assertTrue("expected warnings were not reported",
      errorReporter.hasEncounteredAllWarnings());

  if (parseFileOverview) {
    return jsdocParser.getFileOverviewJSDocInfo();
  } else {
    return jsdocParser.retrieveAndResetParsedJSDocInfo();
  }
}