use of com.intellij.util.xml.DomElement in project android by JetBrains.
the class AndroidFindStyleApplicationsAction method getStyleData.
@Nullable
static MyStyleData getStyleData(@NotNull XmlTag tag) {
final DomElement element = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (!(element instanceof Style)) {
return null;
}
final Style style = (Style) element;
final GenericAttributeValue<String> styleNameDomAttr = style.getName();
final String styleName = styleNameDomAttr.getStringValue();
final XmlAttributeValue styleNameAttrValue = styleNameDomAttr.getXmlAttributeValue();
if (styleName == null || styleName.length() == 0 || styleNameAttrValue == null) {
return null;
}
final AndroidFacet facet = AndroidFacet.getInstance(tag);
if (facet == null) {
return null;
}
return new MyStyleData(style, styleName, facet, styleNameAttrValue);
}
use of com.intellij.util.xml.DomElement in project android by JetBrains.
the class AndroidFindStyleApplicationsProcessor method performRefactoring.
@Override
protected void performRefactoring(@NotNull UsageInfo[] usages) {
final Set<Pair<String, String>> attrsInStyle = new HashSet<Pair<String, String>>();
for (AndroidAttributeInfo info : myAttrMap.keySet()) {
attrsInStyle.add(Pair.create(info.getNamespace(), info.getName()));
}
for (UsageInfo usage : usages) {
final PsiElement element = usage.getElement();
final DomElement domElement = element instanceof XmlTag ? DomManager.getDomManager(myProject).getDomElement((XmlTag) element) : null;
if (domElement instanceof LayoutViewElement) {
final List<XmlAttribute> attributesToDelete = new ArrayList<XmlAttribute>();
for (XmlAttribute attribute : ((XmlTag) element).getAttributes()) {
if (attrsInStyle.contains(Pair.create(attribute.getNamespace(), attribute.getLocalName()))) {
attributesToDelete.add(attribute);
}
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
for (XmlAttribute attribute : attributesToDelete) {
attribute.delete();
}
((LayoutViewElement) domElement).getStyle().setStringValue("@style/" + myStyleName);
}
});
}
}
final PsiFile file = myStyleTag.getContainingFile();
if (file != null) {
UndoUtil.markPsiFileForUndo(file);
}
if (myContext != null) {
UndoUtil.markPsiFileForUndo(myContext);
}
}
use of com.intellij.util.xml.DomElement in project android by JetBrains.
the class AndroidInlineUtil method getLayoutUsageData.
@Nullable
static LayoutUsageData getLayoutUsageData(@NotNull XmlTag tag) {
final Project project = tag.getProject();
final DomElement domElement = DomManager.getDomManager(project).getDomElement(tag);
if (domElement instanceof Include) {
final GenericAttributeValue<ResourceValue> layoutAttribute = ((Include) domElement).getLayout();
final AndroidResourceReferenceBase reference = AndroidDomUtil.getAndroidResourceReference(layoutAttribute, true);
if (reference != null) {
return new LayoutUsageData(project, tag, reference);
}
}
return null;
}
use of com.intellij.util.xml.DomElement in project android by JetBrains.
the class AndroidInlineUtil method getInlinableStyleData.
@Nullable
static MyStyleData getInlinableStyleData(@NotNull XmlTag tag) {
final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (!(domElement instanceof Style)) {
return null;
}
final Style style = (Style) domElement;
final XmlAttributeValue nameAttrValue = style.getName().getXmlAttributeValue();
if (nameAttrValue == null) {
return null;
}
final String styleName = style.getName().getStringValue();
if (styleName == null || styleName.length() == 0) {
return null;
}
return new MyStyleData(styleName, style, nameAttrValue);
}
use of com.intellij.util.xml.DomElement in project android by JetBrains.
the class AndroidExtractAsIncludeAction method isEnabledForTags.
@Override
protected boolean isEnabledForTags(@NotNull XmlTag[] tags) {
if (tags.length == 0) {
return false;
}
final DomManager domManager = DomManager.getDomManager(tags[0].getProject());
boolean containsViewElement = false;
for (XmlTag tag : tags) {
final DomElement domElement = domManager.getDomElement(tag);
if (!isSuitableDomElement(domElement)) {
return false;
}
if (domElement instanceof LayoutViewElement) {
containsViewElement = true;
}
}
if (!containsViewElement) {
return false;
}
final PsiElement parent = tags[0].getParent();
if (!(parent instanceof XmlTag) || parent.getContainingFile() == null) {
return false;
}
for (int i = 1; i < tags.length; i++) {
if (tags[i].getParent() != parent) {
return false;
}
}
return true;
}
Aggregations