Search in sources :

Example 6 with AntDomTarget

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;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) XmlTag(com.intellij.psi.xml.XmlTag) AntDomProject(com.intellij.lang.ant.dom.AntDomProject) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with AntDomTarget

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AntBuildFileBase(com.intellij.lang.ant.config.AntBuildFileBase) DomElement(com.intellij.util.xml.DomElement) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with AntDomTarget

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);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) AntDomTarget(com.intellij.lang.ant.dom.AntDomTarget) PsiElement(com.intellij.psi.PsiElement) Navigatable(com.intellij.pom.Navigatable) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)8 PsiFile (com.intellij.psi.PsiFile)5 XmlTag (com.intellij.psi.xml.XmlTag)4 DomElement (com.intellij.util.xml.DomElement)4 Nullable (org.jetbrains.annotations.Nullable)4 AntDomProject (com.intellij.lang.ant.dom.AntDomProject)3 PsiElement (com.intellij.psi.PsiElement)3 XmlFile (com.intellij.psi.xml.XmlFile)3 AntBuildFileBase (com.intellij.lang.ant.config.AntBuildFileBase)2 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)2 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Navigatable (com.intellij.pom.Navigatable)2 FileModificationService (com.intellij.codeInsight.FileModificationService)1 AntDomRecursiveVisitor (com.intellij.lang.ant.dom.AntDomRecursiveVisitor)1 TargetResolver (com.intellij.lang.ant.dom.TargetResolver)1 IProperty (com.intellij.lang.properties.IProperty)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 Editor (com.intellij.openapi.editor.Editor)1 Project (com.intellij.openapi.project.Project)1