Search in sources :

Example 1 with HintBasedErrorReporter

use of org.jetbrains.android.util.HintBasedErrorReporter in project android by JetBrains.

the class AndroidInlineLayoutHandler method inlineElement.

@Override
public void inlineElement(Project project, Editor editor, PsiElement element) {
    if (element instanceof ResourceElementWrapper) {
        element = ((ResourceElementWrapper) element).getWrappee();
    }
    if (element instanceof XmlFile) {
        PsiElement usageElement = null;
        if (editor != null) {
            final PsiReference reference = TargetElementUtil.findReference(editor);
            if (reference != null) {
                usageElement = reference.getElement();
            }
        }
        AndroidInlineUtil.doInlineLayoutFile(project, (XmlFile) element, usageElement, ourTestConfig);
        return;
    }
    final LayoutUsageData usageData = getLayoutUsageDataFromContext(editor);
    assert usageData != null;
    final AndroidResourceReferenceBase ref = usageData.getReference();
    final PsiElement[] elements = ref.computeTargetElements();
    final ErrorReporter errorReporter = editor != null ? new HintBasedErrorReporter(editor) : new ProjectBasedErrorReporter(project);
    final String title = AndroidBundle.message("android.inline.layout.title");
    if (elements.length == 0) {
        final String resName = ref.getResourceValue().getResourceName();
        final String message = resName != null ? "Cannot find layout '" + resName + "'" : "Error: cannot find the layout";
        errorReporter.report(message, title);
        return;
    }
    if (elements.length > 1) {
        errorReporter.report("Error: unambiguous reference", title);
        return;
    }
    final PsiElement resolvedElement = elements[0];
    if (!(resolvedElement instanceof XmlFile)) {
        errorReporter.report("Cannot inline reference '" + ref.getValue() + "'", title);
        return;
    }
    AndroidInlineUtil.doInlineLayoutFile(project, (XmlFile) resolvedElement, ref.getElement(), ourTestConfig);
}
Also used : HintBasedErrorReporter(org.jetbrains.android.util.HintBasedErrorReporter) ProjectBasedErrorReporter(org.jetbrains.android.util.ProjectBasedErrorReporter) ErrorReporter(org.jetbrains.android.util.ErrorReporter) ProjectBasedErrorReporter(org.jetbrains.android.util.ProjectBasedErrorReporter) XmlFile(com.intellij.psi.xml.XmlFile) AndroidResourceReferenceBase(org.jetbrains.android.dom.converters.AndroidResourceReferenceBase) ResourceElementWrapper(org.jetbrains.android.dom.wrappers.ResourceElementWrapper) PsiReference(com.intellij.psi.PsiReference) HintBasedErrorReporter(org.jetbrains.android.util.HintBasedErrorReporter) PsiElement(com.intellij.psi.PsiElement)

Example 2 with HintBasedErrorReporter

use of org.jetbrains.android.util.HintBasedErrorReporter in project android by JetBrains.

the class AndroidInlineStyleHandler method inlineElement.

@Override
public void inlineElement(Project project, final Editor editor, PsiElement element) {
    final AndroidInlineUtil.MyStyleData data = AndroidInlineUtil.getInlinableStyleDataFromContext(element);
    if (data != null) {
        final ErrorReporter reporter = editor != null ? new HintBasedErrorReporter(editor) : new ProjectBasedErrorReporter(project);
        StyleUsageData usageData = null;
        if (editor != null) {
            final PsiReference reference = TargetElementUtil.findReference(editor);
            if (reference instanceof AndroidResourceReferenceBase) {
                usageData = getUsageDataFromEditor(reference);
            }
        }
        AndroidInlineUtil.doInlineStyleDeclaration(project, data, usageData, reporter, ourTestConfig);
    }
}
Also used : HintBasedErrorReporter(org.jetbrains.android.util.HintBasedErrorReporter) ProjectBasedErrorReporter(org.jetbrains.android.util.ProjectBasedErrorReporter) ErrorReporter(org.jetbrains.android.util.ErrorReporter) ProjectBasedErrorReporter(org.jetbrains.android.util.ProjectBasedErrorReporter) AndroidResourceReferenceBase(org.jetbrains.android.dom.converters.AndroidResourceReferenceBase) PsiReference(com.intellij.psi.PsiReference) HintBasedErrorReporter(org.jetbrains.android.util.HintBasedErrorReporter)

Aggregations

PsiReference (com.intellij.psi.PsiReference)2 AndroidResourceReferenceBase (org.jetbrains.android.dom.converters.AndroidResourceReferenceBase)2 ErrorReporter (org.jetbrains.android.util.ErrorReporter)2 HintBasedErrorReporter (org.jetbrains.android.util.HintBasedErrorReporter)2 ProjectBasedErrorReporter (org.jetbrains.android.util.ProjectBasedErrorReporter)2 PsiElement (com.intellij.psi.PsiElement)1 XmlFile (com.intellij.psi.xml.XmlFile)1 ResourceElementWrapper (org.jetbrains.android.dom.wrappers.ResourceElementWrapper)1