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 { 25 static final Pattern PATTERN = Pattern.compile("([^ \t\r\n]+)[ \t\r\n]+(.*)", Pattern.DOTALL); 26 27 private boolean mIsTypeParameter; 28 private String mParameterComment; 29 private String mParameterName; 30 31 ParamTagInfo(String name, String kind, String text, ContainerInfo base, SourcePositionInfo sp) { 32 super(name, kind, text, base, sp); 33 34 Matcher m = PATTERN.matcher(text); 35 if (m.matches()) { 36 mParameterName = m.group(1); 37 mParameterComment = m.group(2); 38 int len = mParameterName.length(); 39 mIsTypeParameter = 40 len > 2 && mParameterName.charAt(0) == '<' && mParameterName.charAt(len - 1) == '>'; 41 } else { 42 mParameterName = text.trim(); 43 mParameterComment = ""; 44 mIsTypeParameter = false; 45 } 46 setCommentText(mParameterComment); 47 } 48 49 ParamTagInfo(String name, String kind, String text, boolean isTypeParameter, 50 String parameterComment, String parameterName, ContainerInfo base, SourcePositionInfo sp) { 51 super(name, kind, text, base, sp); 52 mIsTypeParameter = isTypeParameter; 53 mParameterComment = parameterComment; 54 mParameterName = parameterName; 55 } 56 57 public boolean isTypeParameter() { 58 return mIsTypeParameter; 59 } 60 61 public String parameterComment() { 62 return mParameterComment; 63 } 64 65 public String parameterName() { 66 return mParameterName; 67 } 68 69 @Override 70 public void makeHDF(Data data, String base) { 71 data.setValue(base + ".name", parameterName()); 72 data.setValue(base + ".isTypeParameter", isTypeParameter() ? "1" : "0"); 73 TagInfo.makeHDF(data, base + ".comment", commentTags()); 74 } 75 76 public static void makeHDF(Data data, String base, ParamTagInfo[] tags) { 77 for (int i = 0; i < tags.length; i++) { 78 // don't output if the comment is "" 79 if (!"".equals(tags[i].parameterComment())) { 80 tags[i].makeHDF(data, base + "." + i); 81 } 82 } 83 } 84 } 85