IDEA-143512 Android: "Define attribute" quick fix inserts required xml attributes without "android:" namespace

This commit is contained in:
peter
2015-08-05 21:18:37 +02:00
parent 63fbd088d7
commit 1ebb9d48e6
2 changed files with 12 additions and 7 deletions
@@ -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)
)
);
}