View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.myfaces.tobago.apt.generate;
21  
22  import java.util.HashSet;
23  import java.util.Set;
24  
25  
26  public class ClassInfo {
27    private String className;
28    private String packageName;
29    private Imports imports;
30    private String superClassName;
31    private Set<String> interfaces = new HashSet<>();
32    private String sourceClass;
33  
34    public ClassInfo(final String sourceClass, final String qualifiedName) {
35      this.sourceClass = sourceClass;
36      this.className = ClassUtils.getSimpleName(qualifiedName);
37      this.packageName = ClassUtils.getPackageName(qualifiedName);
38      imports = new Imports(packageName);
39    }
40  
41    public String getClassName() {
42      return className;
43    }
44  
45    public String getPackageName() {
46      return packageName;
47    }
48  
49    public void setSuperClass(final String qualifiedName) {
50      final String name = ClassUtils.getSimpleName(qualifiedName);
51      if (!name.equals(className)) {
52        imports.addImport(qualifiedName);
53        this.superClassName = name;
54      } else {
55        this.superClassName = qualifiedName;
56      }
57    }
58  
59    public String getSuperClassName() {
60      return superClassName;
61    }
62  
63    public boolean hasSuperClass() {
64      return superClassName != null && superClassName.length() > 0;
65    }
66  
67    public void addImport(final String qualifiedName) {
68      imports.addImport(qualifiedName);
69    }
70  
71    public Set<String> getImports() {
72      return imports.getImports();
73    }
74  
75    public void addInterface(final String qualifiedName) {
76      final String name = ClassUtils.getSimpleName(qualifiedName);
77      if (!name.equals(className)) {
78        imports.addImport(qualifiedName);
79        this.interfaces.add(name);
80      } else {
81        this.interfaces.add(qualifiedName);
82      }
83    }
84  
85    public Set<String> getInterfaces() {
86      return interfaces;
87    }
88  
89    public String getSourceClass() {
90      return sourceClass;
91    }
92  }