1 /* 2 * Copyright (C) 2008 The Android Open Source Project 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 import java.util.regex.Pattern; 18 import java.util.regex.Matcher; 19 import org.clearsilver.HDF; 20 import org.clearsilver.CS; 21 22 public class ParamTagInfo extends ParsedTagInfo 23 { 24 static final Pattern PATTERN = Pattern.compile( 25 "([^ \t\r\n]+)[ \t\r\n]+(.*)", 26 Pattern.DOTALL); 27 28 private boolean mIsTypeParameter; 29 private String mParameterComment; 30 private String mParameterName; 31 32 ParamTagInfo(String name, String kind, String text, ContainerInfo base, 33 SourcePositionInfo sp) 34 { 35 super(name, kind, text, base, sp); 36 37 Matcher m = PATTERN.matcher(text); 38 if (m.matches()) { 39 mParameterName = m.group(1); 40 mParameterComment = m.group(2); 41 int len = mParameterName.length(); 42 mIsTypeParameter = len > 2 43 && mParameterName.charAt(0) == '<' 44 && mParameterName.charAt(len-1) == '>'; 45 } else { 46 mParameterName = text.trim(); 47 mParameterComment = ""; 48 mIsTypeParameter = false; 49 } 50 setCommentText(mParameterComment); 51 } 52 53 ParamTagInfo(String name, String kind, String text, 54 boolean isTypeParameter, String parameterComment, 55 String parameterName, ContainerInfo base, 56 SourcePositionInfo sp) 57 { 58 super(name, kind, text, base, sp); 59 mIsTypeParameter = isTypeParameter; 60 mParameterComment = parameterComment; 61 mParameterName = parameterName; 62 } 63 64 public boolean isTypeParameter() 65 { 66 return mIsTypeParameter; 67 } 68 69 public String parameterComment() 70 { 71 return mParameterComment; 72 } 73 74 public String parameterName() 75 { 76 return mParameterName; 77 } 78 79 @Override 80 public void makeHDF(HDF data, String base) 81 { 82 data.setValue(base + ".name", parameterName()); 83 data.setValue(base + ".isTypeParameter", isTypeParameter() ? "1" : "0"); 84 TagInfo.makeHDF(data, base + ".comment", commentTags()); 85 } 86 87 public static void makeHDF(HDF data, String base, ParamTagInfo[] tags) 88 { 89 for (int i=0; i<tags.length; i++) { 90 // don't output if the comment is "" 91 if (!"".equals(tags[i].parameterComment())) { 92 tags[i].makeHDF(data, base + "." + i); 93 } 94 } 95 } 96 } 97