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 } 43 isExecutable()44 public abstract boolean isExecutable(); 45 46 @Override isHidden()47 public boolean isHidden() { 48 if (mShowAnnotations.size() > 0) { 49 return false; 50 } 51 return super.isHidden(); 52 } 53 54 @Override isRemoved()55 public boolean isRemoved() { 56 if (mShowAnnotations.size() > 0) { 57 return false; 58 } 59 return super.isRemoved(); 60 } 61 62 @Override isHiddenOrRemoved()63 public boolean isHiddenOrRemoved() { 64 return isHidden() || isRemoved(); 65 } 66 anchor()67 public String anchor() { 68 if (mSignature != null) { 69 return mName + mSignature; 70 } else { 71 return mName; 72 } 73 } 74 htmlPage()75 public String htmlPage() { 76 return mContainingClass.htmlPage() + "#" + anchor(); 77 } 78 compareTo(Object that)79 public int compareTo(Object that) { 80 return this.htmlPage().compareTo(((MemberInfo) that).htmlPage()); 81 } 82 name()83 public String name() { 84 return mName; 85 } 86 signature()87 public String signature() { 88 return mSignature; 89 } 90 realContainingClass()91 public ClassInfo realContainingClass() { 92 return mRealContainingClass; 93 } 94 containingClass()95 public ClassInfo containingClass() { 96 return mContainingClass; 97 } 98 isPublic()99 public boolean isPublic() { 100 return mIsPublic; 101 } 102 isProtected()103 public boolean isProtected() { 104 return mIsProtected; 105 } 106 isPackagePrivate()107 public boolean isPackagePrivate() { 108 return mIsPackagePrivate; 109 } 110 isPrivate()111 public boolean isPrivate() { 112 return mIsPrivate; 113 } 114 scope()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 isStatic()129 public boolean isStatic() { 130 return mIsStatic; 131 } 132 isFinal()133 public boolean isFinal() { 134 return mIsFinal; 135 } 136 isSynthetic()137 public boolean isSynthetic() { 138 return mIsSynthetic; 139 } 140 141 @Override parent()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 */ checkLevel()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 kind()164 public String kind() { 165 return mKind; 166 } 167 annotations()168 public ArrayList<AnnotationInstanceInfo> annotations() { 169 return mAnnotations; 170 } 171 showAnnotations()172 public ArrayList<AnnotationInstanceInfo> showAnnotations() { 173 return mShowAnnotations; 174 } 175 176 ClassInfo mContainingClass; 177 ClassInfo mRealContainingClass; 178 String mName; 179 String mSignature; 180 boolean mIsPublic; 181 boolean mIsProtected; 182 boolean mIsPackagePrivate; 183 boolean mIsPrivate; 184 boolean mIsFinal; 185 boolean mIsStatic; 186 boolean mIsSynthetic; 187 String mKind; 188 private ArrayList<AnnotationInstanceInfo> mAnnotations; 189 private ArrayList<AnnotationInstanceInfo> mShowAnnotations; 190 191 } 192