Debian Codegraph @

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

raw symbols SCIP
1 /*
2 * Copyright 2008 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.common.base.Preconditions;
20 import com.google.common.collect.Lists;
21
22 import java.util.List;
23
24 /**
25 * Control whether warnings should be restricted or suppressed for specified
26 * paths.
27 *
28 * @author [email protected] (Anatol Pomazau)
29 */
30 public class ShowByPathWarningsGuard extends WarningsGuard {
31 private static final long serialVersionUID = 1L;
32
33 /**
34 * Controls whether warnings should be restricted to a specified path or
35 * suppressed within the specified path.
36 */
37 public enum ShowType {
38 INCLUDE, // Suppress warnings outside the path.
39 EXCLUDE; // Suppress warnings within the path.
40 }
41
42 private final ByPathWarningsGuard warningsGuard;
43
44 public ShowByPathWarningsGuard(String checkWarningsOnlyForPath) {
45 this(checkWarningsOnlyForPath, ShowType.INCLUDE);
46 }
47
48 public ShowByPathWarningsGuard(String[] checkWarningsOnlyForPath) {
49 this(checkWarningsOnlyForPath, ShowType.INCLUDE);
50 }
51
52 public ShowByPathWarningsGuard(String path, ShowType showType) {
53 this(new String[] { path }, showType);
54 }
55
56 public ShowByPathWarningsGuard(String[] paths, ShowType showType) {
57 Preconditions.checkArgument(paths != null);
58 Preconditions.checkArgument(showType != null);
59 List<String> pathList = Lists.newArrayList(paths);
60 if (showType == ShowType.INCLUDE) {
61 warningsGuard = ByPathWarningsGuard.exceptPath(pathList, CheckLevel.OFF);
62 } else {
63 warningsGuard = ByPathWarningsGuard.forPath(pathList, CheckLevel.OFF);
64 }
65 }
66
67 @Override
68 public CheckLevel level(JSError error) {
69 return warningsGuard.level(error);
70 }
71
72 @Override
73 protected int getPriority() {
74 return warningsGuard.getPriority();
75 }
76 }