Search in sources :

Example 71 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyDataViewerPanel method createEditorField.

@NotNull
private EditorTextField createEditorField() {
    return new EditorTextField(EditorFactory.getInstance().createDocument(""), myProject, PythonFileType.INSTANCE, false, true) {

        @Override
        protected EditorEx createEditor() {
            EditorEx editor = super.createEditor();
            editor.getContentComponent().addKeyListener(new KeyAdapter() {

                @Override
                public void keyPressed(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                        apply(mySliceTextField.getText());
                    }
                }
            });
            return editor;
        }
    };
}
Also used : KeyEvent(java.awt.event.KeyEvent) EditorEx(com.intellij.openapi.editor.ex.EditorEx) EditorTextField(com.intellij.ui.EditorTextField) KeyAdapter(java.awt.event.KeyAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyTypingAnnotationInjector method registerCommentInjection.

@NotNull
private static PyInjectionUtil.InjectionResult registerCommentInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiLanguageInjectionHost host) {
    final String text = host.getText();
    final Matcher m = PyTypingTypeProvider.TYPE_COMMENT_PATTERN.matcher(text);
    if (m.matches()) {
        final String annotationText = m.group(1);
        if (annotationText != null) {
            final int start = m.start(1);
            final int end = m.end(1);
            if (start < end && allowInjectionInComment(host)) {
                Language language = null;
                if ("ignore".equals(annotationText)) {
                    language = null;
                } else if (isFunctionTypeComment(host)) {
                    language = PyFunctionTypeAnnotationDialect.INSTANCE;
                } else if (isTypingAnnotation(annotationText)) {
                    language = PyDocstringLanguageDialect.getInstance();
                }
                if (language != null) {
                    registrar.startInjecting(language);
                    registrar.addPlace("", "", host, TextRange.create(start, end));
                    registrar.doneInjecting();
                    return new PyInjectionUtil.InjectionResult(true, true);
                }
            }
        }
    }
    return PyInjectionUtil.InjectionResult.EMPTY;
}
Also used : Language(com.intellij.lang.Language) Matcher(java.util.regex.Matcher) NotNull(org.jetbrains.annotations.NotNull)

Example 73 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyTypingTypeProvider method getGenericSubstitutions.

@NotNull
@Override
public Map<PyType, PyType> getGenericSubstitutions(@NotNull PyClass cls, @NotNull TypeEvalContext context) {
    final Context ctx = new Context(context);
    if (!isGeneric(cls, ctx)) {
        return Collections.emptyMap();
    }
    final Map<PyType, PyType> results = new HashMap<>();
    // XXX: Requires switching from stub to AST
    for (PyExpression e : cls.getSuperClassExpressions()) {
        final PySubscriptionExpression subscriptionExpr = as(e, PySubscriptionExpression.class);
        final PyExpression superExpr = subscriptionExpr != null ? subscriptionExpr.getOperand() : e;
        final PyType superType = context.getType(superExpr);
        final PyClassType superClassType = as(superType, PyClassType.class);
        final PyClass superClass = superClassType != null ? superClassType.getPyClass() : null;
        final Map<PyType, PyType> superSubstitutions = superClass != null ? doPreventingRecursion(RECURSION_KEY, false, () -> getGenericSubstitutions(superClass, context)) : null;
        if (superSubstitutions != null) {
            results.putAll(superSubstitutions);
        }
        final List<PyType> superGenerics = superClass != null ? collectGenericTypes(superClass, ctx) : Collections.emptyList();
        final List<PyExpression> indices = subscriptionExpr != null ? getSubscriptionIndices(subscriptionExpr) : Collections.emptyList();
        for (int i = 0; i < superGenerics.size(); i++) {
            final PyExpression expr = ContainerUtil.getOrElse(indices, i, null);
            final PyType superGeneric = superGenerics.get(i);
            final Ref<PyType> typeRef = expr != null ? getType(expr, ctx) : null;
            final PyType actualType = typeRef != null ? typeRef.get() : null;
            if (!superGeneric.equals(actualType)) {
                results.put(superGeneric, actualType);
            }
        }
    }
    return results;
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) HashMap(com.intellij.util.containers.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 74 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyTypingTypeProvider method tryResolving.

@NotNull
private static List<PsiElement> tryResolving(@NotNull PyExpression expression, @NotNull TypeEvalContext context) {
    final List<PsiElement> elements = Lists.newArrayList();
    if (expression instanceof PyReferenceExpression) {
        final PyReferenceExpression referenceExpr = (PyReferenceExpression) expression;
        final PyResolveContext resolveContext = PyResolveContext.noImplicits().withTypeEvalContext(context);
        final PsiPolyVariantReference reference = referenceExpr.getReference(resolveContext);
        final List<PsiElement> resolved = PyUtil.multiResolveTopPriority(reference);
        for (PsiElement element : resolved) {
            if (element instanceof PyFunction) {
                final PyFunction function = (PyFunction) element;
                if (PyUtil.isInit(function)) {
                    final PyClass cls = function.getContainingClass();
                    if (cls != null) {
                        elements.add(cls);
                        continue;
                    }
                }
            }
            final String name = element != null ? getQualifiedName(element) : null;
            if (name != null && OPAQUE_NAMES.contains(name)) {
                elements.add(element);
                continue;
            }
            if (element instanceof PyTargetExpression) {
                final PyTargetExpression targetExpr = (PyTargetExpression) element;
                // XXX: Requires switching from stub to AST
                final PyExpression assignedValue = targetExpr.findAssignedValue();
                if (assignedValue != null) {
                    elements.add(assignedValue);
                    continue;
                }
            }
            if (element != null) {
                elements.add(element);
            }
        }
    }
    return !elements.isEmpty() ? elements : Collections.singletonList(expression);
}
Also used : PyResolveContext(com.jetbrains.python.psi.resolve.PyResolveContext) PsiElement(com.intellij.psi.PsiElement) PsiPolyVariantReference(com.intellij.psi.PsiPolyVariantReference) NotNull(org.jetbrains.annotations.NotNull)

Example 75 with NotNull

use of org.jetbrains.annotations.NotNull in project intellij-community by JetBrains.

the class PyDebugRunner method createSession.

protected XDebugSession createSession(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    final PythonCommandLineState pyState = (PythonCommandLineState) state;
    Sdk sdk = pyState.getSdk();
    PyDebugSessionFactory sessionCreator = PyDebugSessionFactory.findExtension(sdk);
    if (sessionCreator != null) {
        return sessionCreator.createSession(pyState, environment);
    }
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
    final int serverLocalPort = serverSocket.getLocalPort();
    RunProfile profile = environment.getRunProfile();
    final ExecutionResult result = pyState.execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, serverLocalPort));
    return XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PyDebugProcess pyDebugProcess = createDebugProcess(session, serverSocket, result, pyState);
            createConsoleCommunicationAndSetupActions(environment.getProject(), result, pyDebugProcess, session);
            return pyDebugProcess;
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) ServerSocket(java.net.ServerSocket) NotNull(org.jetbrains.annotations.NotNull) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)8141 VirtualFile (com.intellij.openapi.vfs.VirtualFile)888 ArrayList (java.util.ArrayList)809 PsiElement (com.intellij.psi.PsiElement)764 Project (com.intellij.openapi.project.Project)647 File (java.io.File)627 Nullable (org.jetbrains.annotations.Nullable)518 List (java.util.List)400 PsiFile (com.intellij.psi.PsiFile)358 Module (com.intellij.openapi.module.Module)336 IOException (java.io.IOException)325 TextRange (com.intellij.openapi.util.TextRange)260 Document (com.intellij.openapi.editor.Document)173 ContainerUtil (com.intellij.util.containers.ContainerUtil)173 BasePhpElementVisitor (com.kalessil.phpStorm.phpInspectionsEA.openApi.BasePhpElementVisitor)169 ASTNode (com.intellij.lang.ASTNode)167 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)167 Map (java.util.Map)156 java.util (java.util)154 IElementType (com.intellij.psi.tree.IElementType)146