use of org.jetbrains.android.dom.layout.LayoutViewElement in project android by JetBrains.
the class AndroidInlineUtil method getStyleUsageData.
@Nullable
static StyleUsageData getStyleUsageData(@NotNull XmlTag tag) {
final DomElement domElement = DomManager.getDomManager(tag.getProject()).getDomElement(tag);
if (domElement instanceof LayoutViewElement) {
final GenericAttributeValue<ResourceValue> styleAttribute = ((LayoutViewElement) domElement).getStyle();
final AndroidResourceReferenceBase reference = AndroidDomUtil.getAndroidResourceReference(styleAttribute, true);
if (reference != null) {
return new ViewStyleUsageData(tag, styleAttribute, reference);
}
} else if (domElement instanceof Style) {
final AndroidResourceReferenceBase reference = AndroidDomUtil.getAndroidResourceReference(((Style) domElement).getParentStyle(), true);
if (reference != null) {
return new ParentStyleUsageData((Style) domElement, reference);
}
}
return null;
}
use of org.jetbrains.android.dom.layout.LayoutViewElement in project android by JetBrains.
the class AndroidFindStyleApplicationsProcessor method isPossibleApplicationOfStyle.
private boolean isPossibleApplicationOfStyle(XmlTag candidate) {
final DomElement domCandidate = DomManager.getDomManager(myProject).getDomElement(candidate);
if (!(domCandidate instanceof LayoutViewElement)) {
return false;
}
final LayoutViewElement candidateView = (LayoutViewElement) domCandidate;
final Map<Pair<String, String>, String> attrsInCandidateMap = new HashMap<Pair<String, String>, String>();
final List<XmlAttribute> attrsInCandidate = AndroidExtractStyleAction.getExtractableAttributes(candidate);
if (attrsInCandidate.size() < myAttrMap.size()) {
return false;
}
for (XmlAttribute attribute : attrsInCandidate) {
final String attrValue = attribute.getValue();
if (attrValue != null) {
attrsInCandidateMap.put(Pair.create(attribute.getNamespace(), attribute.getLocalName()), attrValue);
}
}
for (Map.Entry<AndroidAttributeInfo, String> entry : myAttrMap.entrySet()) {
final String ns = entry.getKey().getNamespace();
final String name = entry.getKey().getName();
final String value = entry.getValue();
final String valueInCandidate = attrsInCandidateMap.get(Pair.create(ns, name));
if (valueInCandidate == null || !valueInCandidate.equals(value)) {
return false;
}
}
if (candidateView.getStyle().getStringValue() != null) {
if (myParentStyleNameAttrValue == null) {
return false;
}
final PsiElement styleNameAttrValueForTag = getStyleNameAttrValueForTag(candidateView);
if (styleNameAttrValueForTag == null || !myParentStyleNameAttrValue.equals(styleNameAttrValueForTag)) {
return false;
}
} else if (myParentStyleNameAttrValue != null) {
return false;
}
return true;
}
use of org.jetbrains.android.dom.layout.LayoutViewElement in project android by JetBrains.
the class StructureViewTest method testLayoutStructureOrder2.
public void testLayoutStructureOrder2() throws Exception {
VirtualFile file = copyFileToProject("layout/structure_view_test_order_2.xml", "/res/layout/layout.xml");
PsiFile psiFile = PsiManager.getInstance(getProject()).findFile(file);
assertInstanceOf(psiFile, XmlFile.class);
DomFileElement<LayoutViewElement> element = DomManager.getDomManager(getProject()).getFileElement(((XmlFile) psiFile), LayoutViewElement.class);
assertNotNull(element);
final StructureViewModel model = new LayoutStructureViewBuilder(element).createStructureViewModel(null);
String expected = "LinearLayout\n" + " Include\n" + " Fragment\n";
assertEquals(expected, model.getRoot().toString());
}
use of org.jetbrains.android.dom.layout.LayoutViewElement in project android by JetBrains.
the class RtlSupportProcessor method getLayoutRefactoringForTag.
private List<UsageInfo> getLayoutRefactoringForTag(@NotNull XmlTag tag, boolean createV17, int minSdk) {
final DomElement domElement = DomManager.getDomManager(myProject).getDomElement(tag);
if (!(domElement instanceof LayoutViewElement)) {
return Collections.emptyList();
}
final List<UsageInfo> result = new ArrayList<UsageInfo>();
final XmlAttribute[] attributes = tag.getAttributes();
for (XmlAttribute attributeToMirror : attributes) {
final String localName = attributeToMirror.getLocalName();
final String namespacePrefix = attributeToMirror.getNamespacePrefix();
final String mirroredLocalName = ourMapMirroredAttributeName.get(localName);
// Check if this is a RTL attribute to mirror or if it is a Gravity attribute
if (mirroredLocalName != null) {
// Mirror only attributes that has not been mirrored before
final XmlAttribute attributeMirrored = tag.getAttribute(namespacePrefix + ":" + mirroredLocalName);
if (attributeMirrored == null) {
final int startOffset = 0;
final int endOffset = attributeToMirror.getTextLength();
RtlRefactoringUsageInfo usageInfoForAttribute = new RtlRefactoringUsageInfo(attributeToMirror, startOffset, endOffset);
usageInfoForAttribute.setType(LAYOUT_FILE_ATTRIBUTE);
usageInfoForAttribute.setCreateV17(createV17);
usageInfoForAttribute.setAndroidManifestMinSdkVersion(minSdk);
result.add(usageInfoForAttribute);
}
} else if (localName.equals(ATTR_GRAVITY) || localName.equals(ATTR_LAYOUT_GRAVITY)) {
final String value = attributeToMirror.getValue();
if (value != null && (value.contains(GRAVITY_VALUE_LEFT) || value.contains(GRAVITY_VALUE_RIGHT))) {
final int startOffset = 0;
final int endOffset = attributeToMirror.getTextLength();
RtlRefactoringUsageInfo usageInfoForAttribute = new RtlRefactoringUsageInfo(attributeToMirror, startOffset, endOffset);
usageInfoForAttribute.setType(LAYOUT_FILE_ATTRIBUTE);
usageInfoForAttribute.setCreateV17(createV17);
result.add(usageInfoForAttribute);
}
}
}
return result;
}
use of org.jetbrains.android.dom.layout.LayoutViewElement in project android by JetBrains.
the class AndroidExtractAsIncludeAction method isEnabledForPsiRange.
@Override
protected boolean isEnabledForPsiRange(@NotNull PsiElement from, @Nullable PsiElement to) {
final DomManager domManager = DomManager.getDomManager(from.getProject());
PsiElement e = from;
boolean containsViewElement = false;
while (e != null) {
if (e instanceof XmlTag) {
final DomElement domElement = domManager.getDomElement((XmlTag) e);
if (!isSuitableDomElement(domElement)) {
return false;
}
if (domElement instanceof LayoutViewElement) {
containsViewElement = true;
}
}
if (e == to) {
break;
}
e = e.getNextSibling();
}
return containsViewElement;
}
Aggregations