Search in sources :

Example 1 with AntFilesProvider

use of com.intellij.lang.ant.AntFilesProvider in project intellij-community by JetBrains.

the class AntDomDocumentationProvider method getAdditionalDocumentation.

@Nullable
private static String getAdditionalDocumentation(PsiElement elem) {
    final XmlTag xmlTag = PsiTreeUtil.getParentOfType(elem, XmlTag.class);
    if (xmlTag == null) {
        return null;
    }
    final AntDomElement antElement = AntSupport.getAntDomElement(xmlTag);
    if (antElement instanceof AntFilesProvider) {
        final List<File> list = ((AntFilesProvider) antElement).getFiles(new HashSet<>());
        if (list.size() > 0) {
            @NonNls final StringBuilder builder = StringBuilderSpinAllocator.alloc();
            try {
                final XmlTag tag = antElement.getXmlTag();
                if (tag != null) {
                    builder.append("<b>");
                    builder.append(tag.getName());
                    builder.append(":</b>");
                }
                for (File file : list) {
                    if (builder.length() > 0) {
                        builder.append("<br>");
                    }
                    builder.append(file.getPath());
                }
                return builder.toString();
            } finally {
                StringBuilderSpinAllocator.dispose(builder);
            }
        }
    }
    return null;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) AntFilesProvider(com.intellij.lang.ant.AntFilesProvider) AntDomElement(com.intellij.lang.ant.dom.AntDomElement) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with AntFilesProvider

use of com.intellij.lang.ant.AntFilesProvider in project intellij-community by JetBrains.

the class CustomAntElementsRegistry method collectUrls.

public static List<URL> collectUrls(AntDomClasspathElement typedef) {
    boolean cleanupNeeded = false;
    if (!ourIsBuildingClasspathForCustomTagLoading.get()) {
        ourIsBuildingClasspathForCustomTagLoading.set(Boolean.TRUE);
        cleanupNeeded = true;
    }
    try {
        final List<URL> urls = new ArrayList<>();
        // check classpath attribute
        final List<File> cpFiles = typedef.getClasspath().getValue();
        if (cpFiles != null) {
            for (File file : cpFiles) {
                try {
                    urls.add(toLocalURL(file));
                } catch (MalformedURLException ignored) {
                    LOG.info(ignored);
                }
            }
        }
        final HashSet<AntFilesProvider> processed = new HashSet<>();
        final AntDomElement referencedPath = typedef.getClasspathRef().getValue();
        if (referencedPath instanceof AntFilesProvider) {
            for (File cpFile : ((AntFilesProvider) referencedPath).getFiles(processed)) {
                try {
                    urls.add(toLocalURL(cpFile));
                } catch (MalformedURLException ignored) {
                    LOG.info(ignored);
                }
            }
        }
        for (final Iterator<AntDomElement> it = typedef.getAntChildrenIterator(); it.hasNext(); ) {
            AntDomElement child = it.next();
            if (child instanceof AntFilesProvider) {
                for (File cpFile : ((AntFilesProvider) child).getFiles(processed)) {
                    try {
                        urls.add(toLocalURL(cpFile));
                    } catch (MalformedURLException ignored) {
                        LOG.info(ignored);
                    }
                }
            }
        }
        return urls;
    } finally {
        if (cleanupNeeded) {
            ourIsBuildingClasspathForCustomTagLoading.remove();
        }
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) AntFilesProvider(com.intellij.lang.ant.AntFilesProvider) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) XmlFile(com.intellij.psi.xml.XmlFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) URL(java.net.URL)

Aggregations

AntFilesProvider (com.intellij.lang.ant.AntFilesProvider)2 PsiFile (com.intellij.psi.PsiFile)2 File (java.io.File)2 AntDomElement (com.intellij.lang.ant.dom.AntDomElement)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlTag (com.intellij.psi.xml.XmlTag)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 NonNls (org.jetbrains.annotations.NonNls)1 Nullable (org.jetbrains.annotations.Nullable)1