VirtualFile (VirtualFile javaFile) { if (javaFile.isDirectory()) return null; CharSequence chars = LoadTextUtil.loadText(javaFile); String packageName = JavaSourceRootDetectionUtil.getPackageName(chars); if (packageName != null){ VirtualFile root = javaFile.getParent(); int index = packageName.length(); while(index > 0){ int index1 = packageName.lastIndexOf('.', index - 1); String token = packageName.substring(index1 + 1, index); String dirName = root.getName(); final boolean equalsToToken = javaFile.isCaseSensitive() ? dirName.equals(token) : dirName.equalsIgnoreCase(token); if (!equalsToToken) { return null; } root = root.getParent(); if (root == null){ return null; } index = index1; } return root; } return null; }