use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class AntDomDocumentationProvider method getHelpFile.
@Nullable
private static VirtualFile getHelpFile(AntDomElement antElement, final VirtualFile documentationRoot) {
final XmlTag xmlTag = antElement.getXmlTag();
if (xmlTag == null) {
return null;
}
@NonNls final String helpFileShortName = "/" + xmlTag.getName() + ".html";
for (String folderName : DOC_FOLDER_NAMES) {
final VirtualFile candidateHelpFile = documentationRoot.findFileByRelativePath(folderName + helpFileShortName);
if (candidateHelpFile != null) {
return candidateHelpFile;
}
}
if (antElement instanceof AntDomTarget || antElement instanceof AntDomProject) {
final VirtualFile candidateHelpFile = documentationRoot.findFileByRelativePath("using.html");
if (candidateHelpFile != null) {
return candidateHelpFile;
}
}
return null;
}
use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class RunTargetAction method findAntTarget.
@Nullable
private static Pair<AntBuildFileBase, AntDomTarget> findAntTarget(@NotNull AnActionEvent e) {
final Editor editor = e.getData(CommonDataKeys.EDITOR);
final Project project = e.getProject();
if (project == null || editor == null) {
return null;
}
final VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
if (file == null) {
return null;
}
final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
if (!(psiFile instanceof XmlFile)) {
return null;
}
final XmlFile xmlFile = (XmlFile) psiFile;
final AntBuildFileBase antFile = AntConfigurationBase.getInstance(project).getAntBuildFile(xmlFile);
if (antFile == null) {
return null;
}
final PsiElement element = xmlFile.findElementAt(editor.getCaretModel().getOffset());
if (element == null) {
return null;
}
final XmlTag xmlTag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
if (xmlTag == null) {
return null;
}
DomElement dom = AntSupport.getAntDomElement(xmlTag);
while (dom != null && !(dom instanceof AntDomTarget)) {
dom = dom.getParent();
}
final AntDomTarget domTarget = (AntDomTarget) dom;
if (domTarget == null) {
return null;
}
return Pair.create(antFile, domTarget);
}
use of com.intellij.lang.ant.dom.AntDomTarget in project intellij-community by JetBrains.
the class AntCreateTargetFix method applyFix.
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);
}
}
Aggregations