Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 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 | |
Andrew Sapperstein | 6ba612e | 2011-06-20 18:41:24 -0700 | [diff] [blame] | 21 | import java.util.ArrayList; |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 22 | import java.util.LinkedHashSet; |
| 23 | import java.util.Set; |
| 24 | |
Andrew Sapperstein | 6ba612e | 2011-06-20 18:41:24 -0700 | [diff] [blame] | 25 | public abstract class DocInfo { |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 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 | */ |
| 34 | public abstract String htmlPage(); |
Hui Shu | 5118ffe | 2014-02-18 14:06:42 -0800 | [diff] [blame] | 35 | |
| 36 | /** |
| 37 | * @return true if the element has never been a part of public API |
| 38 | */ |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 39 | public boolean isHidden() { |
| 40 | return comment().isHidden(); |
| 41 | } |
| 42 | |
Hui Shu | 5118ffe | 2014-02-18 14:06:42 -0800 | [diff] [blame] | 43 | /** |
| 44 | * @return true if the element was once a part of public API, now removed. |
| 45 | */ |
| 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 | */ |
| 55 | public boolean isHiddenOrRemoved() { |
| 56 | return isHidden() || isRemoved(); |
| 57 | } |
| 58 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 59 | public boolean isDocOnly() { |
| 60 | return comment().isDocOnly(); |
| 61 | } |
| 62 | |
| 63 | public String getRawCommentText() { |
| 64 | return mRawCommentText; |
| 65 | } |
| 66 | |
Andrew Sapperstein | d6eaacb | 2011-05-20 13:14:56 -0700 | [diff] [blame] | 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 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 77 | public Comment comment() { |
| 78 | if (mComment == null) { |
| 79 | mComment = new Comment(mRawCommentText, parent(), mPosition); |
| 80 | } |
| 81 | return mComment; |
| 82 | } |
| 83 | |
| 84 | public SourcePositionInfo position() { |
| 85 | return mPosition; |
| 86 | } |
| 87 | |
Andrew Sapperstein | d6eaacb | 2011-05-20 13:14:56 -0700 | [diff] [blame] | 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 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 97 | public abstract ContainerInfo parent(); |
| 98 | |
| 99 | public void setSince(String since) { |
| 100 | mSince = since; |
| 101 | } |
| 102 | |
| 103 | public String getSince() { |
| 104 | return mSince; |
| 105 | } |
Hui Shu | 5118ffe | 2014-02-18 14:06:42 -0800 | [diff] [blame] | 106 | |
Scott Main | 40ad147 | 2012-10-24 18:19:17 -0700 | [diff] [blame] | 107 | public void setDeprecatedSince(String since) { |
| 108 | mDeprecatedSince = since; |
| 109 | } |
| 110 | |
| 111 | public String getDeprecatedSince() { |
| 112 | return mDeprecatedSince; |
| 113 | } |
| 114 | |
Scott Main | 68a238a | 2013-04-30 12:34:19 -0700 | [diff] [blame] | 115 | public boolean isDeprecated() { |
| 116 | return mDeprecatedSince != null ? true : false; |
| 117 | } |
| 118 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 119 | public final void addFederatedReference(FederatedSite source) { |
| 120 | mFederatedReferences.add(source); |
| 121 | } |
Hui Shu | 5118ffe | 2014-02-18 14:06:42 -0800 | [diff] [blame] | 122 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 123 | public final Set<FederatedSite> getFederatedReferences() { |
| 124 | return mFederatedReferences; |
| 125 | } |
Hui Shu | 5118ffe | 2014-02-18 14:06:42 -0800 | [diff] [blame] | 126 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 127 | public final void setFederatedReferences(Data data, String base) { |
| 128 | int pos = 0; |
| 129 | for (FederatedSite source : getFederatedReferences()) { |
| 130 | data.setValue(base + ".federated." + pos + ".url", source.linkFor(htmlPage())); |
| 131 | data.setValue(base + ".federated." + pos + ".name", source.name()); |
| 132 | pos++; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | private String mRawCommentText; |
| 137 | Comment mComment; |
| 138 | SourcePositionInfo mPosition; |
| 139 | private String mSince; |
Scott Main | 40ad147 | 2012-10-24 18:19:17 -0700 | [diff] [blame] | 140 | private String mDeprecatedSince; |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 141 | private Set<FederatedSite> mFederatedReferences = new LinkedHashSet<FederatedSite>(); |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 142 | } |