本文整理汇总了Java中com.intellij.psi.PsiDirectory.getSubdirectories方法的典型用法代码示例。如果您正苦于以下问题:Java PsiDirectory.getSubdirectories方法的具体用法?Java PsiDirectory.getSubdirectories怎么用?Java PsiDirectory.getSubdirectories使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.psi.PsiDirectory
的用法示例。
在下文中一共展示了PsiDirectory.getSubdirectories方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDirectory
import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Nullable
private static PsiDirectory getDirectory(PsiElement element) {
PsiFile file = element.getContainingFile().getOriginalFile();
String filename = file.getName();
PsiDirectory directory = file.getParent();
filename = filename.substring(0, filename.lastIndexOf("."));
if (directory != null) {
if (filename.endsWith("Controller")) {
directory = directory.getParentDirectory();
} else {
PsiDirectory messageParent = directory.findSubdirectory("messages");
while (messageParent == null) {
directory = directory.getParentDirectory();
if (directory == null) {
break;
}
messageParent = directory.findSubdirectory("messages");
}
}
}
if (directory != null) {
directory = directory.findSubdirectory("messages");
if (directory != null && directory.getSubdirectories().length > 0) {
directory = directory.getSubdirectories()[0];
return directory;
}
}
return null;
}
示例2: addCompletions
import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
protected void addCompletions(@NotNull CompletionParameters completionParameters, ProcessingContext processingContext, @NotNull CompletionResultSet completionResultSet) {
final PsiElement psiElement = completionParameters.getPosition();
final MethodReference method = PsiTreeUtil.getParentOfType(psiElement, MethodReference.class);
if (method == null || method.getParameters().length == 0) {
return;
}
if (!ViewsUtil.isValidRenderMethod(method)) {
return;
}
PsiElement parameter = psiElement;
while (parameter != null && !(parameter.getParent() instanceof ParameterList)) {
parameter = parameter.getParent();
}
if (parameter == null || !parameter.equals(method.getParameters()[0])) {
return;
}
String path = getValue(method.getParameters()[0]);
PsiDirectory directory;
if (path.startsWith("/")) {
path = path.substring(1);
directory = ViewsUtil.getRootDirectory(psiElement);
} else {
directory = ViewsUtil.getContextDirectory(psiElement);
}
if (path.contains("/")) {
path = path.substring(0, path.lastIndexOf('/') + 1);
}
while (path.contains("/") && directory != null) {
String subdirectory = path.substring(0, path.indexOf('/'));
path = path.substring(path.indexOf('/') + 1);
directory = subdirectory.equals("..") ? directory.getParent() : directory.findSubdirectory(subdirectory);
}
if (directory != null) {
if (completionResultSet.getPrefixMatcher().getPrefix().contains("/")) {
String prefix = completionResultSet.getPrefixMatcher().getPrefix();
prefix = prefix.substring(prefix.lastIndexOf("/") + 1);
completionResultSet = completionResultSet.withPrefixMatcher(prefix);
}
for (PsiDirectory psiDirectory : directory.getSubdirectories()) {
completionResultSet.addElement(new DirectoryLookupElement(psiDirectory));
}
for (PsiFile psiFile : directory.getFiles()) {
completionResultSet.addElement(new ViewLookupElement(psiFile));
}
}
}