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;
}
};
}
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;
}
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;
}
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);
}
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;
}
});
}
Aggregations