本文整理汇总了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());
}
示例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);
}
示例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;
}
示例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();
}
}
}
}
示例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;
}
示例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;
}
示例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));
}
}
}
示例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;
}
示例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;
}