use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class CCCreateStudyItemActionBase method createItem.
@Nullable
public PsiDirectory createItem(@Nullable final IdeView view, @NotNull final Project project, @NotNull final PsiDirectory sourceDirectory, @NotNull final Course course) {
StudyItem parentItem = getParentItem(course, sourceDirectory);
final StudyItem item = getItem(sourceDirectory, project, course, view, parentItem);
if (item == null) {
return null;
}
final PsiDirectory parentDir = getParentDir(project, course, sourceDirectory);
if (parentDir == null) {
return null;
}
CCUtils.updateHigherElements(parentDir.getVirtualFile().getChildren(), getStudyOrderable(item), item.getIndex() - 1, getItemName(), 1);
addItem(course, item);
Collections.sort(getSiblings(course, parentItem), EduUtils.INDEX_COMPARATOR);
return createItemDir(project, item, view, parentDir, course);
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class YAMLPsiManager method isOutOfCodeBlock.
@Override
protected boolean isOutOfCodeBlock(@NotNull PsiElement element) {
while (true) {
if (element instanceof YAMLFile) {
return true;
}
if (element instanceof PsiFile || element instanceof PsiDirectory) {
return false;
}
PsiElement parent = element.getParent();
if (!(parent instanceof YAMLFile || parent instanceof YAMLKeyValue || parent instanceof YAMLCompoundValue || parent instanceof YAMLDocument)) {
return false;
}
element = parent;
}
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class HtmlFileReferenceHelper method getContexts.
@NotNull
@Override
public Collection<PsiFileSystemItem> getContexts(Project project, @NotNull VirtualFile vFile) {
final PsiFile file = PsiManager.getInstance(project).findFile(vFile);
final Module module = file != null ? ModuleUtilCore.findModuleForPsiElement(file) : null;
if (module == null || !(file instanceof XmlFile))
return Collections.emptyList();
final String basePath = HtmlUtil.getHrefBase((XmlFile) file);
if (basePath != null && !HtmlUtil.hasHtmlPrefix(basePath)) {
for (VirtualFile virtualFile : getBaseRoots(module)) {
final VirtualFile base = virtualFile.findFileByRelativePath(basePath);
final PsiDirectory result = base != null ? PsiManager.getInstance(project).findDirectory(base) : null;
if (result != null) {
return Collections.<PsiFileSystemItem>singletonList(result);
}
}
}
return Collections.emptyList();
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class CreateTestAction method invoke.
@Override
public void invoke(@NotNull final Project project, Editor editor, @NotNull PsiElement element) throws IncorrectOperationException {
final PyFunction srcFunction = PsiTreeUtil.getParentOfType(element, PyFunction.class);
final PyClass srcClass = PsiTreeUtil.getParentOfType(element, PyClass.class);
if (srcClass == null && srcFunction == null)
return;
final PsiDirectory dir = element.getContainingFile().getContainingDirectory();
final CreateTestDialog d = new CreateTestDialog(project);
if (srcClass != null) {
d.setClassName("Test" + StringUtil.capitalize(srcClass.getName()));
d.setFileName("test_" + StringUtil.decapitalize(srcClass.getName()) + ".py");
if (dir != null)
d.setTargetDir(dir.getVirtualFile().getPath());
if (srcFunction != null) {
d.methodsSize(1);
d.addMethod("test_" + srcFunction.getName(), 0);
} else {
final List<PyFunction> methods = Lists.newArrayList();
srcClass.visitMethods(pyFunction -> {
if (pyFunction.getName() != null && !pyFunction.getName().startsWith("__"))
methods.add(pyFunction);
return true;
}, false, null);
d.methodsSize(methods.size());
int i = 0;
for (PyFunction f : methods) {
d.addMethod("test_" + f.getName(), i);
++i;
}
}
} else {
d.setClassName("Test" + StringUtil.capitalize(srcFunction.getName()));
d.setFileName("test_" + StringUtil.decapitalize(srcFunction.getName()) + ".py");
if (dir != null)
d.setTargetDir(dir.getVirtualFile().getPath());
d.methodsSize(1);
d.addMethod("test_" + srcFunction.getName(), 0);
}
if (!d.showAndGet()) {
return;
}
CommandProcessor.getInstance().executeCommand(project, () -> {
PsiFile e = PyTestCreator.generateTestAndNavigate(project, d);
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
documentManager.commitAllDocuments();
}, CodeInsightBundle.message("intention.create.test"), this);
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PyToxConfigurationProducer method setupConfigurationFromContext.
@Override
protected boolean setupConfigurationFromContext(final PyToxConfiguration configuration, final ConfigurationContext context, final Ref<PsiElement> sourceElement) {
final PsiFile file = sourceElement.get().getContainingFile();
if (file == null) {
return false;
}
final String envName = PyToxTestLocator.getEnvNameFromElement(file);
if (envName != null) {
configuration.setRunOnlyEnvs(envName);
configuration.setName(String.format("Tox: run on %s", envName));
return true;
}
final PsiDirectory directory = file.getContainingDirectory();
if (directory == null) {
return false;
}
configuration.setWorkingDirectory(directory.getVirtualFile().getCanonicalPath());
if (TOX_FILE_NAME.equals(file.getName())) {
configuration.setName("Tox");
return true;
}
return false;
}
Aggregations