PY-34617 Remove if stubs

GitOrigin-RevId: 13f49394e92daca80af9c82ac9ac1a439a6ae1f5
This commit is contained in:
Petr
2024-07-28 18:05:47 +02:00
committed by intellij-monorepo-bot
parent 6efb57a0f7
commit a3608ebd22
47 changed files with 264 additions and 538 deletions

View File

@@ -15,12 +15,10 @@
*/
package com.jetbrains.python.psi;
import com.intellij.psi.StubBasedPsiElement;
import com.jetbrains.python.ast.PyAstElsePart;
import com.jetbrains.python.psi.stubs.PyElsePartStub;
/**
* The 'else:' part of various compound statements.
*/
public interface PyElsePart extends PyAstElsePart, PyStatementPart, StubBasedPsiElement<PyElsePartStub> {
public interface PyElsePart extends PyAstElsePart, PyStatementPart {
}

View File

@@ -1,9 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.psi.StubBasedPsiElement;
import com.jetbrains.python.ast.PyAstIfPartElif;
import com.jetbrains.python.psi.stubs.PyIfPartElifStub;
public interface PyIfPartElif extends PyAstIfPartElif, PyIfPart, StubBasedPsiElement<PyIfPartElifStub> {
public interface PyIfPartElif extends PyAstIfPartElif, PyIfPart {
}

View File

@@ -1,9 +1,7 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi;
import com.intellij.psi.StubBasedPsiElement;
import com.jetbrains.python.ast.PyAstIfPartIf;
import com.jetbrains.python.psi.stubs.PyIfPartIfStub;
public interface PyIfPartIf extends PyAstIfPartIf, PyIfPart, StubBasedPsiElement<PyIfPartIfStub> {
public interface PyIfPartIf extends PyAstIfPartIf, PyIfPart {
}

View File

@@ -11,20 +11,14 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.*;
import com.intellij.psi.stubs.StubElement;
import com.intellij.psi.tree.TokenSet;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.QualifiedName;
import com.intellij.util.Processor;
import com.intellij.util.containers.ContainerUtil;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.ast.impl.PyPsiUtilsCore;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.psi.stubs.PyElsePartStub;
import com.jetbrains.python.psi.stubs.PyIfPartElifStub;
import com.jetbrains.python.psi.stubs.PyIfPartIfStub;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -632,59 +626,4 @@ public final class PyPsiUtils {
while (next != null);
return null;
}
/**
* @see <a href="https://typing.readthedocs.io/en/latest/source/stubs.html#version-and-platform-checks">Version and Platform Checks</a>
*/
@ApiStatus.Internal
@Nullable
public static StubElement<?> getParentStubSkippingVersionChecks(@Nullable StubElement<?> stub) {
if (stub != null) {
for (StubElement<?> e = stub.getParentStub(); e != null; e = e.getParentStub()) {
boolean isVersionCheck = e instanceof PyIfPartIfStub || e instanceof PyIfPartElifStub || e instanceof PyElsePartStub;
if (!isVersionCheck) {
return e;
}
}
}
return null;
}
/**
* @see <a href="https://typing.readthedocs.io/en/latest/source/stubs.html#version-and-platform-checks">Version and Platform Checks</a>
*/
@ApiStatus.Internal
public static boolean processChildrenStubs(@NotNull StubElement<?> stub,
@NotNull LanguageLevel languageLevel,
@NotNull Processor<? super StubElement<?>> processor) {
boolean recurse = false;
for (StubElement<?> child : stub.getChildrenStubs()) {
if (child instanceof PyIfPartIfStub ifStub) {
if (ifStub.getVersionCheck().matches(languageLevel)) {
recurse = false;
if (!processChildrenStubs(child, languageLevel, processor)) return false;
}
else {
recurse = true;
}
}
else if (child instanceof PyIfPartElifStub elifStub) {
if (recurse && elifStub.getVersionCheck().matches(languageLevel)) {
recurse = false;
if (!processChildrenStubs(child, languageLevel, processor)) return false;
}
}
else if (child instanceof PyElsePartStub) {
if (recurse) {
recurse = false;
if (!processChildrenStubs(child, languageLevel, processor)) return false;
}
}
else {
recurse = false;
if (!processor.process(child)) return false;
}
}
return true;
}
}

View File

@@ -13,7 +13,7 @@ import java.math.BigInteger
@ApiStatus.Internal
data class PyVersionCheck(val version: Version, val isLessThan: Boolean) {
fun matches(languageLevel: LanguageLevel): Boolean {
return isLessThan == version.compareTo(languageLevel.majorVersion, languageLevel.minorVersion) > 0
return isLessThan == languageLevel.isLessThan(version)
}
companion object {
@@ -79,3 +79,7 @@ data class PyVersionCheck(val version: Version, val isLessThan: Boolean) {
}
}
}
fun LanguageLevel.isLessThan(version: Version): Boolean {
return version.compareTo(majorVersion, minorVersion) > 0
}

View File

@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
public interface PyClassStub extends NamedStub<PyClass> {
public interface PyClassStub extends NamedStub<PyClass>, PyVersionSpecificStub {
/**
* @return a {@code Map} which contains imported class names as keys and their original names as values.

View File

@@ -1,8 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import com.jetbrains.python.psi.PyElsePart;
public interface PyElsePartStub extends StubElement<PyElsePart> {
}

View File

@@ -4,7 +4,7 @@ package com.jetbrains.python.psi.stubs;
import com.intellij.psi.stubs.NamedStub;
import com.jetbrains.python.psi.PyFunction;
public interface PyFunctionStub extends NamedStub<PyFunction>, PyAnnotationOwnerStub, PyTypeCommentOwnerStub {
public interface PyFunctionStub extends NamedStub<PyFunction>, PyAnnotationOwnerStub, PyTypeCommentOwnerStub, PyVersionSpecificStub {
String getDocString();
String getDeprecationMessage();
boolean isAsync();

View File

@@ -1,10 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import com.jetbrains.python.psi.impl.PyVersionCheck;
import com.jetbrains.python.psi.PyIfPartElif;
public interface PyIfPartElifStub extends StubElement<PyIfPartElif> {
PyVersionCheck getVersionCheck();
}

View File

@@ -1,10 +0,0 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi.stubs;
import com.intellij.psi.stubs.StubElement;
import com.jetbrains.python.psi.impl.PyVersionCheck;
import com.jetbrains.python.psi.PyIfPartIf;
public interface PyIfPartIfStub extends StubElement<PyIfPartIf> {
PyVersionCheck getVersionCheck();
}

View File

@@ -8,7 +8,8 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
public interface PyTargetExpressionStub extends NamedStub<PyTargetExpression>, PyTypeCommentOwnerStub, PyAnnotationOwnerStub {
public interface PyTargetExpressionStub
extends NamedStub<PyTargetExpression>, PyTypeCommentOwnerStub, PyAnnotationOwnerStub, PyVersionSpecificStub {
enum InitializerType {
ReferenceExpression(1),
CallExpression(2),

View File

@@ -5,7 +5,7 @@ import com.intellij.psi.stubs.NamedStub;
import com.jetbrains.python.psi.PyTypeAliasStatement;
import org.jetbrains.annotations.Nullable;
public interface PyTypeAliasStatementStub extends NamedStub<PyTypeAliasStatement> {
public interface PyTypeAliasStatementStub extends NamedStub<PyTypeAliasStatement>, PyVersionSpecificStub {
@Nullable
String getTypeExpressionText();

View File

@@ -0,0 +1,10 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.python.psi.stubs
import com.intellij.openapi.util.Version
interface PyVersionSpecificStub {
val versionRange: PyVersionRange
}
class PyVersionRange(val lowInclusive: Version?, val highExclusive: Version?)