Debian Codegraph @

rhino/src/org/mozilla/javascript/ast/ErrorCollector.java

raw symbols SCIP
1 /* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7 package org.mozilla.javascript.ast;
8
9 import org.mozilla.javascript.EvaluatorException;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 /**
15 * An error reporter that gathers the errors and warnings for later display.
16 * This a useful {@link org.mozilla.javascript.ErrorReporter} when the
17 * {@link org.mozilla.javascript.CompilerEnvirons} is set to
18 * ide-mode (for IDEs).
19 *
20 * @author Steve Yegge
21 */
22 public class ErrorCollector implements IdeErrorReporter {
23
24 private List<ParseProblem> errors = new ArrayList<ParseProblem>();
25
26 /**
27 * This is not called during AST generation.
28 * {@link #warning(String,String,int,int)} is used instead.
29 * @throws UnsupportedOperationException
30 */
31 public void warning(String message, String sourceName, int line,
32 String lineSource, int lineOffset) {
33 throw new UnsupportedOperationException();
34 }
35
36 /**
37 * @inheritDoc
38 */
39 public void warning(String message, String sourceName, int offset, int length)
40 {
41 errors.add(new ParseProblem(ParseProblem.Type.Warning,
42 message, sourceName,
43 offset, length));
44 }
45
46 /**
47 * This is not called during AST generation.
48 * {@link #warning(String,String,int,int)} is used instead.
49 * @throws UnsupportedOperationException
50 */
51 public void error(String message, String sourceName, int line,
52 String lineSource, int lineOffset)
53 {
54 throw new UnsupportedOperationException();
55 }
56
57 /**
58 * @inheritDoc
59 */
60 public void error(String message, String sourceName,
61 int fileOffset, int length)
62 {
63 errors.add(new ParseProblem(ParseProblem.Type.Error,
64 message, sourceName,
65 fileOffset, length));
66 }
67
68 /**
69 * @inheritDoc
70 */
71 public EvaluatorException runtimeError(String message, String sourceName,
72 int line, String lineSource,
73 int lineOffset)
74 {
75 throw new UnsupportedOperationException();
76 }
77
78 /**
79 * Returns the list of errors and warnings produced during parsing.
80 */
81 public List<ParseProblem> getErrors() {
82 return errors;
83 }
84
85 @Override
86 public String toString() {
87 StringBuilder sb = new StringBuilder(errors.size() * 100);
88 for (ParseProblem pp : errors) {
89 sb.append(pp.toString()).append("\n");
90 }
91 return sb.toString();
92 }
93 }