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 17package com.google.doclava; 18 19import com.google.clearsilver.jsilver.data.Data; 20 21import java.util.regex.Pattern; 22import java.util.regex.Matcher; 23 24public class ParamTagInfo extends ParsedTagInfo { 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 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} 91