Java Code Examples for org.mozilla.javascript.ast.AstRoot#visit()

The following examples show how to use org.mozilla.javascript.ast.AstRoot#visit() . 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: ClassDefScanner.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Scan the given file for class definitions and accumulate dependencies.
 */
private void scan(final File source) throws IOException {
  log.debug("Scanning: " + source);

  ErrorReporter errorReporter = new LogErrorReporter(log);

  CompilerEnvirons env = new CompilerEnvirons();
  env.setErrorReporter(errorReporter);

  Parser parser = new Parser(env, errorReporter);
  Reader reader = new BufferedReader(new FileReader(source));
  try {
    AstRoot root = parser.parse(reader, source.getAbsolutePath(), 0);
    DependencyAccumulator visitor = new DependencyAccumulator(source);
    root.visit(visitor);

    // complain if no def was found in this source
    if (visitor.current == null) {
      log.warn("No class definition was found while processing: " + source);
    }
  }
  finally {
    reader.close();
  }
}
 
Example 2
Source File: ConstraintGenerator.java    From SJS with Apache License 2.0 5 votes vote down vote up
/**
	 * generate constraints from JavaScript code
	 * @param code the AST to generate constraints for
	 */
	public void generateConstraints(AstRoot code) {
//        System.out.println(code.toSource(0));
        code.visit(constraintVisitor);
		List<SyntaxError> errors = constraintVisitor.getErrors();
		if (!errors.isEmpty()) {
			StringBuilder errmsg = new StringBuilder();
			errmsg.append("Found ").append(errors.size()).append(" syntax errors:");
			for (SyntaxError e : errors) {
				errmsg.append("\n  ").append(e.getMessage())
						.append(" (at line ").append(e.getNode().getLineno()).append(')');
			}
			throw new SolverException(errmsg.toString());
		}
	}
 
Example 3
Source File: JavascriptTestability.java    From testability-explorer with Apache License 2.0 5 votes vote down vote up
public int calculateCost() throws IOException {
  FunctionCountNodeVisitor v = new FunctionCountNodeVisitor();
  for (AstRoot astRoot : repository.getAsts()) {
    astRoot.visit(v);
  }
  return v.getCount();
}