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 | |
| 21 | import java.util.regex.Pattern; |
| 22 | import java.util.regex.Matcher; |
| 23 | |
| 24 | public class ParamTagInfo extends ParsedTagInfo { |
C. Sean Young | da4b2e2 | 2015-05-18 14:12:30 -0500 | [diff] [blame] | 25 | public static final ParamTagInfo[] EMPTY_ARRAY = new ParamTagInfo[0]; |
| 26 | |
| 27 | public static ParamTagInfo[] getArray(int size) { |
| 28 | return size == 0 ? EMPTY_ARRAY : new ParamTagInfo[size]; |
| 29 | } |
| 30 | |
Ben Dodson | 920dbbb | 2010-08-04 15:21:06 -0700 | [diff] [blame] | 31 | static final Pattern PATTERN = Pattern.compile("([^ \t\r\n]+)[ \t\r\n]+(.*)", Pattern.DOTALL); |
| 32 | |
| 33 | private boolean mIsTypeParameter; |
| 34 | private String mParameterComment; |
| 35 | private String mParameterName; |
| 36 | |
| 37 | ParamTagInfo(String name, String kind, String text, ContainerInfo base, SourcePositionInfo sp) { |
| 38 | super(name, kind, text, base, sp); |
| 39 | |
| 40 | Matcher m = PATTERN.matcher(text); |
| 41 | if (m.matches()) { |
| 42 | mParameterName = m.group(1); |
| 43 | mParameterComment = m.group(2); |
| 44 | int len = mParameterName.length(); |
| 45 | mIsTypeParameter = |
| 46 | len > 2 && mParameterName.charAt(0) == '<' && mParameterName.charAt(len - 1) == '>'; |
| 47 | } else { |
| 48 | mParameterName = text.trim(); |
| 49 | mParameterComment = ""; |
| 50 | mIsTypeParameter = false; |
| 51 | } |
| 52 | setCommentText(mParameterComment); |
| 53 | } |
| 54 | |
| 55 | ParamTagInfo(String name, String kind, String text, boolean isTypeParameter, |
| 56 | String parameterComment, String parameterName, ContainerInfo base, SourcePositionInfo sp) { |
| 57 | super(name, kind, text, base, sp); |
| 58 | mIsTypeParameter = isTypeParameter; |
| 59 | mParameterComment = parameterComment; |
| 60 | mParameterName = parameterName; |
| 61 | } |
| 62 | |
| 63 | public boolean isTypeParameter() { |
| 64 | return mIsTypeParameter; |
| 65 | } |
| 66 | |
| 67 | public String parameterComment() { |
| 68 | return mParameterComment; |
| 69 | } |
| 70 | |
| 71 | public String parameterName() { |
| 72 | return mParameterName; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public void makeHDF(Data data, String base) { |
| 77 | data.setValue(base + ".name", parameterName()); |
| 78 | data.setValue(base + ".isTypeParameter", isTypeParameter() ? "1" : "0"); |
| 79 | TagInfo.makeHDF(data, base + ".comment", commentTags()); |
| 80 | } |
| 81 | |
| 82 | public static void makeHDF(Data data, String base, ParamTagInfo[] tags) { |
| 83 | for (int i = 0; i < tags.length; i++) { |
| 84 | // don't output if the comment is "" |
| 85 | if (!"".equals(tags[i].parameterComment())) { |
| 86 | tags[i].makeHDF(data, base + "." + i); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |