当前位置: 首页>>代码示例>>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;未经允许,请勿转载。