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


Java PsiDirectory.findSubdirectory方法代码示例

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


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

示例1: createLessonContent

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
public PsiDirectory createLessonContent(@NotNull Project project, @NotNull Lesson lesson, @Nullable IdeView view, @NotNull PsiDirectory parentDirectory) {
  NewModuleAction newModuleAction = new NewModuleAction();
  String courseDirPath = parentDirectory.getVirtualFile().getPath();
  Module utilModule = ModuleManager.getInstance(project).findModuleByName(EduIntelliJNames.UTIL);
  if (utilModule == null) {
    return null;
  }
  newModuleAction.createModuleFromWizard(project, null, new AbstractProjectWizard("", project, "") {
    @Override
    public StepSequence getSequence() {
      return null;
    }

    @Override
    public ProjectBuilder getProjectBuilder() {
      return new EduLessonModuleBuilder(courseDirPath, lesson, utilModule);
    }
  });
  return parentDirectory.findSubdirectory(EduNames.LESSON + lesson.getIndex());
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:22,代码来源:EduPluginConfiguratorBase.java

示例2: createChildDirectoryNode

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
public PsiDirectoryNode createChildDirectoryNode(StudyItem item, PsiDirectory directory) {
  final List<Lesson> lessons = myCourse.getLessons();
  final Lesson lesson = (Lesson)item;
  if (directory.getChildren().length > 0 && lessons.size() == 1) {
    final List<Task> tasks = lesson.getTaskList();
    if (tasks.size() == 1) {
      PsiDirectory taskDirectory = (PsiDirectory)directory.getChildren()[0];
      PsiDirectory srcDir = taskDirectory.findSubdirectory(EduNames.SRC);
      if (srcDir != null) {
        taskDirectory = srcDir;
      }
      return new TaskDirectoryNode(myProject, taskDirectory, myViewSettings, tasks.get(0));
    }
  }
  return new LessonDirectoryNode(myProject, directory, myViewSettings, lesson);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:CourseDirectoryNode.java

示例3: 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

示例4: applyFix

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement().getParent();
    PsiDirectory directory;
    String path = null;

    if (element instanceof StringLiteralExpression) {
        path = ((StringLiteralExpression) element).getContents();
    }

    if (path == null) {
        return;
    }

    if (path.startsWith("/")) {
        directory = ViewsUtil.getRootDirectory(element);
        path = path.substring(1);
    } else {
        directory = ViewsUtil.getContextDirectory(element);
    }

    if (directory == null) {
        return;
    }

    while (directory != null && path.contains("/")) {
        final String subdirectory = path.substring(0, path.indexOf('/'));
        path = path.substring(path.indexOf('/') + 1);

        directory = directory.findSubdirectory(subdirectory);
    }

    if (directory != null) {
        if (!path.contains(".")) {
            path = path + ".php";
        }

        final PsiFile viewPsiFile = directory.createFile(path);
        FileEditorManager.getInstance(project).openFile(viewPsiFile.getVirtualFile(), true);

        final FileTemplate[] templates = FileTemplateManager.getDefaultInstance().getTemplates(FileTemplateManager.DEFAULT_TEMPLATES_CATEGORY);
        FileTemplate template = null;
        for (FileTemplate fileTemplate : templates) {
            if (fileTemplate.getName().equals("PHP File")) {
                template = fileTemplate;
                break;
            }
        }

        if (template != null && viewPsiFile.getViewProvider().getDocument() != null) {
            final Properties properties = FileTemplateManager.getDefaultInstance().getDefaultProperties();
            template.setLiveTemplateEnabled(true);
            template.setReformatCode(true);
            try {
                viewPsiFile.getViewProvider().getDocument().insertString(0, template.getText(properties));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
开发者ID:nvlad,项目名称:yii2support,代码行数:62,代码来源:MissedViewLocalQuickFix.java

示例5: 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

示例6: createSubDirectory

import com.intellij.psi.PsiDirectory; //导入方法依赖的package包/类
/**
 * 创建子目录
 * @param psiDirectory
 * @param temp
 * @param level
 * @return
 */
private PsiDirectory createSubDirectory(PsiDirectory psiDirectory, String[] temp, int level) {
    PsiDirectory subdirectory = psiDirectory.findSubdirectory(temp[level]);
    if (subdirectory == null) {
        subdirectory = psiDirectory.createSubdirectory(temp[level]);
    }
    if (temp.length != level + 1) {
        return createSubDirectory(subdirectory, temp, level + 1);
    }
    return subdirectory;
}
 
开发者ID:hykes,项目名称:CodeGen,代码行数:18,代码来源:AbstractFileProvider.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: 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


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