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 com.google.clearsilver.jsilver.data.Data; 20 21 import java.util.ArrayList; 22 import java.util.LinkedHashSet; 23 import java.util.Set; 24 25 public abstract class DocInfo { DocInfo(String rawCommentText, SourcePositionInfo sp)26 public DocInfo(String rawCommentText, SourcePositionInfo sp) { 27 mRawCommentText = rawCommentText; 28 mPosition = sp; 29 } 30 31 /** 32 * The relative path to a web page representing this item. 33 */ htmlPage()34 public abstract String htmlPage(); 35 36 /** 37 * @return true if the element has never been a part of public API 38 */ isHidden()39 public boolean isHidden() { 40 return comment().isHidden(); 41 } 42 43 /** 44 * @return true if the element was once a part of public API, now removed. 45 */ isRemoved()46 public boolean isRemoved() { 47 return comment().isRemoved(); 48 } 49 50 /** 51 * Hidden and removed elements should not be appear in api.txt files, nor 52 * should they appear in the java doc. 53 * @return true if the element is either hidden or removed. 54 */ isHiddenOrRemoved()55 public boolean isHiddenOrRemoved() { 56 return isHidden() || isRemoved(); 57 } 58 isDocOnly()59 public boolean isDocOnly() { 60 return comment().isDocOnly(); 61 } 62 getRawCommentText()63 public String getRawCommentText() { 64 return mRawCommentText; 65 } 66 setRawCommentText(String rawCommentText)67 public void setRawCommentText(String rawCommentText) { 68 mRawCommentText = rawCommentText; 69 70 // so that if we've created one prior to changing, we recreate it 71 if (mComment != null) { 72 mComment = new Comment(mRawCommentText, parent(), mPosition); 73 } 74 75 } 76 comment()77 public Comment comment() { 78 if (mComment == null) { 79 mComment = new Comment(mRawCommentText, parent(), mPosition); 80 } 81 return mComment; 82 } 83 position()84 public SourcePositionInfo position() { 85 return mPosition; 86 } 87 setPosition(SourcePositionInfo position)88 public void setPosition(SourcePositionInfo position) { 89 mPosition = position; 90 91 // so that if we've created one prior to changing, we recreate it 92 if (mComment != null) { 93 mComment = new Comment(mRawCommentText, parent(), mPosition); 94 } 95 } 96 parent()97 public abstract ContainerInfo parent(); 98 setSince(String since)99 public void setSince(String since) { 100 mSince = since; 101 } 102 getSince()103 public String getSince() { 104 if (Doclava.METALAVA_API_SINCE) { 105 mSince = comment().getApiSince(); 106 } 107 return mSince; 108 } 109 setSdkExtSince(String sdkextsince)110 public void setSdkExtSince(String sdkextsince) { 111 mSdkExtSince = sdkextsince; 112 } 113 getSdkExtSince()114 public String getSdkExtSince() { 115 if (Doclava.METALAVA_API_SINCE) { 116 mSdkExtSince = comment().getSdkExtSince(); 117 } 118 return mSdkExtSince; 119 } 120 121 /** 122 * Sets the artifact in which the class resides. 123 * <p> 124 * This property should be specified as a full Maven dependency spec. For example, a Support 125 * Library core utility class may use "com.android.support:support-core-utils:26.0.1". 126 * 127 * @param artifact the artifact in which the class resides 128 * @return 129 */ setArtifact(String artifact)130 public void setArtifact(String artifact) { 131 mArtifact = artifact; 132 } 133 134 /** 135 * Returns the artifact in which the class resides. 136 */ getArtifact()137 public String getArtifact() { 138 return mArtifact; 139 } 140 setDeprecatedSince(String since)141 public void setDeprecatedSince(String since) { 142 mDeprecatedSince = since; 143 } 144 getDeprecatedSince()145 public String getDeprecatedSince() { 146 if (Doclava.METALAVA_API_SINCE) { 147 return comment().getDeprecatedSince(); 148 } else { 149 return mDeprecatedSince; 150 } 151 } 152 isDeprecated()153 public boolean isDeprecated() { 154 if (Doclava.METALAVA_API_SINCE) { 155 return comment().isDeprecated(); 156 } else { 157 return mDeprecatedSince != null ? true : false; 158 } 159 } 160 addFederatedReference(FederatedSite source)161 public final void addFederatedReference(FederatedSite source) { 162 mFederatedReferences.add(source); 163 } 164 getFederatedReferences()165 public final Set<FederatedSite> getFederatedReferences() { 166 return mFederatedReferences; 167 } 168 setFederatedReferences(Data data, String base)169 public final void setFederatedReferences(Data data, String base) { 170 int pos = 0; 171 for (FederatedSite source : getFederatedReferences()) { 172 data.setValue(base + ".federated." + pos + ".url", source.linkFor(htmlPage())); 173 data.setValue(base + ".federated." + pos + ".name", source.name()); 174 pos++; 175 } 176 } 177 178 private String mRawCommentText; 179 Comment mComment; 180 SourcePositionInfo mPosition; 181 private String mSince; 182 private String mSdkExtSince; 183 private String mArtifact; 184 private String mDeprecatedSince; 185 private Set<FederatedSite> mFederatedReferences = new LinkedHashSet<FederatedSite>(); 186 } 187