use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class AndroidXmlDocumentationProvider method findAttributeDefinition.
@Nullable
private static Pair<AttributeDefinition, String> findAttributeDefinition(@NotNull PsiElement originalElement, @NotNull AndroidFacet facet, @NotNull final String namespace, @NotNull final String localName) {
if (!originalElement.isValid()) {
return null;
}
final XmlTag parentTag = PsiTreeUtil.getParentOfType(originalElement, XmlTag.class);
if (parentTag == null) {
return null;
}
final DomElement parentDomElement = DomManager.getDomManager(parentTag.getProject()).getDomElement(parentTag);
if (!(parentDomElement instanceof AndroidDomElement)) {
return null;
}
final Ref<Pair<AttributeDefinition, String>> result = Ref.create();
try {
AttributeProcessingUtil.processAttributes((AndroidDomElement) parentDomElement, facet, false, (xn, attrDef, parentStyleableName) -> {
if (xn.getLocalName().equals(localName) && namespace.equals(xn.getNamespaceKey())) {
result.set(Pair.of(attrDef, parentStyleableName));
throw new MyStopException();
}
return null;
});
} catch (MyStopException e) {
// ignore
}
final Pair<AttributeDefinition, String> pair = result.get();
if (pair != null) {
return pair;
}
final AttributeDefinition attrDef = findAttributeDefinitionGlobally(facet, namespace, localName);
return attrDef != null ? Pair.of(attrDef, (String) null) : null;
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class ColorRendererEditor method getAllowedResourceTypes.
@NotNull
@Override
protected EnumSet<ResourceType> getAllowedResourceTypes() {
AttributeDefinition attrDefinition = ResolutionUtils.getAttributeDefinition(myContext.getConfiguration(), myItem.getSelectedValue());
String attributeName = myItem.getName().toLowerCase(Locale.ENGLISH);
if (attributeName.contains("color") || !ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Reference)) {
return COLORS_ONLY;
} else if (attributeName.contains("drawable") || !ThemeEditorUtils.acceptsFormat(attrDefinition, AttributeFormat.Color)) {
return DRAWABLES_ONLY;
} else {
return COLORS_AND_DRAWABLES;
}
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class EnumRendererEditor method getEditorComponent.
@Override
public Component getEditorComponent(JTable table, EditedStyleItem value, boolean isSelected, int row, int column) {
AttributeDefinition attrDefinition = ResolutionUtils.getAttributeDefinition(value.getSourceStyle().getConfiguration(), value.getSelectedValue());
if (attrDefinition != null) {
if (attrDefinition.getFormats().size() > 1) {
// makes the box editable for items that can take values outside of the choices
myComboBox.setEditable(true);
} else {
myComboBox.setEditable(false);
}
myComboBox.setModel(new DefaultComboBoxModel(attrDefinition.getValues()));
}
myComboBox.setSelectedItem(value.getValue());
return myComboBox;
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class AndroidCompletionContributor method isFrameworkAttributeDeprecated.
private static boolean isFrameworkAttributeDeprecated(AndroidFacet facet, XmlAttribute attribute, String attributeName) {
final ResourceManager manager = facet.getResourceManager(AndroidUtils.SYSTEM_RESOURCE_PACKAGE, attribute.getParent());
if (manager == null) {
return false;
}
final AttributeDefinitions attributes = manager.getAttributeDefinitions();
if (attributes == null) {
return false;
}
final AttributeDefinition attributeDefinition = attributes.getAttrDefByName(attributeName);
return attributeDefinition != null && attributeDefinition.isAttributeDeprecated();
}
use of org.jetbrains.android.dom.attrs.AttributeDefinition in project android by JetBrains.
the class AndroidJavaDocRenderer method renderAttributeDoc.
@NotNull
private static String renderAttributeDoc(@NotNull Module module, @Nullable Configuration configuration, @NotNull String name) {
AttributeDefinition def = ResolutionUtils.getAttributeDefinition(module, configuration, name);
String doc = (def == null) ? null : def.getDocValue(null);
HtmlBuilder builder = new HtmlBuilder();
builder.openHtmlBody();
builder.beginBold();
builder.add(name);
builder.endBold();
int api = ResolutionUtils.getOriginalApiLevel(name, module.getProject());
if (api >= 0) {
builder.add(" (Added in API level ");
builder.add(String.valueOf(api));
builder.add(")");
}
builder.addHtml("<br/>");
if (!StringUtil.isEmpty(doc)) {
builder.addHtml(doc);
builder.addHtml("<br/>");
}
builder.addHtml("<hr/>");
builder.closeHtmlBody();
return builder.getHtml();
}
Aggregations