| 1 |
/* |
| 2 |
* Copyright (C) 2010 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.api; |
| 18 |
|
| 19 |
import com.android.annotations.NonNull; |
| 20 |
import com.android.annotations.Nullable; |
| 21 |
import com.android.resources.ResourceType; |
| 22 |
import com.google.common.annotations.Beta; |
| 23 |
|
| 24 |
import java.util.EnumSet; |
| 25 |
|
| 26 |
/** |
| 27 |
* Information about an attribute as gathered from the attrs.xml file where |
| 28 |
* the attribute was declared. This must include a format (string, reference, float, etc.), |
| 29 |
* possible flag or enum values, whether it's deprecated and its javadoc. |
| 30 |
* <p> |
| 31 |
* <b>NOTE: This is not a public or final API; if you rely on this be prepared |
| 32 |
* to adjust your code for the next tools release.</b> |
| 33 |
* </p> |
| 34 |
*/ |
| 35 |
@Beta |
| 36 |
public interface IAttributeInfo { |
| 37 |
|
| 38 |
/** An attribute format, e.g. string, reference, float, etc. */ |
| 39 |
enum Format { |
| 40 |
STRING, |
| 41 |
BOOLEAN, |
| 42 |
INTEGER, |
| 43 |
FLOAT, |
| 44 |
COLOR, |
| 45 |
DIMENSION, |
| 46 |
FRACTION, |
| 47 |
ENUM, |
| 48 |
FLAG, |
| 49 |
REFERENCE; |
| 50 |
|
| 51 |
public static final EnumSet<Format> NONE = EnumSet.noneOf(Format.class); |
| 52 |
public static final EnumSet<Format> FLAG_SET = EnumSet.of(FLAG); |
| 53 |
public static final EnumSet<Format> ENUM_SET = EnumSet.of(ENUM); |
| 54 |
public static final EnumSet<Format> COLOR_SET = EnumSet.of(COLOR); |
| 55 |
public static final EnumSet<Format> STRING_SET = EnumSet.of(STRING); |
| 56 |
public static final EnumSet<Format> BOOLEAN_SET = EnumSet.of(BOOLEAN); |
| 57 |
public static final EnumSet<Format> INTEGER_SET = EnumSet.of(INTEGER); |
| 58 |
public static final EnumSet<Format> FLOAT_SET = EnumSet.of(FLOAT); |
| 59 |
public static final EnumSet<Format> DIMENSION_SET = EnumSet.of(DIMENSION); |
| 60 |
public static final EnumSet<Format> REFERENCE_SET = EnumSet.of(REFERENCE); |
| 61 |
|
| 62 |
/** |
| 63 |
* Returns an EnumSet containing only this format (which should not be |
| 64 |
* modified by the client) |
| 65 |
* |
| 66 |
* @return a new enum set containing exactly this format |
| 67 |
*/ |
| 68 |
@NonNull |
| 69 |
public EnumSet<Format> asSet() { |
| 70 |
switch (this) { |
| 71 |
case BOOLEAN: |
| 72 |
return BOOLEAN_SET; |
| 73 |
case COLOR: |
| 74 |
return COLOR_SET; |
| 75 |
case DIMENSION: |
| 76 |
return DIMENSION_SET; |
| 77 |
case ENUM: |
| 78 |
return ENUM_SET; |
| 79 |
case FLAG: |
| 80 |
return FLAG_SET; |
| 81 |
case FLOAT: |
| 82 |
return FLOAT_SET; |
| 83 |
case INTEGER: |
| 84 |
return INTEGER_SET; |
| 85 |
case STRING: |
| 86 |
return STRING_SET; |
| 87 |
case REFERENCE: |
| 88 |
return REFERENCE_SET; |
| 89 |
case FRACTION: |
| 90 |
default: |
| 91 |
return EnumSet.of(this); |
| 92 |
} |
| 93 |
} |
| 94 |
|
| 95 |
/** Returns the corresponding resource type for this attribute info, |
| 96 |
* or null if there is no known or corresponding resource type (such as for |
| 97 |
* enums and flags) |
| 98 |
* |
| 99 |
* @return the corresponding resource type, or null |
| 100 |
*/ |
| 101 |
@Nullable |
| 102 |
public ResourceType getResourceType() { |
| 103 |
switch (this) { |
| 104 |
case STRING: |
| 105 |
return ResourceType.STRING; |
| 106 |
case BOOLEAN: |
| 107 |
return ResourceType.BOOL; |
| 108 |
case COLOR: |
| 109 |
return ResourceType.COLOR; |
| 110 |
case DIMENSION: |
| 111 |
return ResourceType.DIMEN; |
| 112 |
case FRACTION: |
| 113 |
return ResourceType.FRACTION; |
| 114 |
case INTEGER: |
| 115 |
return ResourceType.INTEGER; |
| 116 |
|
| 117 |
// No direct corresponding resource type |
| 118 |
case ENUM: |
| 119 |
case FLAG: |
| 120 |
case FLOAT: |
| 121 |
case REFERENCE: |
| 122 |
return null; |
| 123 |
} |
| 124 |
|
| 125 |
return null; |
| 126 |
} |
| 127 |
} |
| 128 |
|
| 129 |
/** Returns the XML Name of the attribute */ |
| 130 |
@NonNull |
| 131 |
String getName(); |
| 132 |
|
| 133 |
/** Returns the formats of the attribute. Cannot be null. |
| 134 |
* Should have at least one format. */ |
| 135 |
@NonNull |
| 136 |
EnumSet<Format> getFormats(); |
| 137 |
|
| 138 |
/** Returns the values for enums. null for other types. */ |
| 139 |
@Nullable |
| 140 |
String[] getEnumValues(); |
| 141 |
|
| 142 |
/** Returns the values for flags. null for other types. */ |
| 143 |
@Nullable |
| 144 |
String[] getFlagValues(); |
| 145 |
|
| 146 |
/** Returns a short javadoc, .i.e. the first sentence. */ |
| 147 |
@NonNull |
| 148 |
String getJavaDoc(); |
| 149 |
|
| 150 |
/** Returns the documentation for deprecated attributes. Null if not deprecated. */ |
| 151 |
@Nullable |
| 152 |
String getDeprecatedDoc(); |
| 153 |
|
| 154 |
/** Returns the fully qualified class name of the view defining this attribute */ |
| 155 |
@NonNull |
| 156 |
String getDefinedBy(); |
| 157 |
} |