blob: 822d9cb84fdf3376bb81b9917f719988415f726d [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
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070019import java.util.ArrayList;
20import java.util.Arrays;
21
22public class AnnotationInstanceInfo implements Resolvable {
Ben Dodson920dbbb2010-08-04 15:21:06 -070023 private ClassInfo mType;
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070024 private String mName; // for temp purposes
25 private ArrayList<AnnotationValueInfo> mElementValues;
26 private ArrayList<Resolution> mResolutions;
27
28 public AnnotationInstanceInfo() {
29 mType = null;
30 mElementValues = new ArrayList<AnnotationValueInfo>();
31 }
Ben Dodson920dbbb2010-08-04 15:21:06 -070032
33 public AnnotationInstanceInfo(ClassInfo type, AnnotationValueInfo[] elementValues) {
34 mType = type;
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070035 mElementValues = new ArrayList<AnnotationValueInfo>(Arrays.asList(elementValues));
Ben Dodson920dbbb2010-08-04 15:21:06 -070036 }
37
38 ClassInfo type() {
39 return mType;
40 }
41
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070042 public void setClass(ClassInfo cl) {
43 mType = cl;
44 }
45
46 public void setClassName(String name) {
47 mName = name;
48 }
49
50 ArrayList<AnnotationValueInfo> elementValues() {
Ben Dodson920dbbb2010-08-04 15:21:06 -070051 return mElementValues;
52 }
53
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070054 public void addElementValue(AnnotationValueInfo info) {
55 mElementValues.add(info);
56 }
57
Ben Dodson920dbbb2010-08-04 15:21:06 -070058 @Override
59 public String toString() {
60 StringBuilder str = new StringBuilder();
61 str.append("@");
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070062 if (mType == null) {
63 str.append(mName);
64 } else {
65 str.append(mType.qualifiedName());
66 }
Ben Dodson920dbbb2010-08-04 15:21:06 -070067 str.append("(");
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070068
69 for (AnnotationValueInfo value : mElementValues) {
70 if (value.element() != null) {
71 str.append(value.element().name());
72 str.append("=");
73 }
74
Ben Dodson920dbbb2010-08-04 15:21:06 -070075 str.append(value.valueString());
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070076 if (value != mElementValues.get(mElementValues.size()-1)) {
Ben Dodson920dbbb2010-08-04 15:21:06 -070077 str.append(",");
78 }
79 }
80 str.append(")");
81 return str.toString();
82 }
Andrew Sappersteind6eaacb2011-05-20 13:14:56 -070083
84 public void addResolution(Resolution resolution) {
85 if (mResolutions == null) {
86 mResolutions = new ArrayList<Resolution>();
87 }
88
89 mResolutions.add(resolution);
90 }
91
92 public void printResolutions() {
93 System.out.println("Resolutions for Annotation:");
94 for (Resolution r : mResolutions) {
95 System.out.println(r);
96 }
97 }
Ben Dodson920dbbb2010-08-04 15:21:06 -070098}