Search in sources :

Example 1 with FileIncludeInfo

use of com.intellij.psi.impl.include.FileIncludeInfo in project intellij-community by JetBrains.

the class RelaxIncludeProvider method getIncludeInfos.

@NotNull
@Override
public FileIncludeInfo[] getIncludeInfos(FileContent content) {
    final ArrayList<FileIncludeInfo> infos;
    if (content.getFileType() == XmlFileType.INSTANCE) {
        CharSequence inputDataContentAsText = content.getContentAsText();
        if (CharArrayUtil.indexOf(inputDataContentAsText, ApplicationLoader.RNG_NAMESPACE, 0) == -1)
            return FileIncludeInfo.EMPTY;
        infos = new ArrayList<>();
        NanoXmlUtil.parse(CharArrayUtil.readerFromCharSequence(content.getContentAsText()), new RngBuilderAdapter(infos));
    } else if (content.getFileType() == RncFileType.getInstance()) {
        infos = new ArrayList<>();
        content.getPsiFile().acceptChildren(new RncElementVisitor() {

            @Override
            public void visitElement(RncElement element) {
                element.acceptChildren(this);
            }

            @Override
            public void visitInclude(RncInclude include) {
                final String path = include.getFileReference();
                if (path != null) {
                    infos.add(new FileIncludeInfo(path));
                }
            }
        });
    } else {
        return FileIncludeInfo.EMPTY;
    }
    return infos.toArray(new FileIncludeInfo[infos.size()]);
}
Also used : RncElementVisitor(org.intellij.plugins.relaxNG.compact.psi.RncElementVisitor) FileIncludeInfo(com.intellij.psi.impl.include.FileIncludeInfo) RncInclude(org.intellij.plugins.relaxNG.compact.psi.RncInclude) ArrayList(java.util.ArrayList) RncElement(org.intellij.plugins.relaxNG.compact.psi.RncElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with FileIncludeInfo

use of com.intellij.psi.impl.include.FileIncludeInfo in project intellij-community by JetBrains.

the class XsltIncludeProvider method getIncludeInfos.

@NotNull
public FileIncludeInfo[] getIncludeInfos(FileContent content) {
    CharSequence contentAsText = content.getContentAsText();
    if (CharArrayUtil.indexOf(contentAsText, XsltSupport.XSLT_NS, 0) == -1)
        return FileIncludeInfo.EMPTY;
    final ArrayList<FileIncludeInfo> infos = new ArrayList<>();
    NanoXmlUtil.IXMLBuilderAdapter builder = new NanoXmlUtil.IXMLBuilderAdapter() {

        boolean isXslt;

        boolean isInclude;

        @Override
        public void startElement(String name, String nsPrefix, String nsURI, String systemID, int lineNr) throws Exception {
            boolean isXsltTag = XsltSupport.XSLT_NS.equals(nsURI);
            if (!isXslt) {
                // analyzing start tag
                if (!isXsltTag) {
                    stop();
                } else {
                    isXslt = true;
                }
            }
            isInclude = isXsltTag && ("include".equals(name) || "import".equals(name));
        }

        @Override
        public void addAttribute(String key, String nsPrefix, String nsURI, String value, String type) throws Exception {
            if (isInclude && "href".equals(key)) {
                infos.add(new FileIncludeInfo(value));
            }
        }

        @Override
        public void endElement(String name, String nsPrefix, String nsURI) throws Exception {
            isInclude = false;
        }
    };
    NanoXmlUtil.parse(CharArrayUtil.readerFromCharSequence(contentAsText), builder);
    return infos.toArray(new FileIncludeInfo[infos.size()]);
}
Also used : FileIncludeInfo(com.intellij.psi.impl.include.FileIncludeInfo) ArrayList(java.util.ArrayList) NanoXmlUtil(com.intellij.util.xml.NanoXmlUtil) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with FileIncludeInfo

use of com.intellij.psi.impl.include.FileIncludeInfo in project intellij-community by JetBrains.

the class FilePathResolveTest method testResolveFileReference.

public void testResolveFileReference() throws Exception {
    configureByFile(BASE_PATH + "C.java", BASE_PATH);
    FileIncludeManager fileIncludeManager = FileIncludeManager.getManager(getProject());
    PsiFileSystemItem item = fileIncludeManager.resolveFileInclude(new FileIncludeInfo("x/MyFile.txt"), getFile());
    assertNotNull(item);
    assertEquals("MyFile.txt", item.getName());
}
Also used : FileIncludeInfo(com.intellij.psi.impl.include.FileIncludeInfo) FileIncludeManager(com.intellij.psi.impl.include.FileIncludeManager) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem)

Example 4 with FileIncludeInfo

use of com.intellij.psi.impl.include.FileIncludeInfo in project intellij-plugins by JetBrains.

the class DartPackageAwareFileIncludeProvider method getIncludeInfos.

private static FileIncludeInfo[] getIncludeInfos(@NotNull final XmlFile xmlFile) {
    final List<FileIncludeInfo> result = new ArrayList<>();
    xmlFile.acceptChildren(new XmlRecursiveElementVisitor() {

        @Override
        public void visitXmlTag(XmlTag tag) {
            final String path = "link".equalsIgnoreCase(tag.getName()) ? getPathRelativeToPackageRoot(tag.getAttributeValue("href")) : "script".equalsIgnoreCase(tag.getName()) ? getPathRelativeToPackageRoot(tag.getAttributeValue("src")) : null;
            if (!StringUtil.isEmptyOrSpaces(path)) {
                result.add(new FileIncludeInfo(path));
            }
            super.visitXmlTag(tag);
        }

        @Override
        public void visitElement(PsiElement element) {
            if (element.getLanguage() instanceof XMLLanguage) {
                super.visitElement(element);
            }
        }
    });
    return ContainerUtil.toArray(result, FileIncludeInfo.EMPTY);
}
Also used : FileIncludeInfo(com.intellij.psi.impl.include.FileIncludeInfo) XmlRecursiveElementVisitor(com.intellij.psi.XmlRecursiveElementVisitor) ArrayList(java.util.ArrayList) XMLLanguage(com.intellij.lang.xml.XMLLanguage) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

FileIncludeInfo (com.intellij.psi.impl.include.FileIncludeInfo)4 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)2 XMLLanguage (com.intellij.lang.xml.XMLLanguage)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)1 XmlRecursiveElementVisitor (com.intellij.psi.XmlRecursiveElementVisitor)1 FileIncludeManager (com.intellij.psi.impl.include.FileIncludeManager)1 XmlTag (com.intellij.psi.xml.XmlTag)1 NanoXmlUtil (com.intellij.util.xml.NanoXmlUtil)1 RncElement (org.intellij.plugins.relaxNG.compact.psi.RncElement)1 RncElementVisitor (org.intellij.plugins.relaxNG.compact.psi.RncElementVisitor)1 RncInclude (org.intellij.plugins.relaxNG.compact.psi.RncInclude)1