com.google.javascript.jscomp.NodeTraversal.Callback Java Examples

The following examples show how to use com.google.javascript.jscomp.NodeTraversal.Callback. 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: DefaultPassConfig.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected HotSwapCompilerPass create(final AbstractCompiler compiler) {
  List<Callback> sharedCallbacks = Lists.newArrayList();
  if (options.checkSuspiciousCode) {
    sharedCallbacks.add(new CheckSuspiciousCode());
  }

  if (options.enables(DiagnosticGroups.GLOBAL_THIS)) {
    sharedCallbacks.add(new CheckGlobalThis(compiler));
  }

  if (options.enables(DiagnosticGroups.DEBUGGER_STATEMENT_PRESENT)) {
    sharedCallbacks.add(new CheckDebuggerStatement(compiler));
  }

  return combineChecks(compiler, sharedCallbacks);
}
 
Example #2
Source File: Closure_102_Normalize_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Remove duplicate VAR declarations.
 */
private void removeDuplicateDeclarations(Node root) {
  Callback tickler = new ScopeTicklingCallback();
  ScopeCreator scopeCreator =  new SyntacticScopeCreator(
      compiler, new DuplicateDeclarationHandler());
  NodeTraversal t = new NodeTraversal(compiler, tickler, scopeCreator);
  t.traverse(root);
}
 
Example #3
Source File: Closure_79_Normalize_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Remove duplicate VAR declarations.
 */
private void removeDuplicateDeclarations(Node externs, Node root) {
  Callback tickler = new ScopeTicklingCallback();
  ScopeCreator scopeCreator =  new SyntacticScopeCreator(
      compiler, new DuplicateDeclarationHandler());
  NodeTraversal t = new NodeTraversal(compiler, tickler, scopeCreator);
  t.traverseRoots(externs, root);
}
 
Example #4
Source File: Closure_79_Normalize_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Remove duplicate VAR declarations.
 */
private void removeDuplicateDeclarations(Node externs, Node root) {
  Callback tickler = new ScopeTicklingCallback();
  ScopeCreator scopeCreator =  new SyntacticScopeCreator(
      compiler, new DuplicateDeclarationHandler());
  NodeTraversal t = new NodeTraversal(compiler, tickler, scopeCreator);
  t.traverseRoots(externs, root);
}
 
Example #5
Source File: Closure_102_Normalize_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Remove duplicate VAR declarations.
 */
private void removeDuplicateDeclarations(Node root) {
  Callback tickler = new ScopeTicklingCallback();
  ScopeCreator scopeCreator =  new SyntacticScopeCreator(
      compiler, new DuplicateDeclarationHandler());
  NodeTraversal t = new NodeTraversal(compiler, tickler, scopeCreator);
  t.traverse(root);
}
 
Example #6
Source File: CombinedCompilerPass.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
CombinedCompilerPass(
    AbstractCompiler compiler, List<Callback> callbacks) {
  this.compiler = compiler;
  this.callbacks = new CallbackWrapper[callbacks.size()];
  for (int i = 0; i < callbacks.size(); i++) {
    this.callbacks[i] = new CallbackWrapper(callbacks.get(i));
  }
}
 
Example #7
Source File: CombinedCompilerPass.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static void traverse(AbstractCompiler compiler, Node root,
    List<Callback> callbacks) {
  if (callbacks.size() == 1) {
    NodeTraversal.traverse(compiler, root, callbacks.get(0));
  } else {
    (new CombinedCompilerPass(compiler, callbacks)).process(null, root);
  }
}
 
Example #8
Source File: CombinedCompilerPass.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private CallbackWrapper(Callback callback) {
  this.callback = callback;
  if (callback instanceof ScopedCallback) {
    scopedCallback = (ScopedCallback) callback;
  } else {
    scopedCallback = null;
  }
}
 
Example #9
Source File: Normalize.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Remove duplicate VAR declarations.
 */
private void removeDuplicateDeclarations(Node externs, Node root) {
  Callback tickler = new ScopeTicklingCallback();
  ScopeCreator scopeCreator =  new SyntacticScopeCreator(
      compiler, new DuplicateDeclarationHandler());
  NodeTraversal t = new NodeTraversal(compiler, tickler, scopeCreator);
  t.traverseRoots(externs, root);
}
 
Example #10
Source File: FieldCleanupPass.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
  String srcName = originalRoot.getSourceFileName();
  Callback cb =
      new QualifiedNameSearchTraversal(compiler.getTypeRegistry(), srcName);
  new NodeTraversal(compiler, cb).traverse(originalRoot);
}
 
Example #11
Source File: DefaultPassConfig.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected HotSwapCompilerPass create(AbstractCompiler compiler) {
  List<Callback> callbacks = Lists.newArrayList();
  if (options.checkUnreachableCode.isOn()) {
    callbacks.add(
        new CheckUnreachableCode(compiler, options.checkUnreachableCode));
  }
  if (options.checkMissingReturn.isOn() && options.checkTypes) {
    callbacks.add(
        new CheckMissingReturn(compiler, options.checkMissingReturn));
  }
  return combineChecks(compiler, callbacks);
}
 
Example #12
Source File: DefaultPassConfig.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Executes the given callbacks with a {@link CombinedCompilerPass}. */
private static HotSwapCompilerPass combineChecks(AbstractCompiler compiler,
    List<Callback> callbacks) {
  Preconditions.checkArgument(callbacks.size() > 0);
  Callback[] array = callbacks.toArray(new Callback[callbacks.size()]);
  return new CombinedCompilerPass(compiler, array);
}
 
Example #13
Source File: ClosureCodeRemoval.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void process(Node externs, Node root) {
  List<Callback> passes = Lists.newArrayList();
  if (removeAbstractMethods) {
    passes.add(new FindAbstractMethods());
  }
  if (removeAssertionCalls) {
    passes.add(new FindAssertionCalls());
  }
  CombinedCompilerPass.traverse(compiler, root, passes);

  for (RemovableAssignment assignment : abstractMethodAssignmentNodes) {
    assignment.remove();
  }

  for (Node call : assertionCalls) {
    // If the assertion is an expression, just strip the whole thing.
    Node parent = call.getParent();
    if (parent.isExprResult()) {
      parent.getParent().removeChild(parent);
    } else {
      // Otherwise, replace the assertion with its first argument,
      // which is the return value of the assertion.
      Node firstArg = call.getFirstChild().getNext();
      if (firstArg == null) {
        parent.replaceChild(call, NodeUtil.newUndefinedNode(call));
      } else {
        parent.replaceChild(call, firstArg.detachFromParent());
      }
    }
    compiler.reportCodeChange();
  }
}
 
Example #14
Source File: InlineSimpleMethods.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
Callback getActingCallback() {
  return new InlineTrivialAccessors();
}
 
Example #15
Source File: CheckRequiresForConstructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void hotSwapScript(Node scriptRoot, Node originalRoot) {
  Callback callback = new CheckRequiresForConstructorsCallback();
  new NodeTraversal(compiler, callback).traverseWithScope(scriptRoot,
      SyntacticScopeCreator.generateUntypedTopScope(compiler));
}
 
Example #16
Source File: CheckRequiresForConstructors.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Uses Collections of new and goog.require nodes to create a compiler warning
 * for each new class name without a corresponding goog.require().
 */
@Override
public void process(Node externs, Node root) {
  Callback callback = new CheckRequiresForConstructorsCallback();
  new NodeTraversal(compiler, callback).traverseRoots(externs, root);
}
 
Example #17
Source File: CombinedCompilerPass.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Creates a combined compiler pass.
 * @param compiler the compiler
 */
CombinedCompilerPass(
    AbstractCompiler compiler, Callback... callbacks) {
  this(compiler, Lists.<Callback>newArrayList(callbacks));
}
 
Example #18
Source File: MethodCompilerPass.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Subclasses should return a callback that does the actual work they
 * want to perform given the computed list of method signatures
 */
abstract Callback getActingCallback();