Debian Codegraph @

src/com/google/javascript/jscomp/parsing/Config.java

raw symbols SCIP
1 /*
2 * Copyright 2009 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.parsing;
18
19 import com.google.common.collect.ImmutableMap;
20
21 import java.util.Map;
22 import java.util.Set;
23
24 /**
25 * Configuration for the AST factory. Should be shared across AST creation
26 * for all files of a compilation process.
27 *
28 * @author [email protected] (Nick Santos)
29 */
30 public class Config {
31
32 public enum LanguageMode {
33 ECMASCRIPT3,
34 ECMASCRIPT5,
35 ECMASCRIPT5_STRICT,
36 }
37
38 /**
39 * Whether to parse the descriptions of JsDoc comments.
40 */
41 final boolean parseJsDocDocumentation;
42
43 /**
44 * Whether we're in IDE mode.
45 */
46 final boolean isIdeMode;
47
48 /**
49 * Recognized JSDoc annotations, mapped from their name to their internal
50 * representation.
51 */
52 final Map<String, Annotation> annotationNames;
53
54 /**
55 * Recognized names in a {@code @suppress} tag.
56 */
57 final Set<String> suppressionNames;
58
59 /**
60 * Accept ECMAScript5 syntax, such as getter/setter.
61 */
62 final LanguageMode languageMode;
63
64 /**
65 * Accept `const' keyword.
66 */
67 final boolean acceptConstKeyword;
68
69 /**
70 * Annotation names.
71 */
72
73 Config(Set<String> annotationWhitelist, Set<String> suppressionNames,
74 boolean isIdeMode, LanguageMode languageMode,
75 boolean acceptConstKeyword) {
76 this.annotationNames = buildAnnotationNames(annotationWhitelist);
77 this.parseJsDocDocumentation = isIdeMode;
78 this.suppressionNames = suppressionNames;
79 this.isIdeMode = isIdeMode;
80 this.languageMode = languageMode;
81 this.acceptConstKeyword = acceptConstKeyword;
82 }
83
84 /**
85 * Create the annotation names from the user-specified
86 * annotation whitelist.
87 */
88 private static Map<String, Annotation> buildAnnotationNames(
89 Set<String> annotationWhitelist) {
90 ImmutableMap.Builder<String, Annotation> annotationBuilder =
91 ImmutableMap.builder();
92 annotationBuilder.putAll(Annotation.recognizedAnnotations);
93 for (String unrecognizedAnnotation : annotationWhitelist) {
94 if (!Annotation.recognizedAnnotations.containsKey(
95 unrecognizedAnnotation)) {
96 annotationBuilder.put(
97 unrecognizedAnnotation, Annotation.NOT_IMPLEMENTED);
98 }
99 }
100 return annotationBuilder.build();
101 }
102 }