blob: da11360558747a2ecaf6b02113ba1b790bdd5198 [file] [log] [blame]
Ben Dodson920dbbb2010-08-04 15:21:06 -07001/*
2 * Copyright (C) 2010 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.google.doclava;
18
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070019import java.util.ArrayList;
20
Ben Dodson920dbbb2010-08-04 15:21:06 -070021public abstract class MemberInfo extends DocInfo implements Comparable, Scoped {
22 public MemberInfo(String rawCommentText, String name, String signature,
23 ClassInfo containingClass, ClassInfo realContainingClass, boolean isPublic,
24 boolean isProtected, boolean isPackagePrivate, boolean isPrivate, boolean isFinal,
25 boolean isStatic, boolean isSynthetic, String kind, SourcePositionInfo position,
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070026 ArrayList<AnnotationInstanceInfo> annotations) {
Ben Dodson920dbbb2010-08-04 15:21:06 -070027 super(rawCommentText, position);
28 mName = name;
29 mSignature = signature;
30 mContainingClass = containingClass;
31 mRealContainingClass = realContainingClass;
32 mIsPublic = isPublic;
33 mIsProtected = isProtected;
34 mIsPackagePrivate = isPackagePrivate;
35 mIsPrivate = isPrivate;
36 mIsFinal = isFinal;
37 mIsStatic = isStatic;
38 mIsSynthetic = isSynthetic;
39 mKind = kind;
40 mAnnotations = annotations;
Jeff Arneson051dace2014-08-12 15:22:00 -070041 mShowAnnotations = AnnotationInstanceInfo.getShowAnnotationsIntersection(annotations);
Ben Dodson920dbbb2010-08-04 15:21:06 -070042 }
43
44 public abstract boolean isExecutable();
45
Jeff Hamiltonca151a92012-11-12 17:11:27 -060046 @Override
47 public boolean isHidden() {
Jeff Arneson051dace2014-08-12 15:22:00 -070048 if (mShowAnnotations.size() > 0) {
49 return false;
Jeff Hamiltonca151a92012-11-12 17:11:27 -060050 }
51 return super.isHidden();
52 }
53
Hui Shu5118ffe2014-02-18 14:06:42 -080054 @Override
55 public boolean isRemoved() {
Jeff Arneson051dace2014-08-12 15:22:00 -070056 if (mShowAnnotations.size() > 0) {
57 return false;
Hui Shu5118ffe2014-02-18 14:06:42 -080058 }
59 return super.isRemoved();
60 }
61
62 @Override
63 public boolean isHiddenOrRemoved() {
64 return isHidden() || isRemoved();
65 }
66
Ben Dodson920dbbb2010-08-04 15:21:06 -070067 public String anchor() {
68 if (mSignature != null) {
69 return mName + mSignature;
70 } else {
71 return mName;
72 }
73 }
74
75 public String htmlPage() {
76 return mContainingClass.htmlPage() + "#" + anchor();
77 }
78
79 public int compareTo(Object that) {
80 return this.htmlPage().compareTo(((MemberInfo) that).htmlPage());
81 }
82
83 public String name() {
84 return mName;
85 }
86
87 public String signature() {
88 return mSignature;
89 }
90
91 public ClassInfo realContainingClass() {
92 return mRealContainingClass;
93 }
94
95 public ClassInfo containingClass() {
96 return mContainingClass;
97 }
98
99 public boolean isPublic() {
100 return mIsPublic;
101 }
102
103 public boolean isProtected() {
104 return mIsProtected;
105 }
106
107 public boolean isPackagePrivate() {
108 return mIsPackagePrivate;
109 }
110
111 public boolean isPrivate() {
112 return mIsPrivate;
113 }
Hui Shu5118ffe2014-02-18 14:06:42 -0800114
Ben Dodson920dbbb2010-08-04 15:21:06 -0700115 public String scope() {
116 if (isPublic()) {
117 return "public";
118 } else if (isProtected()) {
119 return "protected";
120 } else if (isPackagePrivate()) {
121 return "";
122 } else if (isPrivate()) {
123 return "private";
124 } else {
125 throw new RuntimeException("invalid scope for object " + this);
126 }
127 }
128
129 public boolean isStatic() {
130 return mIsStatic;
131 }
132
133 public boolean isFinal() {
134 return mIsFinal;
135 }
136
137 public boolean isSynthetic() {
138 return mIsSynthetic;
139 }
140
141 @Override
142 public ContainerInfo parent() {
143 return mContainingClass;
144 }
145
Omari Stephens274a19e2015-06-04 21:29:09 -0700146 /**
147 * Returns {@code true} if the member's scope is above the minimum requested scope passed to
148 * Doclava, <emph>or</emph> if the member is tagged with an annotation which was specified in a
149 * "-showAnnotation" argument to Doclava
150 */
Ben Dodson920dbbb2010-08-04 15:21:06 -0700151 public boolean checkLevel() {
Omari Stephens274a19e2015-06-04 21:29:09 -0700152 if (Doclava.checkLevel(mIsPublic, mIsProtected, mIsPackagePrivate, mIsPrivate,
153 isHiddenOrRemoved())) {
154 return true;
155 } else if (mShowAnnotations != null && !mShowAnnotations.isEmpty()) {
156 return true;
157 }
158
159 return false;
Ben Dodson920dbbb2010-08-04 15:21:06 -0700160 }
161
162 public String kind() {
163 return mKind;
164 }
165
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -0700166 public ArrayList<AnnotationInstanceInfo> annotations() {
Ben Dodson920dbbb2010-08-04 15:21:06 -0700167 return mAnnotations;
168 }
169
Jeff Arneson051dace2014-08-12 15:22:00 -0700170 public ArrayList<AnnotationInstanceInfo> showAnnotations() {
171 return mShowAnnotations;
172 }
173
Ben Dodson920dbbb2010-08-04 15:21:06 -0700174 ClassInfo mContainingClass;
175 ClassInfo mRealContainingClass;
176 String mName;
177 String mSignature;
178 boolean mIsPublic;
179 boolean mIsProtected;
180 boolean mIsPackagePrivate;
181 boolean mIsPrivate;
182 boolean mIsFinal;
183 boolean mIsStatic;
184 boolean mIsSynthetic;
185 String mKind;
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -0700186 private ArrayList<AnnotationInstanceInfo> mAnnotations;
Jeff Arneson051dace2014-08-12 15:22:00 -0700187 private ArrayList<AnnotationInstanceInfo> mShowAnnotations;
Ben Dodson920dbbb2010-08-04 15:21:06 -0700188
189}