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.lethe.analysis;
18  
19  import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * A series of comment lines.
26   */
27  public class ThemisAnalysisComment
28          implements ThemisAnalysisProcessed {
29      /**
30       * Is this a javaDoc comment?
31       */
32      private final boolean isJavaDoc;
33  
34      /**
35       * The commentLines.
36       */
37      private final List<ThemisAnalysisLine> theComments;
38  
39      /**
40       * Constructor.
41       *
42       * @param pParser the parser
43       * @param pLine   the initial comment line
44       * @throws OceanusException on error
45       */
46      ThemisAnalysisComment(final ThemisAnalysisParser pParser,
47                            final ThemisAnalysisLine pLine) throws OceanusException {
48          /* Create the list of comment lines */
49          theComments = new ArrayList<>();
50          theComments.add(pLine);
51  
52          /* Determine whether this is a javaDoc comment */
53          isJavaDoc = isJavaDocComment(pLine);
54  
55          /* If this is not a complete comment */
56          ThemisAnalysisLine myLine = pLine;
57          while (!isEndComment(myLine)) {
58              /* Pop next line and add it */
59              myLine = (ThemisAnalysisLine) pParser.popNextLine();
60              theComments.add(myLine);
61          }
62      }
63  
64      @Override
65      public int getNumLines() {
66          return theComments.size();
67      }
68  
69      /**
70       * Is this a javaDoc comment.
71       *
72       * @return true/false
73       */
74      public boolean isJavaDoc() {
75          return isJavaDoc;
76      }
77  
78      /**
79       * Is the line a starting comment?
80       *
81       * @param pLine the line
82       * @return true/false
83       */
84      static boolean isStartComment(final ThemisAnalysisLine pLine) {
85          return pLine.startsWithSequence("/*");
86      }
87  
88      /**
89       * Is the line a javaDoc comment?
90       *
91       * @param pLine the line
92       * @return true/false
93       */
94      private static boolean isJavaDocComment(final ThemisAnalysisLine pLine) {
95          return pLine.startsWithSequence("/**");
96      }
97  
98      /**
99       * Is the line an ending comment?
100      *
101      * @param pLine the line
102      * @return true/false
103      */
104     private static boolean isEndComment(final ThemisAnalysisLine pLine) {
105         return pLine.endsWithSequence("*/");
106     }
107 }