本文整理匯總了Java中com.intellij.psi.PsiFile.getContainingDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiFile.getContainingDirectory方法的具體用法?Java PsiFile.getContainingDirectory怎麽用?Java PsiFile.getContainingDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.psi.PsiFile
的用法示例。
在下文中一共展示了PsiFile.getContainingDirectory方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: resolveImportReference
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Nullable
public PsiElement resolveImportReference(QualifiedName name, PyQualifiedNameResolveContext context, boolean withRoots) {
if (StudyTaskManager.getInstance(context.getProject()).getCourse() == null) {
return null;
}
final String nameString = name.toString();
PsiFile containingFile = context.getFootholdFile();
if (containingFile == null) return null;
final PsiDirectory directory = containingFile.getContainingDirectory();
if (directory == null) return null;
final PsiFile file = directory.findFile(nameString + ".py");
if (file != null) {
return file;
}
return null;
}
示例2: performAnswerPlaceholderAction
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
protected void performAnswerPlaceholderAction(@NotNull CCState state) {
final Project project = state.getProject();
PsiFile file = state.getFile();
final PsiDirectory taskDir = file.getContainingDirectory();
final PsiDirectory lessonDir = taskDir.getParent();
if (lessonDir == null) return;
AnswerPlaceholder answerPlaceholder = state.getAnswerPlaceholder();
if (answerPlaceholder == null) {
return;
}
CCCreateAnswerPlaceholderDialog dlg = new CCCreateAnswerPlaceholderDialog(project, answerPlaceholder.getTaskText(), answerPlaceholder.getHints());
dlg.setTitle("Edit Answer Placeholder");
if (dlg.showAndGet()) {
final String answerPlaceholderText = dlg.getTaskText();
answerPlaceholder.setTaskText(answerPlaceholderText);
answerPlaceholder.setLength(answerPlaceholder.getActiveSubtaskInfo().isNeedInsertText() ? 0 : StringUtil.notNullize(answerPlaceholderText).length());
answerPlaceholder.setHints(dlg.getHints());
}
}
示例3: loadModules
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
private void loadModules() {
Collection<String> packages = FileBasedIndex.getInstance().getAllKeys(ModulePackageIndex.KEY, this.project);
PsiManager psiManager = PsiManager.getInstance(this.project);
for (String packageName: packages) {
if (components.containsKey(packageName)) {
continue;
}
Collection<VirtualFile> containingFiles = FileBasedIndex.getInstance()
.getContainingFiles(ModulePackageIndex.KEY, packageName, GlobalSearchScope.allScope(this.project));
if (containingFiles.size() > 0) {
VirtualFile configurationFile = containingFiles.iterator().next();
PsiFile psiFile = psiManager.findFile(configurationFile);
if (psiFile != null && psiFile instanceof JsonFile) {
JsonObject jsonObject = PsiTreeUtil.getChildOfType((JsonFile) psiFile, JsonObject.class);
if (jsonObject == null) {
continue;
}
MagentoComponent magentoComponent;
ComposerPackageModel composerPackageModel = new ComposerPackageModelImpl(jsonObject);
if ("magento2-module".equals(composerPackageModel.getType())) {
magentoComponent = new MagentoModuleImpl(new ComposerPackageModelImpl(jsonObject), psiFile.getContainingDirectory());
} else {
magentoComponent = new MagentoComponentImp(new ComposerPackageModelImpl(jsonObject), psiFile.getContainingDirectory());
}
components.put(
packageName,
magentoComponent
);
}
}
}
}
示例4: getAppDirectoryFromFile
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Nullable
public static PsiDirectory getAppDirectoryFromFile(@NotNull PsiFile file) {
PsiDirectory dir = file.getContainingDirectory();
while (dir != null) {
if (dir.getName().equals("app")) {
return dir;
}
dir = dir.getParent();
}
return null;
}
示例5: tryToRenameTaskFile
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
private static void tryToRenameTaskFile(PsiFile file, String oldName) {
final PsiDirectory taskDir = file.getContainingDirectory();
final Project project = file.getProject();
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
return;
}
PsiDirectory lessonDir = taskDir.getParent();
if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
return;
}
Lesson lesson = course.getLesson(lessonDir.getName());
if (lesson == null) {
return;
}
Task task = lesson.getTask(taskDir.getName());
if (task == null) {
return;
}
Map<String, TaskFile> taskFiles = task.getTaskFiles();
TaskFile taskFile = task.getTaskFile(oldName);
if (taskFile == null) {
return;
}
taskFiles.remove(oldName);
taskFiles.put(StudyUtils.pathRelativeToTask(file.getVirtualFile()), taskFile);
}
示例6: bindToElement
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public PsiElement bindToElement(@NotNull PsiElement element) throws IncorrectOperationException {
final StringLiteralExpression string = (StringLiteralExpression) this.getElement();
final PsiDirectory context = ViewsUtil.getContextDirectory(string);
final PsiFile file = (PsiFile) element;
final PsiElement newValue;
String fileName = string.getContents();
if (fileName.contains("/")) {
fileName = fileName.substring(fileName.lastIndexOf('/') + 1);
}
if (!file.getContainingDirectory().equals(context)) {
final PsiDirectory root = ViewsUtil.getRootDirectory(string);
if (root == null) {
return null;
}
PsiDirectory dir = file.getContainingDirectory();
while (dir != null && !(dir.equals(root) || dir.equals(context))) {
fileName = dir.getName() + "/" + fileName;
dir = dir.getParent();
}
if (dir == null) {
return null;
}
if (dir.equals(root)) {
fileName = "/" + fileName;
}
}
fileName = string.isSingleQuote() ? "'" + fileName + "'" : "\"" + fileName + "\"";
newValue = PhpPsiElementFactory.createFromText(element.getProject(), StringLiteralExpression.class, fileName);
if (newValue != null) {
string.replace(newValue);
}
for (MethodReference reference : PsiTreeUtil.findChildrenOfType(file, MethodReference.class)) {
if (reference.getName() != null && ArrayUtil.contains(reference.getName(), ViewsUtil.renderMethods)) {
reference.putUserData(ViewsUtil.RENDER_VIEW_FILE, null);
}
}
return newValue;
}
示例7: actionPerformed
import com.intellij.psi.PsiFile; //導入方法依賴的package包/類
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
Module module = LangDataKeys.MODULE.getData(e.getDataContext());
if (project == null || module == null) {
return;
}
final PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext());
if (file == null) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
VirtualFile virtualFile = file.getVirtualFile();
TaskFile taskFile = StudyUtils.getTaskFile(project, virtualFile);
if (taskFile == null) {
return;
}
final PsiDirectory taskDir = file.getContainingDirectory();
if (taskDir == null) {
return;
}
PsiDirectory lessonDir = taskDir.getParentDirectory();
if (lessonDir == null) {
return;
}
if (taskFile.getActivePlaceholders().isEmpty()) {
Messages.showInfoMessage("Preview is available for task files with answer placeholders only", "No Preview for This File");
return;
}
final Task task = taskFile.getTask();
ApplicationManager.getApplication().runWriteAction(() -> {
TaskFile studentTaskFile = EduUtils.createStudentFile(project, virtualFile, task.copy(),
task instanceof TaskWithSubtasks ? ((TaskWithSubtasks)task).getActiveSubtaskIndex() : 0);
if (studentTaskFile != null) {
showPreviewDialog(project, studentTaskFile);
}
});
}