private static boolean findInFile(VirtualFile root, final StringTokenizer filePath) { if (!filePath.hasMoreTokens()) return true; @NonNls String name = filePath.nextToken(); if (!filePath.hasMoreTokens()) { name += ".class"; } final VirtualFile child = root.findChild(name); return child != null && findInFile(child, filePath); }
public void readExternal(Element element) throws InvalidDataException { proportions.clear(); String prop = element.getAttributeValue(ATTRIBUTE_PROPORTIONS); String version = element.getAttributeValue(ATTRIBUTE_VERSION); if (prop != null && Comparing.equal(version, DATA_VERSION)) { StringTokenizer tokenizer = new StringTokenizer(prop, ","); while (tokenizer.hasMoreTokens()) { String p = tokenizer.nextToken(); proportions.add(Float.valueOf(p)); } } }
public static List<VirtualFile> findSuitableFilesFor( final String filePath, final Project project) { final ProjectFileIndex index = ProjectRootManager.getInstance(project).getFileIndex(); // at first let's try to find file as is, by it's real path // and check that file belongs to current project // this location provider designed for tests thus we will check only project content // (we cannot check just sources or tests folders because RM doesn't use it final VirtualFile file = getByFullPath(filePath); final boolean inProjectContent = file != null && (index.isInContent(file)); if (inProjectContent) { return Collections.singletonList(file); } // split file by "/" in parts final LinkedList<String> folders = new LinkedList<String>(); final StringTokenizer st = new StringTokenizer(filePath, "/", false); String fileName = null; while (st.hasMoreTokens()) { final String pathComponent = st.nextToken(); if (st.hasMoreTokens()) { folders.addFirst(pathComponent); } else { // last token fileName = pathComponent; } } if (fileName == null) { return Collections.emptyList(); } final List<VirtualFile> target = findFilesClosestToTarget( folders, collectCandidates(project, fileName, true), MIN_PROXIMITY_THRESHOLD); return target.isEmpty() && file != null ? Collections.singletonList(file) : target; }