mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-07 22:09:38 +07:00
PY-71002 PEP-696: Support new syntax for default types of Type Parameters in new-style declarations
- PEP-696 adds a new syntax for declaring the default types of Type Parameters in new-new style generic classes, functions and type alias statements. Support these grammar changes. - Store info about default types in stubs for Type Parameters - Increment the stub version counter in PyFileElementType GitOrigin-RevId: b6b22e3eaa86ce06132885781e5775a89bf4b840
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d73bf77d9a
commit
7751fceaed
@@ -6,6 +6,7 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -43,7 +44,30 @@ public interface PyAstTypeParameter extends PyAstElement, PsiNameIdentifierOwner
|
||||
|
||||
@Nullable
|
||||
default PyAstExpression getBoundExpression() {
|
||||
return PsiTreeUtil.getChildOfType(this, PyAstExpression.class);
|
||||
PsiElement element = StreamEx.of(getChildren())
|
||||
.findFirst(child -> {
|
||||
PsiElement e = PsiTreeUtil.skipWhitespacesBackward(child);
|
||||
return e != null && e.getNode().getElementType() == PyTokenTypes.COLON;
|
||||
})
|
||||
.orElse(null);
|
||||
if (element instanceof PyAstExpression expression) {
|
||||
return expression;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
default PyAstExpression getDefaultExpression() {
|
||||
PsiElement element = StreamEx.of(getChildren())
|
||||
.findFirst(child -> {
|
||||
PsiElement e = PsiTreeUtil.skipWhitespacesBackward(child);
|
||||
return e != null && e.getNode().getElementType() == PyTokenTypes.EQ;
|
||||
})
|
||||
.orElse(null);
|
||||
if (element instanceof PyAstExpression expression) {
|
||||
return expression;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,6 +85,16 @@ public interface PyAstTypeParameter extends PyAstElement, PsiNameIdentifierOwner
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
default String getDefaultExpressionText() {
|
||||
PyAstExpression defaultExpression = getDefaultExpression();
|
||||
if (defaultExpression != null) {
|
||||
return defaultExpression.getText();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
default Kind getKind() {
|
||||
String paramText = getText();
|
||||
|
||||
Reference in New Issue
Block a user