1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package io.github.tonywasher.joceanus.themis.xanalysis.parser.node;
18
19 import com.github.javaparser.ast.CompilationUnit;
20 import com.github.javaparser.ast.NodeList;
21 import com.github.javaparser.ast.body.TypeDeclaration;
22 import io.github.tonywasher.joceanus.oceanus.base.OceanusException;
23 import io.github.tonywasher.joceanus.themis.xanalysis.parser.base.ThemisXAnalysisParserDef;
24
25 import java.util.List;
26
27
28
29
30 public class ThemisXAnalysisNodeCompilationUnit
31 extends ThemisXAnalysisBaseNode<CompilationUnit> {
32
33
34
35 private final ThemisXAnalysisNodeInstance thePackageDef;
36
37
38
39
40 private final List<ThemisXAnalysisNodeInstance> theImports;
41
42
43
44
45 private final ThemisXAnalysisClassInstance theContents;
46
47
48
49
50
51
52
53
54 ThemisXAnalysisNodeCompilationUnit(final ThemisXAnalysisParserDef pParser,
55 final CompilationUnit pUnit) throws OceanusException {
56 super(pParser, pUnit);
57 thePackageDef = pParser.parseNode(pUnit.getPackageDeclaration().orElse(null));
58 theImports = pParser.parseNodeList(pUnit.getImports());
59 final NodeList<TypeDeclaration<?>> myTypes = pUnit.getTypes();
60 if (myTypes.size() > 1) {
61 throw pParser.buildException("More than one class definition in file", pUnit);
62 }
63 if (myTypes.isEmpty()) {
64 throw pParser.buildException("No class definition found in file", pUnit);
65 }
66 theContents = (ThemisXAnalysisClassInstance) pParser.parseDeclaration(pUnit.getType(0));
67 }
68
69
70
71
72
73
74 public ThemisXAnalysisNodeInstance getPackage() {
75 return thePackageDef;
76 }
77
78
79
80
81
82
83 public List<ThemisXAnalysisNodeInstance> getImports() {
84 return theImports;
85 }
86
87
88
89
90
91
92 public ThemisXAnalysisClassInstance getContents() {
93 return theContents;
94 }
95 }