mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-116929 [regression] Ant: after rewriting to DOM API create target quick fix is missing
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.lang.ant.AntBundle;
|
||||
import com.intellij.lang.ant.AntSupport;
|
||||
import com.intellij.lang.ant.quickfix.AntChangeContextLocalFix;
|
||||
import com.intellij.lang.ant.quickfix.AntCreatePropertyFix;
|
||||
import com.intellij.lang.ant.quickfix.AntCreateTargetFix;
|
||||
import com.intellij.lang.ant.validation.AntInspection;
|
||||
import com.intellij.lang.properties.psi.PropertiesFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
@@ -126,6 +127,9 @@ public class AntResolveInspection extends AntInspection {
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (ref instanceof AntDomTargetReference) {
|
||||
quickFixList.add(new AntCreateTargetFix(ref.getCanonicalText()));
|
||||
}
|
||||
|
||||
holder.createProblem(
|
||||
domElement,
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.lang.ant.quickfix;
|
||||
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.lang.ant.AntBundle;
|
||||
import com.intellij.lang.ant.dom.AntDomTarget;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.xml.XmlFile;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.util.xml.DomElement;
|
||||
import com.intellij.util.xml.DomUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AntCreateTargetFix implements LocalQuickFix {
|
||||
private static final String TAG_NAME = "target";
|
||||
private static final String NAME_ATTR = "name";
|
||||
private final String myCanonicalText;
|
||||
|
||||
public AntCreateTargetFix(String canonicalText) {
|
||||
myCanonicalText = canonicalText;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return AntBundle.message("ant.create.target.intention.description", myCanonicalText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getFamilyName() {
|
||||
return AntBundle.message("ant.intention.create.target.family.name");
|
||||
}
|
||||
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
final PsiElement psiElement = descriptor.getPsiElement();
|
||||
final PsiFile containingFile = psiElement.getContainingFile();
|
||||
|
||||
|
||||
Navigatable result = null;
|
||||
if (containingFile instanceof XmlFile) {
|
||||
final XmlFile xmlFile = (XmlFile)containingFile;
|
||||
final XmlTag rootTag = xmlFile.getRootTag();
|
||||
if (rootTag != null) {
|
||||
final XmlTag propTag = rootTag.createChildTag(TAG_NAME, rootTag.getNamespace(), "", false);
|
||||
propTag.setAttribute(NAME_ATTR, myCanonicalText);
|
||||
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
|
||||
PsiElement generated;
|
||||
if (contextElement == null) {
|
||||
generated = rootTag.addSubTag(propTag, true);
|
||||
}
|
||||
else {
|
||||
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
|
||||
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
|
||||
final XmlTag tag = anchor.getXmlTag();
|
||||
if (!rootTag.equals(tag)) {
|
||||
generated = tag.getParent().addBefore(propTag, tag);
|
||||
}
|
||||
else {
|
||||
generated = rootTag.addSubTag(propTag, true);
|
||||
}
|
||||
}
|
||||
if (generated instanceof XmlTag) {
|
||||
result = new OpenFileDescriptor(project, containingFile.getVirtualFile(), ((XmlTag)generated).getValue().getTextRange().getEndOffset());
|
||||
}
|
||||
if (result == null && generated instanceof Navigatable) {
|
||||
result = (Navigatable)generated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (result != null) {
|
||||
result.navigate(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user