1 package org.apache.maven.tools.plugin.javadoc;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Objects;
23 import java.util.Optional;
24
25
26
27
28
29
30
31
32
33 public class FullyQualifiedJavadocReference
34 extends JavadocReference
35 {
36
37
38 private final boolean isExternal;
39
40 private final Optional<String> packageName;
41
42 private final Optional<MemberType> memberType;
43
44
45 public enum MemberType
46 {
47 FIELD, METHOD, CONSTRUCTOR
48 }
49
50 public FullyQualifiedJavadocReference( String packageName, boolean isExternal )
51 {
52 this( packageName, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), isExternal );
53 }
54
55 public FullyQualifiedJavadocReference( String packageName, Optional<String> label, boolean isExternal )
56 {
57 this( packageName, Optional.empty(), Optional.empty(), Optional.empty(), label, isExternal );
58 }
59
60 public FullyQualifiedJavadocReference( String packageName, String className, boolean isExternal )
61 {
62 this( packageName, Optional.of( className ), Optional.empty(), Optional.empty(), Optional.empty(),
63 isExternal );
64 }
65
66 public FullyQualifiedJavadocReference( String packageName, String className, String member, MemberType memberType,
67 boolean isExternal )
68 {
69 this( packageName, Optional.of( className ), Optional.of( member ), Optional.of( memberType ),
70 Optional.empty(), isExternal );
71 }
72
73 public FullyQualifiedJavadocReference( String packageName, Optional<String> className, Optional<String> member,
74 Optional<MemberType> memberType, Optional<String> label, boolean isExternal )
75 {
76 this( Optional.empty(), Optional.of( packageName ), className, member, memberType, label, isExternal );
77 }
78
79 public FullyQualifiedJavadocReference( Optional<String> moduleName, Optional<String> packageName,
80 Optional<String> className, Optional<String> member,
81 Optional<MemberType> memberType, Optional<String> label,
82 boolean isExternal )
83 {
84 super( moduleName, className, member, label );
85 this.packageName = packageName;
86 this.isExternal = isExternal;
87 if ( !moduleName.isPresent() && !packageName.isPresent() )
88 {
89 throw new IllegalArgumentException( "At least one of module name or package name needs to be set" );
90 }
91 if ( member.isPresent() )
92 {
93 if ( !memberType.isPresent() )
94 {
95 throw new IllegalArgumentException( "When member is set, also the member type needs to be set" );
96 }
97 if ( member.get().matches( ".*\\s.*" ) )
98 {
99 throw new IllegalArgumentException( "member must not contain any whitespace characters!" );
100 }
101 }
102 this.memberType = memberType;
103 }
104
105
106
107
108
109 public boolean isExternal()
110 {
111 return isExternal;
112 }
113
114
115 public Optional<String> getPackageName()
116 {
117 return packageName;
118 }
119
120
121
122
123
124 public Optional<String> getClassName()
125 {
126 return getPackageNameClassName();
127 }
128
129
130 public Optional<MemberType> getMemberType()
131 {
132 return memberType;
133 }
134
135 public Optional<String> getFullyQualifiedClassName()
136 {
137 if ( getClassName().isPresent() && getPackageName().isPresent() )
138 {
139 return Optional.of( getPackageName().get() + "." + getClassName().get() );
140 }
141 else
142 {
143 return Optional.empty();
144 }
145 }
146
147 @Override
148 public String toString()
149 {
150 return "FullyQualifiedJavadocReference [moduleName=" + getModuleName() + ", packageName=" + packageName
151 + ", className=" + getClassName() + ", memberType=" + memberType + ", member=" + getMember() + ", label="
152 + getLabel() + ", isExternal=" + isExternal + "]";
153 }
154
155 @Override
156 public int hashCode()
157 {
158 final int prime = 31;
159 int result = super.hashCode();
160 result = prime * result + Objects.hash( memberType, packageName, isExternal );
161 return result;
162 }
163
164 @Override
165 public boolean equals( Object obj )
166 {
167 if ( this == obj )
168 {
169 return true;
170 }
171 if ( !super.equals( obj ) )
172 {
173 return false;
174 }
175 if ( getClass() != obj.getClass() )
176 {
177 return false;
178 }
179 FullyQualifiedJavadocReference other = (FullyQualifiedJavadocReference) obj;
180 return Objects.equals( memberType, other.memberType ) && Objects.equals( packageName, other.packageName )
181 && isExternal == other.isExternal;
182 }
183
184 }