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