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 { MemberInfo(String rawCommentText, String name, String signature, ClassInfo containingClass, ClassInfo realContainingClass, boolean isPublic, boolean isProtected, boolean isPackagePrivate, boolean isPrivate, boolean isFinal, boolean isStatic, boolean isSynthetic, String kind, SourcePositionInfo position, ArrayList<AnnotationInstanceInfo> annotations)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 mHideAnnotations = AnnotationInstanceInfo.getHideAnnotationsIntersection(annotations); 43 } 44 isExecutable()45 public abstract boolean isExecutable(); 46 47 @Override isHidden()48 public boolean isHidden() { 49 if (mShowAnnotations.size() > 0) { 50 return false; 51 } 52 return super.isHidden() || mHideAnnotations.size() > 0; 53 } 54 55 @Override isHiddenOrRemoved()56 public boolean isHiddenOrRemoved() { 57 return isHidden() || isRemoved(); 58 } 59 anchor()60 public String anchor() { 61 if (mSignature != null) { 62 return mName + mSignature; 63 } else { 64 return mName; 65 } 66 } 67 htmlPage()68 public String htmlPage() { 69 return mContainingClass.htmlPage() + "#" + anchor(); 70 } 71 compareTo(Object that)72 public int compareTo(Object that) { 73 return this.htmlPage().compareTo(((MemberInfo) that).htmlPage()); 74 } 75 name()76 public String name() { 77 return mName; 78 } 79 signature()80 public String signature() { 81 return mSignature; 82 } 83 realContainingClass()84 public ClassInfo realContainingClass() { 85 return mRealContainingClass; 86 } 87 containingClass()88 public ClassInfo containingClass() { 89 return mContainingClass; 90 } 91 isPublic()92 public boolean isPublic() { 93 return mIsPublic; 94 } 95 isProtected()96 public boolean isProtected() { 97 return mIsProtected; 98 } 99 isPackagePrivate()100 public boolean isPackagePrivate() { 101 return mIsPackagePrivate; 102 } 103 isPrivate()104 public boolean isPrivate() { 105 return mIsPrivate; 106 } 107 scope()108 public String scope() { 109 if (isPublic()) { 110 return "public"; 111 } else if (isProtected()) { 112 return "protected"; 113 } else if (isPackagePrivate()) { 114 return ""; 115 } else if (isPrivate()) { 116 return "private"; 117 } else { 118 throw new RuntimeException("invalid scope for object " + this); 119 } 120 } 121 isStatic()122 public boolean isStatic() { 123 return mIsStatic; 124 } 125 isFinal()126 public boolean isFinal() { 127 return mIsFinal; 128 } 129 isSynthetic()130 public boolean isSynthetic() { 131 return mIsSynthetic; 132 } 133 134 @Override parent()135 public ContainerInfo parent() { 136 return mContainingClass; 137 } 138 139 /** 140 * Returns {@code true} if the member's scope is above the minimum requested scope passed to 141 * Doclava. Provided that the {@code -showAnnotationOverridesVisibility} argument was passed to 142 * Doclava, this will <emph>also</emph> return {@code true} if the member is tagged with an 143 * annotation which was specified in a {@code -showAnnotation} argument to Doclava 144 */ checkLevel()145 public boolean checkLevel() { 146 if (Doclava.checkLevel(mIsPublic, mIsProtected, mIsPackagePrivate, mIsPrivate, 147 isHiddenOrRemoved())) { 148 return true; 149 } else if (Doclava.showAnnotationOverridesVisibility && 150 mShowAnnotations != null && !mShowAnnotations.isEmpty()) { 151 return true; 152 } 153 154 return false; 155 } 156 kind()157 public String kind() { 158 return mKind; 159 } 160 annotations()161 public ArrayList<AnnotationInstanceInfo> annotations() { 162 return mAnnotations; 163 } 164 hasShowAnnotation()165 public boolean hasShowAnnotation() { 166 return mShowAnnotations != null && mShowAnnotations.size() > 0; 167 } 168 showAnnotations()169 public ArrayList<AnnotationInstanceInfo> showAnnotations() { 170 return mShowAnnotations; 171 } 172 hideAnnotations()173 public ArrayList<AnnotationInstanceInfo> hideAnnotations() { 174 return mHideAnnotations; 175 } 176 177 ClassInfo mContainingClass; 178 ClassInfo mRealContainingClass; 179 String mName; 180 String mSignature; 181 boolean mIsPublic; 182 boolean mIsProtected; 183 boolean mIsPackagePrivate; 184 boolean mIsPrivate; 185 boolean mIsFinal; 186 boolean mIsStatic; 187 boolean mIsSynthetic; 188 String mKind; 189 private ArrayList<AnnotationInstanceInfo> mAnnotations; 190 private ArrayList<AnnotationInstanceInfo> mShowAnnotations; 191 private ArrayList<AnnotationInstanceInfo> mHideAnnotations; 192 193 } 194