當前位置: 首頁>>代碼示例>>Java>>正文


Java PsiDirectory.getParentDirectory方法代碼示例

本文整理匯總了Java中com.intellij.psi.PsiDirectory.getParentDirectory方法的典型用法代碼示例。如果您正苦於以下問題:Java PsiDirectory.getParentDirectory方法的具體用法?Java PsiDirectory.getParentDirectory怎麽用?Java PsiDirectory.getParentDirectory使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.intellij.psi.PsiDirectory的用法示例。


在下文中一共展示了PsiDirectory.getParentDirectory方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findDirectory

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
@Nullable
private static PsiDirectory findDirectory(PsiElement element) {
    final PhpClass phpClass = PsiTreeUtil.getParentOfType(element, PhpClass.class);
    final PsiFile file = element.getContainingFile();
    if (phpClass != null) {
        return findClassDirectory(phpClass, file);
    }

    PsiDirectory context = file.getOriginalFile().getContainingDirectory();
    if (context != null) {
        PsiDirectory root = context.getParentDirectory();
        while (root != null && !root.getName().equals("views")) {
            root = root.getParentDirectory();
        }

        file.putUserData(VIEWS_CONTEXT_DIRECTORY, context);
        file.putUserData(VIEWS_DIRECTORY, root);
        file.putUserData(VIEWS_DIRECTORY_MODIFIED, file.getModificationStamp());

        return root;
    }

    return null;
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:25,代碼來源:ViewsUtil.java

示例2: findResourcesDirectory

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
/**
 * 根據選擇的package目錄,找到resources目錄
 * @param psiDirectory
 * @return
 */
private PsiDirectory findResourcesDirectory(PsiDirectory psiDirectory) {

    PsiDirectory parentDirectory = psiDirectory.getParentDirectory();
    PsiDirectory iterator = psiDirectory.getParentDirectory();

    while (iterator != null && !iterator.getName().equals("main")) {
        iterator = iterator.getParentDirectory();
    }

    PsiDirectory resourcesDirectory = iterator == null ? null : iterator.findSubdirectory("resources");
    if (resourcesDirectory == null) {
        resourcesDirectory = parentDirectory.findSubdirectory("resources");
        if (resourcesDirectory == null) {
            resourcesDirectory = parentDirectory.createSubdirectory("resources");
        }
    }
    return resourcesDirectory;
}
 
開發者ID:hykes,項目名稱:CodeGen,代碼行數:24,代碼來源:AbstractFileProvider.java

示例3: 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;
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:33,代碼來源:Util.java

示例4: buildUrnKeyForFile

import com.intellij.psi.PsiDirectory; //導入方法依賴的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();
}
 
開發者ID:magento,項目名稱:magento2-phpstorm-plugin,代碼行數:36,代碼來源:SettingsForm.java

示例5: isFileInContext

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
@Override
public boolean isFileInContext(@NotNull PsiFile psiFile) {
    PsiDirectory containingDirectory = psiFile.getOriginalFile().getContainingDirectory();
    while (containingDirectory != null) {
        if (containingDirectory.getManager().areElementsEquivalent(containingDirectory, directory)) {
            return true;
        }

        containingDirectory = containingDirectory.getParentDirectory();
    }

    return false;
}
 
開發者ID:magento,項目名稱:magento2-phpstorm-plugin,代碼行數:14,代碼來源:MagentoComponentImp.java

示例6: update

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
@Override
public void update(@NotNull AnActionEvent e) {
  e.getPresentation().setEnabledAndVisible(false);
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (view == null || project == null) {
    return;
  }
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null || !(course instanceof RemoteCourse)) {
    return;
  }
  if (!course.getCourseMode().equals(CCUtils.COURSE_MODE)) return;
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return;
  }
  final PsiDirectory taskDir = directories[0];

  if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
    return;
  }
  final PsiDirectory lessonDir = taskDir.getParentDirectory();
  if (lessonDir == null) return;
  final Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson != null && lesson.getId() > 0 && ((RemoteCourse)course).getId() > 0) {
    e.getPresentation().setEnabledAndVisible(true);
    final com.jetbrains.edu.learning.courseFormat.tasks.Task task = lesson.getTask(taskDir.getName());
    if (task.getStepId() <= 0) {
      e.getPresentation().setText("Upload Task to Stepik");
    }
  }
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:34,代碼來源:CCPushTask.java

示例7: findClassDirectory

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
@Nullable
private static PsiDirectory findClassDirectory(PhpClass phpClass, PsiFile file) {
    if (phpClass != null) {
        Method getViewPath = phpClass.findMethodByName("getViewPath");
        PhpClass ownClass = phpClass.getSuperClass();
        PsiDirectory directory = file.getOriginalFile().getContainingDirectory();
        if (directory != null) {
            while (ownClass != null) {
                if (getViewPath != null) {
                    getViewPath = ownClass.findMethodByName("getViewPath");
                }
                switch (ownClass.getFQN()) {
                    case "\\yii\\base\\Controller":
                        directory = directory.getParentDirectory();
                        if (directory == null) {
                            return null;
                        }
                        if (getViewPath != null && Objects.equals(getViewPath.getContainingClass(), ownClass)) {
                            directory = directory.findSubdirectory("views");
                        }

                        if (directory != null) {
                            file.putUserData(VIEWS_DIRECTORY_MODIFIED, file.getModificationStamp());
                            file.putUserData(VIEWS_DIRECTORY, directory);

                            String controllerId = phpClass.getName();
                            controllerId = controllerId.substring(0, controllerId.length() - 10);
                            controllerId = new SplitWordsMacro.LowercaseAndDash().convertString(controllerId);

                            PsiDirectory context = directory.findSubdirectory(controllerId);
                            if (context != null) {
                                file.putUserData(VIEWS_CONTEXT_DIRECTORY, context);
                            }
                        }

                        return directory;
                    case "\\yii\\base\\Widget":
                        directory = directory.findSubdirectory("views");
                        if (directory != null) {
                            file.putUserData(VIEWS_DIRECTORY_MODIFIED, file.getModificationStamp());
                            file.putUserData(VIEWS_DIRECTORY, directory);
                            file.putUserData(VIEWS_CONTEXT_DIRECTORY, directory);
                        }

                        return directory;
                }
                ownClass = ownClass.getSuperClass();
            }
        }
    }

    return null;
}
 
開發者ID:nvlad,項目名稱:yii2support,代碼行數:54,代碼來源:ViewsUtil.java

示例8: actionPerformed

import com.intellij.psi.PsiDirectory; //導入方法依賴的package包/類
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final IdeView view = e.getData(LangDataKeys.IDE_VIEW);
  final Project project = e.getData(CommonDataKeys.PROJECT);
  if (view == null || project == null) {
    return;
  }
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  if (course == null) {
    return;
  }
  final PsiDirectory[] directories = view.getDirectories();
  if (directories.length == 0 || directories.length > 1) {
    return;
  }

  final PsiDirectory taskDir = directories[0];

  if (taskDir == null || !taskDir.getName().contains(EduNames.TASK)) {
    return;
  }
  final PsiDirectory lessonDir = taskDir.getParentDirectory();
  if (lessonDir == null) return;
  final Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson == null) return;

  final com.jetbrains.edu.learning.courseFormat.tasks.Task task = lesson.getTask(taskDir.getName());
  if (task == null) return;

  ProgressManager.getInstance().run(new Task.Modal(project, "Uploading Task", true) {
    @Override
    public void run(@NotNull ProgressIndicator indicator) {
      indicator.setText("Uploading task to " + EduStepicNames.STEPIC_URL);
      if (task.getStepId() <= 0) {
        CCStepicConnector.postTask(project, task, lesson.getId());
      }
      else {
        CCStepicConnector.updateTask(project, task);
      }
    }
  });
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:43,代碼來源:CCPushTask.java

示例9: actionPerformed

import com.intellij.psi.PsiDirectory; //導入方法依賴的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);
    }
  });
}
 
開發者ID:medvector,項目名稱:educational-plugin,代碼行數:44,代碼來源:CCShowPreview.java


注:本文中的com.intellij.psi.PsiDirectory.getParentDirectory方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。