Debian Codegraph @

src/com/google/javascript/jscomp/PrintStreamErrorManager.java

raw symbols SCIP
1 /*
2 * Copyright 2007 The Closure Compiler Authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.google.javascript.jscomp;
18
19 import com.google.javascript.jscomp.CheckLevel;
20
21 import java.io.PrintStream;
22
23 /**
24 * <p>An error manager that prints errors and warnings to the print stream
25 * provided in addition to the functionality of the
26 * {@link BasicErrorManager}.</p>
27 *
28 * <p>It collaborates with a {@link SourceExcerptProvider} via a
29 * {@link MessageFormatter} to display error messages with source context.</p>
30 *
31 */
32 public class PrintStreamErrorManager extends BasicErrorManager {
33 private final MessageFormatter formatter;
34 private final PrintStream stream;
35 private int summaryDetailLevel = 1;
36
37 /**
38 * Creates an error manager.
39 * @param formatter the message formatter used to format the messages
40 * @param stream the stream on which the errors and warnings should be
41 * printed. This class does not close the stream
42 */
43 public PrintStreamErrorManager(MessageFormatter formatter,
44 PrintStream stream) {
45 this.formatter = formatter;
46 this.stream = stream;
47 }
48
49 /**
50 * Creates an instance with a source-less error formatter.
51 */
52 public PrintStreamErrorManager(PrintStream stream) {
53 this(ErrorFormat.SOURCELESS.toFormatter(null, false), stream);
54 }
55
56 @Override
57 public void println(CheckLevel level, JSError error) {
58 stream.println(error.format(level, formatter));
59 }
60
61 public void setSummaryDetailLevel(int summaryDetailLevel) {
62 this.summaryDetailLevel = summaryDetailLevel;
63 }
64
65 @Override
66 public void printSummary() {
67 if (summaryDetailLevel >= 3 ||
68 (summaryDetailLevel >= 1 && getErrorCount() + getWarningCount() > 0) ||
69 (summaryDetailLevel >= 2 && getTypedPercent() > 0.0)) {
70 if (getTypedPercent() > 0.0) {
71 stream.format("%d error(s), %d warning(s), %.1f%% typed%n",
72 getErrorCount(), getWarningCount(), getTypedPercent());
73 } else {
74 stream.format("%d error(s), %d warning(s)%n", getErrorCount(),
75 getWarningCount());
76 }
77 }
78 }
79 }