1 package org.apache.maven.jxr.pacman;
2
3 /*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22 import java.nio.file.Path;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.HashSet;
26 import java.util.List;
27 import java.util.Set;
28
29 /**
30 * Interface for objects which wish to provide meta-info about a JavaFile.
31 *
32 * @author <a href="mailto:burton@apache.org">Kevin A. Burton</a>
33 * @version $Id$
34 */
35 public abstract class JavaFile
36 {
37 private Set<ImportType> imports = new HashSet<>();
38
39 private List<ClassType> classTypes = new ArrayList<>();
40
41 private PackageTypeType.html#PackageType">PackageType packageType = new PackageType();
42
43 private final Path path;
44
45 private final String encoding;
46
47 protected JavaFile( Path path, String encoding )
48 {
49 this.path = path;
50 this.encoding = encoding;
51 }
52
53 /**
54 * Get the imported packages/files that this package has.
55 */
56 public Set<ImportType> getImportTypes()
57 {
58 return Collections.unmodifiableSet( imports );
59 }
60
61 /**
62 * Get the name of this class.
63 */
64 public ClassType getClassType()
65 {
66 if ( classTypes.isEmpty() )
67 {
68 return null;
69 }
70 else
71 {
72 // To retain backward compatibility, return the first class
73 return this.classTypes.get( 0 );
74 }
75 }
76
77 /**
78 * Get the names of the classes in this file.
79 */
80 public List<ClassType> getClassTypes()
81 {
82 return this.classTypes;
83 }
84
85 /**
86 * Get the package of this class.
87 */
88 public PackageType getPackageType()
89 {
90 return this.packageType;
91 }
92
93
94 /**
95 * Add a ClassType to the current list of class types.
96 */
97 public void addClassType( ClassType classType )
98 {
99 this.classTypes.add( classType );
100 }
101
102 /**
103 * Add an ImportType to the current imports.
104 */
105 public void addImportType( ImportType importType )
106 {
107 this.imports.add( importType );
108 }
109
110 /**
111 * Set the name of this class.
112 */
113 public void setClassType( ClassType classType )
114 {
115 // To retain backward compatibility, make sure the list contains only the supplied classType
116 this.classTypes.clear();
117 this.classTypes.add( classType );
118 }
119
120 /**
121 * Set the PackageType of this class.
122 */
123 public void setPackageType( PackageType packageType )
124 {
125 this.packageType = packageType;
126 }
127
128
129 /**
130 * Gets the filename attribute of the JavaFile object
131 */
132 public Path getPath()
133 {
134 return this.path;
135 }
136
137 /**
138 * Gets the encoding attribute of the JavaFile object
139 */
140 public String getEncoding()
141 {
142 return this.encoding;
143 }
144 }