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