Search in sources :

Example 61 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class StepikPyProjectGenerator method getLocationField.

@Nullable
private TextFieldWithBrowseButton getLocationField() {
    if (locationField == null) {
        Container basePanel = wizardStep.getComponent().getParent();
        if (basePanel == null) {
            return null;
        }
        try {
            Container topPanel = (Container) basePanel.getComponent(0);
            LabeledComponent locationComponent = (LabeledComponent) topPanel.getComponent(0);
            locationField = (TextFieldWithBrowseButton) locationComponent.getComponent();
        } catch (ClassCastException | ArrayIndexOutOfBoundsException e) {
            logger.warn("Auto naming for a project don't work: ", e);
            return null;
        }
    }
    return locationField;
}
Also used : LabeledComponent(com.intellij.openapi.ui.LabeledComponent) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class StepikSendAction method getSubmissionId.

@Nullable
private static Long getSubmissionId(@NotNull Project project, @NotNull StepikApiClient stepikApiClient, @NotNull StepNode stepNode, long intAttemptId) {
    SupportedLanguages currentLang = stepNode.getCurrentLang();
    String code = getCode(project, stepNode, currentLang);
    if (code == null) {
        logger.info(String.format("Sending step failed: id=%s. Step content is null", stepNode.getId()));
        return null;
    }
    Submissions submissions;
    try {
        submissions = stepikApiClient.submissions().post().attempt(intAttemptId).language(currentLang.getName()).code(code).execute();
        if (submissions.isEmpty()) {
            notifyFailed(project, stepNode, "Submissions is empty", null);
            return null;
        }
    } catch (StepikClientException e) {
        notifyFailed(project, stepNode, "Failed post submission", e);
        return null;
    }
    return submissions.getFirst().getId();
}
Also used : SupportedLanguages(org.stepik.core.SupportedLanguages) Submissions(org.stepik.api.objects.submissions.Submissions) StepikClientException(org.stepik.api.exceptions.StepikClientException) Nullable(org.jetbrains.annotations.Nullable)

Example 63 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class StepikSendAction method getCode.

@Nullable
private static String getCode(@NotNull Project project, @NotNull StepNode stepNode, @NotNull SupportedLanguages currentLang) {
    VirtualFile src = getOrCreateSrcDirectory(project, stepNode, true);
    if (src == null) {
        return null;
    }
    VirtualFile mainFile = src.findChild(currentLang.getMainFileName());
    if (mainFile == null) {
        return null;
    }
    String text = getFileText(mainFile);
    return getTextUnderDirectives(text, currentLang);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Nullable(org.jetbrains.annotations.Nullable)

Example 64 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class AbstractMoveHandlerDelegate method doMove.

@Override
public void doMove(Project project, PsiElement[] elements, @Nullable PsiElement targetContainer, @Nullable MoveCallback callback) {
    List<PsiFileSystemItem> sources = Arrays.stream(elements).filter(psiElement -> isNotMovableOrRenameElement(psiElement, acceptableClasses)).map(ProjectPsiFilesUtils::getFile).filter(Objects::nonNull).collect(Collectors.toList());
    StringBuilder message = new StringBuilder();
    if (sources.size() > 1) {
        message.append("You can not move the following elements:");
    } else {
        PsiFileSystemItem source = sources.get(0);
        message.append("You can not move the ").append(source.isDirectory() ? "directory" : "file").append(":");
    }
    for (PsiFileSystemItem file : sources) {
        message.append("\n").append(file.getVirtualFile().getPath());
    }
    MessagesEx.error(project, message.toString(), "Move").showNow();
}
Also used : MoveHandlerDelegate(com.intellij.refactoring.move.MoveHandlerDelegate) Arrays(java.util.Arrays) ProjectPsiFilesUtils.isNotMovableOrRenameElement(org.stepik.plugin.utils.ProjectPsiFilesUtils.isNotMovableOrRenameElement) MoveCallback(com.intellij.refactoring.move.MoveCallback) MessagesEx(com.intellij.openapi.ui.ex.MessagesEx) Set(java.util.Set) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils.isCanNotBeTarget(org.stepik.plugin.utils.ProjectPsiFilesUtils.isCanNotBeTarget) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) ProjectPsiFilesUtils(org.stepik.plugin.utils.ProjectPsiFilesUtils)

Example 65 with Nullable

use of org.jetbrains.annotations.Nullable in project intellij-plugins by StepicOrg.

the class NavigationUtils method findNodeWithObject.

@Nullable
private static DefaultMutableTreeNode findNodeWithObject(@NotNull TreeNode root, PsiFileSystemItem file) {
    for (int i = 0; i < root.getChildCount(); i++) {
        TreeNode child = root.getChildAt(i);
        if (child instanceof DefaultMutableTreeNode) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) child;
            Object userObject = node.getUserObject();
            if (userObject instanceof PsiDirectoryNode) {
                PsiDirectoryNode directoryNode = (PsiDirectoryNode) userObject;
                PsiDirectory value = directoryNode.getValue();
                if (file.equals(value)) {
                    return node;
                }
            }
            node = findNodeWithObject(child, file);
            if (node != null) {
                return node;
            }
        }
    }
    return null;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) PsiDirectory(com.intellij.psi.PsiDirectory) PsiDirectoryNode(com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Nullable (org.jetbrains.annotations.Nullable)4694 VirtualFile (com.intellij.openapi.vfs.VirtualFile)812 PsiElement (com.intellij.psi.PsiElement)485 File (java.io.File)405 Project (com.intellij.openapi.project.Project)396 PsiFile (com.intellij.psi.PsiFile)320 NotNull (org.jetbrains.annotations.NotNull)259 IOException (java.io.IOException)247 Module (com.intellij.openapi.module.Module)227 ArrayList (java.util.ArrayList)178 TextRange (com.intellij.openapi.util.TextRange)156 Document (com.intellij.openapi.editor.Document)124 List (java.util.List)116 ASTNode (com.intellij.lang.ASTNode)105 IElementType (com.intellij.psi.tree.IElementType)103 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)102 XmlTag (com.intellij.psi.xml.XmlTag)96 Editor (com.intellij.openapi.editor.Editor)94 Element (org.jdom.Element)93 XmlFile (com.intellij.psi.xml.XmlFile)78