mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-143512 Android: "Define attribute" quick fix inserts required xml attributes without "android:" namespace
This commit is contained in:
@@ -24,7 +24,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -33,9 +32,15 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class DefineAttributeQuickFix implements LocalQuickFix {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.spring.model.highlighting.DefineAttributeQuickFix");
|
||||
private final String myAttrName;
|
||||
private final String myNamespace;
|
||||
|
||||
public DefineAttributeQuickFix(@NonNls final String attrName) {
|
||||
public DefineAttributeQuickFix(String attrName) {
|
||||
this(attrName, "");
|
||||
}
|
||||
|
||||
public DefineAttributeQuickFix(@NotNull final String attrName, @NotNull String namespace) {
|
||||
myAttrName = attrName;
|
||||
myNamespace = namespace;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -52,7 +57,7 @@ public class DefineAttributeQuickFix implements LocalQuickFix {
|
||||
try {
|
||||
final XmlTag tag = (XmlTag)descriptor.getPsiElement();
|
||||
if (!FileModificationService.getInstance().preparePsiElementForWrite(descriptor.getPsiElement().getContainingFile())) return;
|
||||
final XmlAttribute attribute = tag.setAttribute(myAttrName, "", "");
|
||||
final XmlAttribute attribute = tag.setAttribute(myAttrName, myNamespace, "");
|
||||
new OpenFileDescriptor(project, tag.getContainingFile().getVirtualFile(),
|
||||
attribute.getValueElement().getTextRange().getStartOffset() + 1).navigate(true);
|
||||
}
|
||||
|
||||
@@ -69,17 +69,17 @@ public class DomHighlightingHelperImpl extends DomHighlightingHelper {
|
||||
if (xmlElement == null) {
|
||||
if (required.value()) {
|
||||
final String xmlElementName = element.getXmlElementName();
|
||||
String namespace = element.getXmlElementNamespace();
|
||||
if (element instanceof GenericAttributeValue) {
|
||||
return Collections.singletonList(holder
|
||||
.createProblem(element, IdeBundle.message("attribute.0.should.be.defined", xmlElementName),
|
||||
new DefineAttributeQuickFix(xmlElementName)));
|
||||
return Collections.singletonList(holder.createProblem(element, IdeBundle.message("attribute.0.should.be.defined", xmlElementName),
|
||||
new DefineAttributeQuickFix(xmlElementName, namespace)));
|
||||
}
|
||||
return Collections.singletonList(
|
||||
holder.createProblem(
|
||||
element,
|
||||
HighlightSeverity.ERROR,
|
||||
IdeBundle.message("child.tag.0.should.be.defined", xmlElementName),
|
||||
new AddRequiredSubtagFix(xmlElementName, element.getXmlElementNamespace())
|
||||
new AddRequiredSubtagFix(xmlElementName, namespace)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user