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