View Javadoc
1   /*
2    * Themis: Java Project Framework
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.themis.xanalysis.parser.node;
18  
19  import com.github.javaparser.ast.Modifier.Keyword;
20  import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisModifierList;
21  import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisInstance.ThemisXAnalysisNodeInstance;
22  
23  import java.util.List;
24  
25  /**
26   * Modifier List.
27   */
28  public class ThemisXAnalysisNodeModifierList
29          implements ThemisXAnalysisModifierList {
30      /**
31       * The Modifier list.
32       */
33      private final List<ThemisXAnalysisNodeInstance> theModifiers;
34  
35      /**
36       * Constructor.
37       */
38      public ThemisXAnalysisNodeModifierList() {
39          this(null);
40      }
41  
42      /**
43       * Constructor.
44       *
45       * @param pModifiers the Modifiers.
46       */
47      public ThemisXAnalysisNodeModifierList(final List<ThemisXAnalysisNodeInstance> pModifiers) {
48          theModifiers = pModifiers;
49      }
50  
51      @Override
52      public boolean isPublic() {
53          return isPresent(Keyword.PUBLIC);
54      }
55  
56      @Override
57      public boolean isProtected() {
58          return isPresent(Keyword.PROTECTED);
59      }
60  
61      @Override
62      public boolean isPrivate() {
63          return isPresent(Keyword.PRIVATE);
64      }
65  
66      @Override
67      public boolean isStatic() {
68          return isPresent(Keyword.STATIC);
69      }
70  
71      @Override
72      public boolean isFinal() {
73          return isPresent(Keyword.FINAL);
74      }
75  
76      @Override
77      public boolean isSynchronized() {
78          return isPresent(Keyword.SYNCHRONIZED);
79      }
80  
81      @Override
82      public boolean isVolatile() {
83          return isPresent(Keyword.VOLATILE);
84      }
85  
86      @Override
87      public boolean isTransient() {
88          return isPresent(Keyword.TRANSIENT);
89      }
90  
91      @Override
92      public boolean isTransitive() {
93          return isPresent(Keyword.TRANSITIVE);
94      }
95  
96      @Override
97      public boolean isNative() {
98          return isPresent(Keyword.NATIVE);
99      }
100 
101     @Override
102     public boolean isAbstract() {
103         return isPresent(Keyword.ABSTRACT);
104     }
105 
106     @Override
107     public boolean isSealed() {
108         return isPresent(Keyword.SEALED);
109     }
110 
111     /**
112      * Look for keyword in modifiers.
113      *
114      * @param pKeyword the keyword
115      * @return true/false if present
116      */
117     private boolean isPresent(final Keyword pKeyword) {
118         return theModifiers.stream().map(x -> (ThemisXAnalysisNodeModifier) x)
119                 .map(ThemisXAnalysisNodeModifier::getKeyword).anyMatch(pKeyword::equals);
120     }
121 }