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 java.util.ArrayList;
     18 import java.util.Comparator;
     19 
     20 import org.clearsilver.HDF;
     21 import org.clearsilver.CS;
     22 
     23 public class AttributeInfo {
     24     public static final Comparator<AttributeInfo> comparator = new Comparator<AttributeInfo>() {
     25         public int compare(AttributeInfo a, AttributeInfo b) {
     26             return a.name().compareTo(b.name());
     27         }
     28     };
     29 
     30     public FieldInfo attrField;
     31     public ArrayList<MethodInfo> methods = new ArrayList<MethodInfo>();
     32 
     33     private ClassInfo mClass;
     34     private String mName;
     35     private Comment mComment;
     36 
     37     public AttributeInfo(ClassInfo cl, FieldInfo f) {
     38         mClass = cl;
     39         attrField = f;
     40     }
     41 
     42     public String name() {
     43         if (mName == null) {
     44             for (AttrTagInfo comment: attrField.comment().attrTags()) {
     45                 String n = comment.name();
     46                 if (n != null) {
     47                     mName = n;
     48                     return n;
     49                 }
     50             }
     51         }
     52         return mName;
     53     }
     54 
     55     public Comment comment() {
     56         if (mComment == null) {
     57             for (AttrTagInfo attr: attrField.comment().attrTags()) {
     58                 Comment c = attr.description();
     59                 if (c != null) {
     60                     mComment = c;
     61                     return c;
     62                 }
     63             }
     64         }
     65         if (mComment == null) {
     66             return new Comment("", mClass, new SourcePositionInfo());
     67         }
     68         return mComment;
     69     }
     70 
     71     public String anchor() {
     72         return "attr_" + name();
     73     }
     74     public String htmlPage() {
     75         return mClass.htmlPage() + "#" + anchor();
     76     }
     77 
     78     public void makeHDF(HDF data, String base) {
     79         data.setValue(base + ".name", name());
     80         data.setValue(base + ".anchor", anchor());
     81         data.setValue(base + ".href", htmlPage());
     82         data.setValue(base + ".R.name", attrField.name());
     83         data.setValue(base + ".R.href", attrField.htmlPage());
     84         TagInfo.makeHDF(data, base + ".deprecated", attrField.comment().deprecatedTags());
     85         TagInfo.makeHDF(data, base + ".shortDescr", comment().briefTags());
     86         TagInfo.makeHDF(data, base + ".descr", comment().tags());
     87 
     88         int i=0;
     89         for (MethodInfo m: methods) {
     90             String s = base + ".methods." + i;
     91             data.setValue(s + ".href", m.htmlPage());
     92             data.setValue(s + ".name", m.name() + m.prettySignature());
     93         }
     94     }
     95 
     96     public boolean checkLevel() {
     97         return attrField.checkLevel();
     98     }
     99 }
    100 
    101