本文整理匯總了Java中com.intellij.psi.PsiFile.getParent方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiFile.getParent方法的具體用法?Java PsiFile.getParent怎麽用?Java PsiFile.getParent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.PsiFile
的用法示例。
在下文中一共展示了PsiFile.getParent方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getDirectory
import com.intellij.psi.PsiFile; //導入方法依賴的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: buildUrnKeyForFile
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Nullable
private String buildUrnKeyForFile(@NotNull PsiFile psiFile, @NotNull MagentoComponent magentoComponent) {
String prefix = null;
if (magentoComponent instanceof MagentoModule) {
prefix = MODULE + ((MagentoModule)magentoComponent).getMagentoName() + ":";
} else {
ComposerPackageModel composerPackageModel = magentoComponent.getComposerModel();
if ("magento2-library".equals(composerPackageModel.getType())) {
prefix = FRAMEWORK;
}
}
if (prefix == null) {
return null;
}
Stack<String> relativePath = new Stack<>();
relativePath.push(psiFile.getName());
PsiManager psiManager = magentoComponent.getDirectory().getManager();
PsiDirectory parentDir = psiFile.getParent();
while (parentDir != null && !psiManager.areElementsEquivalent(parentDir, magentoComponent.getDirectory())) {
relativePath.push("/");
relativePath.push(parentDir.getName());
parentDir = parentDir.getParentDirectory();
}
StringBuilder stringBuilder = new StringBuilder(prefix);
while (!relativePath.empty()) {
stringBuilder.append(relativePath.pop());
}
return stringBuilder.toString();
}