1 /* 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 17 package com.google.doclava; 18 19 import java.util.ArrayList; 20 21 public 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, 26 ArrayList<AnnotationInstanceInfo> annotations) { 27 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; 41 mShowAnnotations = AnnotationInstanceInfo.getShowAnnotationsIntersection(annotations); 42 } 43 44 public abstract boolean isExecutable(); 45 46 @Override 47 public boolean isHidden() { 48 if (mShowAnnotations.size() > 0) { 49 return false; 50 } 51 return super.isHidden(); 52 } 53 54 @Override 55 public boolean isRemoved() { 56 if (mShowAnnotations.size() > 0) { 57 return false; 58 } 59 return super.isRemoved(); 60 } 61 62 @Override 63 public boolean isHiddenOrRemoved() { 64 return isHidden() || isRemoved(); 65 } 66 67 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 } 114 115 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 146 /** 147 * Returns {@code true} if the member's scope is above the minimum requested scope passed to 148 * Doclava. Provided that the {@code -showAnnotationOverridesVisibility} argument was passed to 149 * Doclava, this will <emph>also</emph> return {@code true} if the member is tagged with an 150 * annotation which was specified in a {@code -showAnnotation} argument to Doclava 151 */ 152 public boolean checkLevel() { 153 if (Doclava.checkLevel(mIsPublic, mIsProtected, mIsPackagePrivate, mIsPrivate, 154 isHiddenOrRemoved())) { 155 return true; 156 } else if (Doclava.showAnnotationOverridesVisibility && 157 mShowAnnotations != null && !mShowAnnotations.isEmpty()) { 158 return true; 159 } 160 161 return false; 162 } 163 164 public String kind() { 165 return mKind; 166 } 167 168 public ArrayList<AnnotationInstanceInfo> annotations() { 169 return mAnnotations; 170 } 171 172 public boolean hasShowAnnotation() { 173 return mShowAnnotations != null && mShowAnnotations.size() > 0; 174 } 175 176 public ArrayList<AnnotationInstanceInfo> showAnnotations() { 177 return mShowAnnotations; 178 } 179 180 ClassInfo mContainingClass; 181 ClassInfo mRealContainingClass; 182 String mName; 183 String mSignature; 184 boolean mIsPublic; 185 boolean mIsProtected; 186 boolean mIsPackagePrivate; 187 boolean mIsPrivate; 188 boolean mIsFinal; 189 boolean mIsStatic; 190 boolean mIsSynthetic; 191 String mKind; 192 private ArrayList<AnnotationInstanceInfo> mAnnotations; 193 private ArrayList<AnnotationInstanceInfo> mShowAnnotations; 194 195 } 196