• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Eclipse Public License, Version 1.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.eclipse.org/org/documents/epl-v10.php
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.android.ide.common.resources.platform;
18 
19 import com.android.annotations.NonNull;
20 import com.android.ide.common.api.IAttributeInfo;
21 
22 import java.util.EnumSet;
23 
24 
25 /**
26  * Information about an attribute as gathered from the attrs.xml file where
27  * the attribute was declared. This must include a format (string, reference, float, etc.),
28  * possible flag or enum values, whether it's deprecated and its javadoc.
29  */
30 public class AttributeInfo implements IAttributeInfo {
31     /** XML Name of the attribute */
32     private String mName;
33 
34     /** Formats of the attribute. Cannot be null. Should have at least one format. */
35     private EnumSet<Format> mFormats;
36     /** Values for enum. null for other types. */
37     private String[] mEnumValues;
38     /** Values for flag. null for other types. */
39     private String[] mFlagValues;
40     /** Short javadoc (i.e. the first sentence). */
41     private String mJavaDoc;
42     /** Documentation for deprecated attributes. Null if not deprecated. */
43     private String mDeprecatedDoc;
44     /** The source class defining this attribute */
45     private String mDefinedBy;
46 
47     /**
48      * @param name The XML Name of the attribute
49      * @param formats The formats of the attribute. Cannot be null.
50      *                Should have at least one format.
51      */
AttributeInfo(@onNull String name, @NonNull EnumSet<Format> formats)52     public AttributeInfo(@NonNull String name, @NonNull EnumSet<Format> formats) {
53         mName = name;
54         mFormats = formats;
55     }
56 
57     /**
58      * @param name The XML Name of the attribute
59      * @param formats The formats of the attribute. Cannot be null.
60      *                Should have at least one format.
61      * @param javadoc Short javadoc (i.e. the first sentence).
62      */
AttributeInfo(@onNull String name, @NonNull EnumSet<Format> formats, String javadoc)63     public AttributeInfo(@NonNull String name, @NonNull EnumSet<Format> formats, String javadoc) {
64         mName = name;
65         mFormats = formats;
66         mJavaDoc = javadoc;
67     }
68 
AttributeInfo(AttributeInfo info)69     public AttributeInfo(AttributeInfo info) {
70         mName = info.mName;
71         mFormats = info.mFormats;
72         mEnumValues = info.mEnumValues;
73         mFlagValues = info.mFlagValues;
74         mJavaDoc = info.mJavaDoc;
75         mDeprecatedDoc = info.mDeprecatedDoc;
76     }
77 
78     /** Returns the XML Name of the attribute */
79     @Override
getName()80     public String getName() {
81         return mName;
82     }
83     /** Returns the formats of the attribute. Cannot be null.
84      *  Should have at least one format. */
85     @Override
getFormats()86     public EnumSet<Format> getFormats() {
87         return mFormats;
88     }
89     /** Returns the values for enums. null for other types. */
90     @Override
getEnumValues()91     public String[] getEnumValues() {
92         return mEnumValues;
93     }
94     /** Returns the values for flags. null for other types. */
95     @Override
getFlagValues()96     public String[] getFlagValues() {
97         return mFlagValues;
98     }
99     /** Returns a short javadoc, .i.e. the first sentence. */
100     @Override
getJavaDoc()101     public String getJavaDoc() {
102         return mJavaDoc;
103     }
104     /** Returns the documentation for deprecated attributes. Null if not deprecated. */
105     @Override
getDeprecatedDoc()106     public String getDeprecatedDoc() {
107         return mDeprecatedDoc;
108     }
109 
110     /** Sets the values for enums. null for other types. */
setEnumValues(String[] values)111     public AttributeInfo setEnumValues(String[] values) {
112         mEnumValues = values;
113         return this;
114     }
115 
116     /** Sets the values for flags. null for other types. */
setFlagValues(String[] values)117     public AttributeInfo setFlagValues(String[] values) {
118         mFlagValues = values;
119         return this;
120     }
121 
122     /** Sets a short javadoc, .i.e. the first sentence. */
setJavaDoc(String javaDoc)123     public void setJavaDoc(String javaDoc) {
124         mJavaDoc = javaDoc;
125     }
126 
127     /** Sets the documentation for deprecated attributes. Null if not deprecated. */
setDeprecatedDoc(String deprecatedDoc)128     public void setDeprecatedDoc(String deprecatedDoc) {
129         mDeprecatedDoc = deprecatedDoc;
130     }
131 
132     /**
133      * Sets the name of the class (fully qualified class name) which defined
134      * this attribute
135      *
136      * @param definedBy the name of the class (fully qualified class name) which
137      *            defined this attribute
138      */
setDefinedBy(String definedBy)139     public void setDefinedBy(String definedBy) {
140         mDefinedBy = definedBy;
141     }
142 
143     /**
144      * Returns the name of the class (fully qualified class name) which defined
145      * this attribute
146      *
147      * @return the name of the class (fully qualified class name) which defined
148      *         this attribute
149      */
150     @Override
getDefinedBy()151     public String getDefinedBy() {
152         return mDefinedBy;
153     }
154 }
155