blob: 25d424f8b666241cf4ab497da3186b5afcad308a [file] [log] [blame]
Ben Dodson920dbbb2010-08-04 15:21:06 -07001/*
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.ArrayList;
22import java.util.Comparator;
23
24public 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 }
53 return mName;
54 }
55
56 public Comment comment() {
57 if (mComment == null) {
58 for (AttrTagInfo attr : attrField.comment().attrTags()) {
59 Comment c = attr.description();
60 if (c != null) {
61 mComment = c;
62 return c;
63 }
64 }
65 }
66 if (mComment == null) {
67 return new Comment("", mClass, SourcePositionInfo.UNKNOWN);
68 }
69 return mComment;
70 }
71
72 public String anchor() {
73 return "attr_" + name();
74 }
75
76 public String htmlPage() {
77 return mClass.htmlPage() + "#" + anchor();
78 }
79
80 public void makeHDF(Data data, String base) {
81 data.setValue(base + ".name", name());
82 data.setValue(base + ".anchor", anchor());
83 data.setValue(base + ".href", htmlPage());
84 data.setValue(base + ".R.name", attrField.name());
85 data.setValue(base + ".R.href", attrField.htmlPage());
86 TagInfo.makeHDF(data, base + ".deprecated", attrField.comment().deprecatedTags());
87 TagInfo.makeHDF(data, base + ".shortDescr", comment().briefTags());
88 TagInfo.makeHDF(data, base + ".descr", comment().tags());
89
90 int i = 0;
91 for (MethodInfo m : methods) {
92 String s = base + ".methods." + i;
93 data.setValue(s + ".href", m.htmlPage());
94 data.setValue(s + ".name", m.prettySignature());
95 }
96 }
97
98 public boolean checkLevel() {
99 return attrField.checkLevel();
100 }
101}