当前位置: 首页>>代码示例>>Java>>正文


Java Node.checkTreeEquals方法代码示例

本文整理汇总了Java中com.google.javascript.rhino.Node.checkTreeEquals方法的典型用法代码示例。如果您正苦于以下问题:Java Node.checkTreeEquals方法的具体用法?Java Node.checkTreeEquals怎么用?Java Node.checkTreeEquals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.javascript.rhino.Node的用法示例。


在下文中一共展示了Node.checkTreeEquals方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: test

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
/**
 * Asserts that when compiling with the given compiler options,
 * {@code original} is transformed into {@code compiled}.
 */
private void test(String[] original, String[] compiled) {
  Compiler compiler = compile(original);
  assertEquals("Expected no warnings or errors\n" +
      "Errors: \n" + Joiner.on("\n").join(compiler.getErrors()) +
      "Warnings: \n" + Joiner.on("\n").join(compiler.getWarnings()),
      0, compiler.getErrors().length + compiler.getWarnings().length);

  Node root = compiler.getRoot().getLastChild();
  if (useStringComparison) {
    assertEquals(Joiner.on("").join(compiled), compiler.toSource());
  } else {
    Node expectedRoot = parse(compiled);
    String explanation = expectedRoot.checkTreeEquals(root);
    assertNull("\nExpected: " + compiler.toSource(expectedRoot) +
        "\nResult: " + compiler.toSource(root) +
        "\n" + explanation, explanation);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:23,代码来源:CommandLineRunnerTest.java

示例2: helperExposeExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void helperExposeExpression(
    String code,
    String fnName,
    String expectedResult,
    Set<String> knownConstants
    ) {
  Compiler compiler = new Compiler();
  if (knownConstants == null) {
    knownConstants = Sets.newHashSet();
  }
  ExpressionDecomposer decomposer = new ExpressionDecomposer(
      compiler, compiler.getUniqueNameIdSupplier(), knownConstants);
  decomposer.setTempNamePrefix("temp_");
  Node expectedRoot = parse(compiler, expectedResult);
  Node tree = parse(compiler, code);
  assertNotNull(tree);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;

  Node callSite = findCall(tree, fnName);
  assertNotNull("Call to " + fnName + " was not found.", callSite);

  DecompositionType result = decomposer.canExposeExpression(callSite);
  assertTrue(result == DecompositionType.DECOMPOSABLE);

  compiler.resetUniqueNameId();
  decomposer.exposeExpression(callSite);
  String explanation = expectedRoot.checkTreeEquals(tree);
  assertNull("\nExpected: " + compiler.toSource(expectedRoot) +
      "\nResult: " + compiler.toSource(tree) +
      "\n" + explanation, explanation);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:34,代码来源:ExpresssionDecomposerTest.java

示例3: helperMoveExpression

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void helperMoveExpression(
    String code,
    String fnName,
    String expectedResult,
    Set<String> knownConstants
    ) {
  Compiler compiler = new Compiler();
  if (knownConstants == null) {
    knownConstants = Sets.newHashSet();
  }

  ExpressionDecomposer decomposer = new ExpressionDecomposer(
      compiler, compiler.getUniqueNameIdSupplier(), knownConstants);
  decomposer.setTempNamePrefix("temp_");
  Node expectedRoot = parse(compiler, expectedResult);
  Node tree = parse(compiler, code);
  assertNotNull(tree);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;

  Node callSite = findCall(tree, fnName);
  assertNotNull("Call to " + fnName + " was not found.", callSite);

  compiler.resetUniqueNameId();
  decomposer.moveExpression(callSite);
  String explanation = expectedRoot.checkTreeEquals(tree);
  assertNull("\nExpected: " + compiler.toSource(expectedRoot) +
      "\nResult: " + compiler.toSource(tree) +
      "\n" + explanation, explanation);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:32,代码来源:ExpresssionDecomposerTest.java

示例4: testNewFunctionNode

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void testNewFunctionNode() {
  Node expected = parse("function foo(p1, p2, p3) { throw 2; }");
  Node body = new Node(Token.BLOCK, new Node(Token.THROW, Node.newNumber(2)));
  List<Node> params = Lists.newArrayList(Node.newString(Token.NAME, "p1"),
                                         Node.newString(Token.NAME, "p2"),
                                         Node.newString(Token.NAME, "p3"));
  FunctionNode function = NodeUtil.newFunctionNode(
      "foo", params, body, -1, -1);
  ScriptOrFnNode actual = new ScriptOrFnNode(Token.SCRIPT);
  actual.addChildToFront(function);
  String difference = expected.checkTreeEquals(actual);
  if (difference != null) {
    assertTrue("Nodes do not match:\n" + difference, false);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:16,代码来源:NodeUtilTest.java

示例5: helperInlineReferenceToFunction

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void helperInlineReferenceToFunction(
    String code, final String expectedResult,
    final String fnName, final InliningMode mode,
    final boolean decompose) {
  final Compiler compiler = new Compiler();
  final FunctionInjector injector = new FunctionInjector(
      compiler, compiler.getUniqueNameIdSupplier(), decompose);

  JSSourceFile[] externsInputs = new JSSourceFile[] {
      JSSourceFile.fromCode("externs", "")
  };

  CompilerOptions options = new CompilerOptions();
  compiler.init(externsInputs, new JSSourceFile[] {
      JSSourceFile.fromCode("code", code) }, options);
  Node parseRoot = compiler.parseInputs();
  Node externsRoot = parseRoot.getFirstChild();
  final Node tree = parseRoot.getLastChild();
  assertNotNull(tree);
  assertTrue(tree != externsRoot);

  final Node expectedRoot = parseExpected(new Compiler(), expectedResult);

  Node mainRoot = tree;
  MarkNoSideEffectCalls mark = new MarkNoSideEffectCalls(compiler);
  mark.process(externsRoot, mainRoot);

  Normalize normalize = new Normalize(compiler, false);
  normalize.process(externsRoot, mainRoot);
  compiler.setNormalized();

  final Node fnNode = findFunction(tree, fnName);
  assertNotNull(fnNode);
  final Set<String> unsafe =
      FunctionArgumentInjector.findModifiedParameters(fnNode);
  assertNotNull(fnNode);

  // inline tester
  Method tester = new Method() {
    public boolean call(NodeTraversal t, Node n, Node parent) {

      CanInlineResult canInline = injector.canInlineReferenceToFunction(
          t, n, fnNode, unsafe, mode, NodeUtil.referencesThis(fnNode));
      assertTrue("canInlineReferenceToFunction should not be CAN_NOT_INLINE",
          CanInlineResult.NO != canInline);
      if (decompose) {
        assertTrue("canInlineReferenceToFunction " +
            "should be CAN_INLINE_AFTER_DECOMPOSITION",
            CanInlineResult.AFTER_DECOMPOSITION == canInline);

        Set<String> knownConstants = Sets.newHashSet();
        injector.setKnownConstants(knownConstants);
        new ExpressionDecomposer(
            compiler, compiler.getUniqueNameIdSupplier(), knownConstants)
                .maybeDecomposeExpression(n);
        assertTrue("canInlineReferenceToFunction " +
            "should be CAN_INLINE",
            CanInlineResult.YES != canInline);
      }

      Node result = injector.inline(
          t, n, fnName, fnNode, mode);
      String explanation = expectedRoot.checkTreeEquals(tree.getFirstChild());
      assertNull("\nExpected: " + toSource(expectedRoot) +
          "\nResult: " + toSource(tree.getFirstChild()) +
          "\n" + explanation, explanation);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverse(compiler, tree, test);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:75,代码来源:FunctionInjectorTest.java

示例6: helperMutate

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
public void helperMutate(
    String code, final String expectedResult, final String fnName,
    final String resultName,
    final boolean needsDefaultResult,
    final boolean isCallInLoop) {
  final Compiler compiler = new Compiler();
  final FunctionToBlockMutator mutator = new FunctionToBlockMutator(
      compiler, compiler.getUniqueNameIdSupplier());
  Node expectedRoot = parse(compiler, expectedResult);
  final Node expected = expectedRoot.getFirstChild();
  final Node tree = parse(compiler, code);

  Node externsRoot = new Node(Token.EMPTY);
  Node mainRoot = tree;
  MarkNoSideEffectCalls mark = new MarkNoSideEffectCalls(compiler);
  mark.process(externsRoot, mainRoot);

  final Node fnNode = findFunction(tree, fnName);
  final Set<String> unsafe =
      FunctionArgumentInjector.findModifiedParameters(fnNode);

  // Fake precondition.
  compiler.setNormalized();

  // inline tester
  Method tester = new Method() {
    public boolean call(NodeTraversal t, Node n, Node parent) {

      Node result = mutator.mutate(
          fnName, fnNode, n, resultName,
          needsDefaultResult, isCallInLoop);
      String explanation = expected.checkTreeEquals(result);
      assertNull("\nExpected: " + compiler.toSource(expected) +
          "\nResult: " + compiler.toSource(result) +
          "\n" + explanation, explanation);
      return true;
    }
  };

  compiler.resetUniqueNameId();
  TestCallback test = new TestCallback(fnName, tester);
  NodeTraversal.traverse(compiler, tree, test);
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:44,代码来源:FunctionToBlockMutatorTest.java

示例7: assertNodeEquality

import com.google.javascript.rhino.Node; //导入方法依赖的package包/类
private void assertNodeEquality(Node expected, Node found) {
  String message = expected.checkTreeEquals(found);
  if (message != null) {
    fail(message);
  }
}
 
开发者ID:andyjko,项目名称:feedlack,代码行数:7,代码来源:ParserTest.java


注:本文中的com.google.javascript.rhino.Node.checkTreeEquals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。