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()); }
@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<FileIncludeInfo>(); NanoXmlUtil.parse(CharArrayUtil.readerFromCharSequence(content.getContentAsText()), new RngBuilderAdapter(infos)); } else if (content.getFileType() == RncFileType.getInstance()) { infos = new ArrayList<FileIncludeInfo>(); 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()]); }
@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()]); }
public RngBuilderAdapter(ArrayList<FileIncludeInfo> infos) { myInfos = infos; }
@Override public void addAttribute(String key, String nsPrefix, String nsURI, String value, String type) throws Exception { if (isInclude && "href".equals(key)) { myInfos.add(new FileIncludeInfo(value)); } }