1 /*
2  * Copyright (C) 2016-2018 The JavaParser Team.
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.github.javaparser.symbolsolver.resolution.naming;
18 
19 /**
20  * Context causes a name syntactically to fall into one of seven categories: ModuleName, PackageName, TypeName,
21  * ExpressionName, MethodName, PackageOrTypeName, or AmbiguousName.
22  * TypeName is less expressive than the other six categories, because it is denoted with TypeIdentifier, which excludes
23  * the character sequence var (§3.8).
24  *
25  * See JLS 6.5 (https://docs.oracle.com/javase/specs/jls/se10/html/jls-6.html#jls-6.5)
26  */
27 public enum NameCategory {
28     MODULE_NAME(false),
29     PACKAGE_NAME(false),
30     TYPE_NAME(false),
31     EXPRESSION_NAME(false),
32     METHOD_NAME(false),
33     PACKAGE_OR_TYPE_NAME(true),
34     AMBIGUOUS_NAME(true),
35     COMPILATION_ERROR(false);
36 
37     private boolean needDisambiguation;
38 
NameCategory(boolean needDisambiguation)39     NameCategory(boolean needDisambiguation) {
40         this.needDisambiguation = needDisambiguation;
41     }
42 
43     /**
44      * Certain category include two or more unambiguous categories.
45      * These ambiguous categories are recognized solely through a syntactic process. In order to disambiguate them
46      * a semantic process (i.e., consider the symbols which are actually visible in a given context) is needed.
47      */
isNeedingDisambiguation()48     public boolean isNeedingDisambiguation() {
49         return needDisambiguation;
50     }
51 
52     /**
53      * Is the given name acceptable for the given category?
54      */
isNameAcceptable(String name)55     public boolean isNameAcceptable(String name) {
56         return this != TYPE_NAME || !name.equals("var");
57     }
58 
isValid()59     public boolean isValid() {
60         return this != COMPILATION_ERROR;
61     }
62 
63 }
64