mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[python] Minor code deduplication
GitOrigin-RevId: 9ffcd59ab6810970b0f595fe9e1a721f83997812
This commit is contained in:
committed by
intellij-monorepo-bot
parent
f9a7736d09
commit
405b37ac93
+1
-1
@@ -21,7 +21,7 @@ open class PyVersionAwareElementVisitor(languageLevel: LanguageLevel?) : PyRecur
|
||||
}
|
||||
val ifParts = sequenceOf(node.ifPart) + node.elifParts.asSequence()
|
||||
for (ifPart in ifParts) {
|
||||
val versions = ifPart.condition?.let(PyVersionCheck::convertToVersionRanges)
|
||||
val versions = PyVersionCheck.convertToVersionRanges(ifPart)
|
||||
if (versions == null) {
|
||||
super.visitPyIfStatement(node)
|
||||
return
|
||||
|
||||
@@ -6,11 +6,7 @@ import com.google.common.collect.Range
|
||||
import com.intellij.openapi.util.Version
|
||||
import com.intellij.psi.util.QualifiedName
|
||||
import com.jetbrains.python.PyTokenTypes
|
||||
import com.jetbrains.python.psi.PyBinaryExpression
|
||||
import com.jetbrains.python.psi.PyExpression
|
||||
import com.jetbrains.python.psi.PyNumericLiteralExpression
|
||||
import com.jetbrains.python.psi.PyReferenceExpression
|
||||
import com.jetbrains.python.psi.PyTupleExpression
|
||||
import com.jetbrains.python.psi.*
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import java.math.BigInteger
|
||||
|
||||
@@ -22,7 +18,11 @@ object PyVersionCheck {
|
||||
* @see <a href="https://peps.python.org/pep-0484/#version-and-platform-checking">Version and Platform Checks</a>
|
||||
*/
|
||||
@JvmStatic
|
||||
fun convertToVersionRanges(expression: PyExpression): ImmutableRangeSet<Version>? {
|
||||
fun convertToVersionRanges(ifPart: PyIfPart): ImmutableRangeSet<Version>? {
|
||||
return ifPart.condition?.let(PyVersionCheck::convertToVersionRanges)
|
||||
}
|
||||
|
||||
private fun convertToVersionRanges(expression: PyExpression): ImmutableRangeSet<Version>? {
|
||||
val binaryExpr = PyPsiUtils.flattenParens(expression) as? PyBinaryExpression ?: return null
|
||||
when (val operator = binaryExpr.operator) {
|
||||
PyTokenTypes.AND_KEYWORD, PyTokenTypes.OR_KEYWORD -> {
|
||||
|
||||
+2
-2
@@ -53,7 +53,7 @@ internal fun evaluateVersionsForElement(element: PsiElement): ImmutableRangeSet<
|
||||
private fun evaluateVersionRangeForIfStatementPart(ifStatement: PyIfStatement, ifStatementPart: PsiElement): RangeSet<Version>? {
|
||||
assert(ifStatementPart is PyIfPart || ifStatementPart is PyElsePart)
|
||||
val result = if (ifStatementPart is PyIfPart) {
|
||||
val versionRanges = ifStatementPart.condition?.let(PyVersionCheck::convertToVersionRanges) ?: return null
|
||||
val versionRanges = PyVersionCheck.convertToVersionRanges(ifStatementPart) ?: return null
|
||||
TreeRangeSet.create(versionRanges)
|
||||
}
|
||||
else {
|
||||
@@ -61,7 +61,7 @@ private fun evaluateVersionRangeForIfStatementPart(ifStatement: PyIfStatement, i
|
||||
}
|
||||
val ifParts = sequenceOf(ifStatement.ifPart) + ifStatement.elifParts.asSequence()
|
||||
for (ifPart in ifParts.takeWhile { it !== ifStatementPart }) {
|
||||
val versionRanges = ifPart.condition?.let(PyVersionCheck::convertToVersionRanges) ?: return null
|
||||
val versionRanges = PyVersionCheck.convertToVersionRanges(ifPart) ?: return null
|
||||
result.removeAll(versionRanges)
|
||||
}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user