use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class AndroidXmlDocumentationProvider method getAttributeDefinitionForElement.
/**
* Try to get the attribute definition for an element using first the system resource manager and then the local one.
* Return null if can't find definition in any resource manager.
*/
@Nullable
private static AttributeDefinition getAttributeDefinitionForElement(@NotNull PsiElement element, @NotNull String name) {
AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
return null;
}
AttributeDefinitions definitions = getAttributeDefinitions(facet.getSystemResourceManager());
if (definitions == null) {
return null;
}
AttributeDefinition attributeDefinition = definitions.getAttrDefByName(name);
if (attributeDefinition == null) {
// Try to get the attribute definition using the local resource manager instead
definitions = getAttributeDefinitions(facet.getLocalResourceManager());
if (definitions == null) {
return null;
}
attributeDefinition = definitions.getAttrDefByName(name);
}
return attributeDefinition;
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class EditedStyleItem method isDeprecated.
public boolean isDeprecated() {
AttributeDefinition def = ResolutionUtils.getAttributeDefinition(mySourceTheme.getConfiguration(), getSelectedValue());
String doc = (def == null) ? null : def.getDocValue(null);
return (doc != null && StringUtil.containsIgnoreCase(doc, DEPRECATED));
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class RenderErrorContributor method reportTagResourceFormat.
private void reportTagResourceFormat(@NotNull RenderResult result, @NotNull RenderProblem message) {
Object clientData = message.getClientData();
if (!(clientData instanceof String[])) {
return;
}
String[] strings = (String[]) clientData;
if (strings.length != 2) {
return;
}
RenderTask renderTask = result.getRenderTask();
if (renderTask == null) {
return;
}
IAndroidTarget target = renderTask.getConfiguration().getRealTarget();
if (target == null) {
return;
}
AndroidPlatform platform = renderTask.getPlatform();
if (platform == null) {
return;
}
AndroidTargetData targetData = platform.getSdkData().getTargetData(target);
AttributeDefinitions definitionLookup = targetData.getPublicAttrDefs(result.getFile().getProject());
final String attributeName = strings[0];
final String currentValue = strings[1];
if (definitionLookup == null) {
return;
}
AttributeDefinition definition = definitionLookup.getAttrDefByName(attributeName);
if (definition == null) {
return;
}
Set<AttributeFormat> formats = definition.getFormats();
if (formats.contains(AttributeFormat.Flag) || formats.contains(AttributeFormat.Enum)) {
String[] values = definition.getValues();
if (values.length > 0) {
HtmlBuilder builder = new HtmlBuilder();
builder.add("Change ").add(currentValue).add(" to: ");
boolean first = true;
for (String value : values) {
if (first) {
first = false;
} else {
builder.add(", ");
}
builder.addLink(value, myLinkManager.createReplaceAttributeValueUrl(attributeName, currentValue, value));
}
addRefreshAction(builder);
addIssue().setSummary("Incorrect resource value format").setHtmlContent(builder).build();
}
}
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlBooleanIconEditor method updateDescription.
private void updateDescription(@NotNull NlProperty property) {
AttributeDefinition definition = property.getDefinition();
if (definition != null) {
String description = definition.getValueDoc(myAction.myTrueValue);
if (description != null) {
// TODO: Add a getter of the presentation instance in ActionButton. Then we can get rid of myPresentation.
myPresentation.setDescription(description);
myPresentation.setText(description);
}
}
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class NlPropertyEditors method getEditorType.
@NotNull
private static EditorType getEditorType(@NotNull NlProperty property) {
AttributeDefinition definition = property.getDefinition();
Set<AttributeFormat> formats = definition != null ? definition.getFormats() : Collections.emptySet();
Boolean isBoolean = null;
for (AttributeFormat format : formats) {
switch(format) {
case Boolean:
if (isBoolean == null) {
isBoolean = Boolean.TRUE;
}
break;
case String:
case Color:
case Dimension:
case Integer:
case Float:
case Fraction:
if (isBoolean == null) {
isBoolean = Boolean.FALSE;
}
break;
case Enum:
return EditorType.COMBO;
case Flag:
return EditorType.FLAG;
default:
break;
}
}
// Do not inline this method. Other classes should not know about EnumSupportFactory.
if (isBoolean == Boolean.TRUE) {
return EditorType.BOOLEAN;
} else if (EnumSupportFactory.supportsProperty(property)) {
if (property.getName().equals(ATTR_STYLE)) {
return EditorType.COMBO_WITH_BROWSE;
}
return EditorType.COMBO;
}
return EditorType.DEFAULT;
}
Aggregations