use of org.jetbrains.android.util.ProjectBasedErrorReporter in project android by JetBrains.
the class AndroidInlineStyleReferenceAction 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 StyleUsageData usageData = AndroidInlineUtil.getStyleUsageData(tag);
if (usageData == null) {
return;
}
final AndroidResourceReferenceBase reference = usageData.getReference();
final String title = AndroidBundle.message("android.inline.style.title");
final PsiElement[] styleElements = reference.computeTargetElements();
if (styleElements.length == 0) {
AndroidUtils.reportError(project, "Cannot find style by reference '" + reference.getValue() + "'", title);
return;
}
if (styleElements.length > 1) {
AndroidUtils.reportError(project, RefactoringBundle.getCannotRefactorMessage("Unambiguous style reference."), title);
return;
}
final PsiElement styleElement = styleElements[0];
final XmlTag styleTag = PsiTreeUtil.getParentOfType(styleElement, XmlTag.class);
final DomElement domElement = styleTag != null ? DomManager.getDomManager(project).getDomElement(styleTag) : null;
if (!(domElement instanceof Style)) {
AndroidUtils.reportError(project, "Cannot find style by reference '" + reference.getValue() + "'", title);
return;
}
final Style style = (Style) domElement;
String styleName = style.getName().getStringValue();
if (styleName == null) {
AndroidUtils.reportError(project, RefactoringBundle.getCannotRefactorMessage("Style name is not specified."), title);
return;
}
AndroidInlineUtil.doInlineStyleDeclaration(project, new AndroidInlineUtil.MyStyleData(styleName, style, styleElement), usageData, new ProjectBasedErrorReporter(project), myTestConfig);
}
use of org.jetbrains.android.util.ProjectBasedErrorReporter in project android by JetBrains.
the class AndroidFindStyleApplicationsAction method createFindStyleApplicationsProcessor.
public static AndroidFindStyleApplicationsProcessor createFindStyleApplicationsProcessor(XmlTag tag, MyStyleData styleData, PsiFile context) {
final ErrorReporter errorReporter = new ProjectBasedErrorReporter(tag.getProject());
final Style style = styleData.getStyle();
final Map<AndroidAttributeInfo, String> attrMap = AndroidRefactoringUtil.computeAttributeMap(style, new ProjectBasedErrorReporter(tag.getProject()), AndroidBundle.message("android.find.style.applications.title"));
if (attrMap == null || attrMap.size() == 0) {
return null;
}
final AndroidFacet facet = styleData.getFacet();
final StyleRefData parentStyleRef = AndroidRefactoringUtil.getParentStyle(style);
PsiElement parentStyleAttrName = null;
if (parentStyleRef != null) {
parentStyleAttrName = resolveStyleRef(parentStyleRef, facet);
if (parentStyleAttrName == null) {
errorReporter.report("Cannot resolve parent style '" + parentStyleRef.getStyleName() + "'", AndroidBundle.message("android.find.style.applications.title"));
return null;
}
}
return new AndroidFindStyleApplicationsProcessor(styleData.getFacet().getModule(), attrMap, styleData.getName(), tag, styleData.getNameAttrValue(), parentStyleAttrName, context);
}
use of org.jetbrains.android.util.ProjectBasedErrorReporter 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);
}
use of org.jetbrains.android.util.ProjectBasedErrorReporter 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);
}
}
Aggregations