Search in sources :

Example 6 with AndroidResourceReferenceBase

use of org.jetbrains.android.dom.converters.AndroidResourceReferenceBase in project android by JetBrains.

the class AndroidInlineIncludeAction method doRefactorForTags.

@Override
protected void doRefactorForTags(@NotNull Project project, @NotNull final XmlTag[] tags) {
    assert tags.length == 1;
    final XmlTag tag = tags[0];
    final PsiFile file = tag.getContainingFile();
    if (file == null) {
        return;
    }
    final LayoutUsageData usageData = AndroidInlineUtil.getLayoutUsageData(tag);
    if (usageData == null) {
        return;
    }
    final AndroidResourceReferenceBase reference = usageData.getReference();
    final String title = AndroidBundle.message("android.inline.layout.title");
    final PsiElement[] resolvedElements = reference.computeTargetElements();
    if (resolvedElements.length == 0) {
        AndroidUtils.reportError(project, "Cannot find layout by reference '" + reference.getValue() + "'", title);
        return;
    }
    if (resolvedElements.length > 1) {
        AndroidUtils.reportError(project, RefactoringBundle.getCannotRefactorMessage("Unambiguous layout reference."), title);
        return;
    }
    final PsiElement resolvedElement = resolvedElements[0];
    if (!(resolvedElement instanceof XmlFile)) {
        AndroidUtils.reportError(project, "Cannot find layout by reference '" + reference.getValue() + "'", title);
        return;
    }
    AndroidInlineUtil.doInlineLayoutFile(project, (XmlFile) resolvedElement, usageData.getReference().getElement(), myTestConfig);
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) AndroidResourceReferenceBase(org.jetbrains.android.dom.converters.AndroidResourceReferenceBase) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

AndroidResourceReferenceBase (org.jetbrains.android.dom.converters.AndroidResourceReferenceBase)6 PsiElement (com.intellij.psi.PsiElement)3 DomElement (com.intellij.util.xml.DomElement)3 ProjectBasedErrorReporter (org.jetbrains.android.util.ProjectBasedErrorReporter)3 PsiFile (com.intellij.psi.PsiFile)2 PsiReference (com.intellij.psi.PsiReference)2 XmlFile (com.intellij.psi.xml.XmlFile)2 XmlTag (com.intellij.psi.xml.XmlTag)2 ResourceValue (org.jetbrains.android.dom.resources.ResourceValue)2 Style (org.jetbrains.android.dom.resources.Style)2 ErrorReporter (org.jetbrains.android.util.ErrorReporter)2 HintBasedErrorReporter (org.jetbrains.android.util.HintBasedErrorReporter)2 Nullable (org.jetbrains.annotations.Nullable)2 Project (com.intellij.openapi.project.Project)1 Include (org.jetbrains.android.dom.layout.Include)1 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)1 ResourceElementWrapper (org.jetbrains.android.dom.wrappers.ResourceElementWrapper)1