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