当前位置: 首页>>代码示例>>Java>>正文


Java PsiDirectory.getParent方法代码示例

本文整理汇总了Java中com.intellij.psi.PsiDirectory.getParent方法的典型用法代码示例。如果您正苦于以下问题:Java PsiDirectory.getParent方法的具体用法?Java PsiDirectory.getParent怎么用?Java PsiDirectory.getParent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.psi.PsiDirectory的用法示例。


在下文中一共展示了PsiDirectory.getParent方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: performAnswerPlaceholderAction

import com.intellij.psi.PsiDirectory; //导入方法依赖的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());
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:21,代码来源:CCEditAnswerPlaceholder.java

示例2: rename

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
protected void rename(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory) {
  if (directory.getName().equals(EduNames.SRC)) {
    directory = directory.getParent();
    if (directory == null) {
      return;
    }
  }
  PsiDirectory lessonDir = directory.getParent();
  if (lessonDir == null || !lessonDir.getName().contains(EduNames.LESSON)) {
    return;
  }
  Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson == null) {
    return;
  }
  String directoryName = directory.getName();
  Task task = lesson.getTask(directoryName);
  if (task != null) {
    processRename(task, EduNames.TASK, project);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:23,代码来源:CCTaskRenameHandler.java

示例3: getAppDirectoryFromFile

import com.intellij.psi.PsiDirectory; //导入方法依赖的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;
}
 
开发者ID:dmeybohm,项目名称:chocolate-cakephp,代码行数:12,代码来源:PsiUtil.java

示例4: getTask

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Nullable
public static Task getTask(@NotNull final PsiDirectory directory, @NotNull final Course course) {
  PsiDirectory lessonDir = directory.getParent();
  if (lessonDir == null) {
    return null;
  }
  Lesson lesson = course.getLesson(lessonDir.getName());
  if (lesson == null) {
    return null;
  }
  return lesson.getTask(directory.getName());
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:13,代码来源:EduUtils.java

示例5: getParentDir

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Nullable
@Override
protected PsiDirectory getParentDir(@NotNull Project project, @NotNull Course course, @NotNull PsiDirectory directory) {
  if (isAddedAsLast(directory, project, course)) {
    return directory;
  }
  return directory.getParent();
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:9,代码来源:CCCreateTask.java

示例6: tryToRenameTaskFile

import com.intellij.psi.PsiDirectory; //导入方法依赖的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);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:31,代码来源:CCRefactoringElementListenerProvider.java

示例7: 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));
        }
    }
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:55,代码来源:CompletionProvider.java

示例8: getViewFile

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Nullable
public static PsiFile getViewFile(PsiElement element) {
    final MethodReference reference = PsiTreeUtil.getParentOfType(element, MethodReference.class);
    if (reference == null) {
        return null;
    }

    final PsiElement[] parameters = reference.getParameters();
    if (parameters.length == 0 || !(parameters[0] instanceof StringLiteralExpression)) {
        return null;
    }

    String view = reference.getUserData(RENDER_VIEW);
    if (!((StringLiteralExpression) parameters[0]).getContents().equals(view)) {
        view = ((StringLiteralExpression) parameters[0]).getContents();
        reference.putUserData(RENDER_VIEW, view);
        reference.putUserData(RENDER_VIEW_FILE, null);
        reference.putUserData(RENDER_VIEW_PATH, null);
    }

    PsiFile file = reference.getUserData(RENDER_VIEW_FILE);
    if (file != null && file.isValid()) {
        if (!file.getVirtualFile().getPath().equals(reference.getUserData(RENDER_VIEW_PATH))) {
            reference.putUserData(RENDER_VIEW_FILE, null);
            reference.putUserData(RENDER_VIEW_PATH, null);
            file = null;
        }
    }

    if (file == null || !file.isValid()) {
        if (reference.getParameters()[0] instanceof StringLiteralExpression) {
            PsiDirectory directory;

            String path = ((StringLiteralExpression) reference.getParameters()[0]).getContents();
            if (path.startsWith("/")) {
                directory = ViewsUtil.getRootDirectory(element);
                path = path.substring(1);
            } else {
                directory = ViewsUtil.getContextDirectory(element);
            }

            String filename;
            if (path.contains("/")) {
                filename = path.substring(path.lastIndexOf('/') + 1);
                path = path.substring(0, path.lastIndexOf('/') + 1);
            } else {
                filename = path;
                path = "";
            }

            while (path.contains("/") && directory != null) {
                final String dirName = path.substring(0, path.indexOf('/'));
                directory = dirName.equals("..") ? directory.getParent() : directory.findSubdirectory(dirName);
                path = path.substring(path.indexOf('/') + 1);
            }

            if (directory == null) {
                return null;
            }

            if (filename.contains(".")) {
                file = directory.findFile(filename);
            } else {
                file = directory.findFile(filename + ".php");
                if (file == null) {
                    file = directory.findFile(filename + ".twig");
                }
                if (file == null) {
                    file = directory.findFile(filename + ".tpl");
                }
            }

            if (file != null) {
                reference.putUserData(RENDER_VIEW_FILE, file);
                reference.putUserData(RENDER_VIEW_PATH, file.getVirtualFile().getPath());
            }
        }
    }

    return file;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:82,代码来源:ViewsUtil.java

示例9: bindToElement

import com.intellij.psi.PsiDirectory; //导入方法依赖的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;
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:47,代码来源:PsiReference.java

示例10: doMove

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
public void doMove(final Project project,
                   PsiElement[] elements,
                   @Nullable PsiElement targetContainer,
                   @Nullable MoveCallback callback) {
  if (targetContainer == null || !(targetContainer instanceof PsiDirectory)) {
    return;
  }

  PsiDirectory targetDir = (PsiDirectory)targetContainer;
  if (!isTaskDir(targetDir) && !CCUtils.isLessonDir(targetDir)) {
    Messages.showInfoMessage("Tasks can be moved only to other lessons or inside lesson", "Incorrect Target For Move");
    return;
  }
  final Course course = StudyTaskManager.getInstance(project).getCourse();
  final PsiDirectory sourceDirectory = (PsiDirectory)elements[0];

  if (course == null) {
    return;
  }
  final Task taskToMove = EduUtils.getTask(sourceDirectory, course);
  if (taskToMove == null) {
    return;
  }

  if (CCUtils.isLessonDir(targetDir)) {
    //if user moves task to any lesson, this task is inserted as the last task in this lesson
    Lesson targetLesson = course.getLesson(targetDir.getName());
    if (targetLesson == null) {
      return;
    }
    List<Task> taskList = targetLesson.getTaskList();
    moveTask(sourceDirectory, taskToMove, taskList.isEmpty() ? null : taskList.get(taskList.size() - 1),
             1, targetDir.getVirtualFile(), targetLesson);
  }
  else {
    PsiDirectory lessonDir = targetDir.getParent();
    if (lessonDir == null) {
      return;
    }
    Task targetTask = EduUtils.getTask(targetDir, course);
    if (targetTask == null) {
      return;
    }
    final CCMoveStudyItemDialog dialog = new CCMoveStudyItemDialog(project, EduNames.TASK, targetTask.getName());
    dialog.show();
    if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
      return;
    }
    moveTask(sourceDirectory, taskToMove, targetTask, dialog.getIndexDelta(),
             lessonDir.getVirtualFile(), targetTask.getLesson());
  }

}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:55,代码来源:CCTaskMoveHandlerDelegate.java


注:本文中的com.intellij.psi.PsiDirectory.getParent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。