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 ThrowsTagInfo extends ParsedTagInfo { 25 static final Pattern PATTERN = Pattern.compile("(\\S+)\\s+(.*)", Pattern.DOTALL); 26 private ClassInfo mException; 27 28 public ThrowsTagInfo(String name, String kind, String text, ContainerInfo base, 29 SourcePositionInfo sp) { 30 super(name, kind, text, base, sp); 31 32 Matcher m = PATTERN.matcher(text); 33 if (m.matches()) { 34 setCommentText(m.group(2)); 35 String className = m.group(1); 36 if (base instanceof ClassInfo) { 37 mException = ((ClassInfo) base).findClass(className); 38 } 39 if (mException == null) { 40 mException = Converter.obtainClass(className); 41 } 42 } 43 } 44 45 public ThrowsTagInfo(String name, String kind, String text, ClassInfo exception, 46 String exceptionComment, ContainerInfo base, SourcePositionInfo sp) { 47 super(name, kind, text, base, sp); 48 mException = exception; 49 setCommentText(exceptionComment); 50 } 51 52 public ClassInfo exception() { 53 return mException; 54 } 55 56 public TypeInfo exceptionType() { 57 if (mException != null) { 58 return mException.asTypeInfo(); 59 } else { 60 return null; 61 } 62 } 63 64 public static void makeHDF(Data data, String base, ThrowsTagInfo[] tags) { 65 for (int i = 0; i < tags.length; i++) { 66 TagInfo.makeHDF(data, base + '.' + i + ".comment", tags[i].commentTags()); 67 if (tags[i].exceptionType() != null) { 68 tags[i].exceptionType().makeHDF(data, base + "." + i + ".type"); 69 } 70 } 71 } 72 73 74} 75