mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactor python: j2k augmented assignment statements
GitOrigin-RevId: 7bc0031faa4027e20bee67e8e0b06cc094d2f16f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
167c4683a3
commit
7b9bf36bd7
@@ -1,35 +1,27 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.ast;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.jetbrains.python.PyTokenTypes;
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider;
|
||||
import com.jetbrains.python.ast.impl.PyPsiUtilsCore;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
package com.jetbrains.python.ast
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.jetbrains.python.PyTokenTypes
|
||||
import com.jetbrains.python.PythonDialectsTokenSetProvider
|
||||
import com.jetbrains.python.ast.impl.PyPsiUtilsCore
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public interface PyAstAugAssignmentStatement extends PyAstStatement {
|
||||
default @NotNull PyAstExpression getTarget() {
|
||||
final PyAstExpression target = childToPsi(PythonDialectsTokenSetProvider.getInstance().getExpressionTokens(), 0);
|
||||
if (target == null) {
|
||||
throw new RuntimeException("Target missing in augmented assignment statement");
|
||||
interface PyAstAugAssignmentStatement : PyAstStatement {
|
||||
val target: PyAstExpression
|
||||
get() {
|
||||
return childToPsi(PythonDialectsTokenSetProvider.getInstance().expressionTokens, 0)
|
||||
?: throw RuntimeException("Target missing in augmented assignment statement")
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
default @Nullable PyAstExpression getValue() {
|
||||
return childToPsi(PythonDialectsTokenSetProvider.getInstance().getExpressionTokens(), 1);
|
||||
}
|
||||
val value: PyAstExpression?
|
||||
get() = childToPsi(PythonDialectsTokenSetProvider.getInstance().expressionTokens, 1)
|
||||
|
||||
default @Nullable PsiElement getOperation() {
|
||||
return PyPsiUtilsCore.getChildByFilter(this, PyTokenTypes.AUG_ASSIGN_OPERATIONS, 0);
|
||||
}
|
||||
val operation: PsiElement?
|
||||
get() = PyPsiUtilsCore.getChildByFilter(this, PyTokenTypes.AUG_ASSIGN_OPERATIONS, 0)
|
||||
|
||||
@Override
|
||||
default void acceptPyVisitor(PyAstElementVisitor pyVisitor) {
|
||||
pyVisitor.visitPyAugAssignmentStatement(this);
|
||||
override fun acceptPyVisitor(pyVisitor: PyAstElementVisitor) {
|
||||
pyVisitor.visitPyAugAssignmentStatement(this)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
// 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;
|
||||
// Copyright 2000-2026 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.jetbrains.python.ast.PyAstAssignmentExpression;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.jetbrains.python.ast.PyAstAssignmentExpression
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
|
||||
/**
|
||||
* Represents assignment expressions introduced in Python 3.8 (PEP 572).
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface PyAssignmentExpression extends PyAstAssignmentExpression, PyExpression {
|
||||
interface PyAssignmentExpression : PyAstAssignmentExpression, PyExpression {
|
||||
override val target: PyTargetExpression?
|
||||
/**
|
||||
* @return LHS of an expression (before :=), null if underlying target is not an identifier.
|
||||
*/
|
||||
get() = super.target as PyTargetExpression?
|
||||
|
||||
/**
|
||||
* @return LHS of an expression (before :=), null if underlying target is not an identifier.
|
||||
*/
|
||||
@Override
|
||||
default @Nullable PyTargetExpression getTarget() {
|
||||
return (PyTargetExpression)PyAstAssignmentExpression.super.getTarget();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return RHS of an expression (after :=), null if assigned value is omitted or not an expression.
|
||||
*/
|
||||
@Override
|
||||
default @Nullable PyExpression getAssignedValue() {
|
||||
return (PyExpression)PyAstAssignmentExpression.super.getAssignedValue();
|
||||
}
|
||||
override val assignedValue: PyExpression?
|
||||
/**
|
||||
* @return RHS of an expression (after :=), null if assigned value is omitted or not an expression.
|
||||
*/
|
||||
get() = super.assignedValue as PyExpression?
|
||||
}
|
||||
|
||||
@@ -1,19 +1,12 @@
|
||||
// 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;
|
||||
// Copyright 2000-2026 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.jetbrains.python.ast.PyAstAugAssignmentStatement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.jetbrains.python.ast.PyAstAugAssignmentStatement
|
||||
|
||||
interface PyAugAssignmentStatement : PyAstAugAssignmentStatement, PyStatement {
|
||||
override val target: PyExpression
|
||||
get() = super.value as PyExpression
|
||||
|
||||
public interface PyAugAssignmentStatement extends PyAstAugAssignmentStatement, PyStatement {
|
||||
@Override
|
||||
default @NotNull PyExpression getTarget() {
|
||||
return (PyExpression)PyAstAugAssignmentStatement.super.getTarget();
|
||||
}
|
||||
|
||||
@Override
|
||||
default @Nullable PyExpression getValue() {
|
||||
return (PyExpression)PyAstAugAssignmentStatement.super.getValue();
|
||||
}
|
||||
override val value: PyExpression?
|
||||
get() = super.value as PyExpression?
|
||||
}
|
||||
|
||||
@@ -1,28 +1,11 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.jetbrains.python.psi;
|
||||
// Copyright 2000-2026 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.jetbrains.python.ast.PyAstQualifiedExpression;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import com.jetbrains.python.ast.PyAstQualifiedExpression
|
||||
|
||||
/**
|
||||
* Represents a qualified expression, that is, of "a.b.c..." sort.
|
||||
*/
|
||||
public interface PyQualifiedExpression extends PyAstQualifiedExpression, PyExpression {
|
||||
@Override
|
||||
@Nullable
|
||||
PyExpression getQualifier();
|
||||
interface PyQualifiedExpression : PyAstQualifiedExpression, PyExpression {
|
||||
override fun getQualifier(): PyExpression?
|
||||
}
|
||||
|
||||
+7
-13
@@ -1,18 +1,12 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.jetbrains.python.psi.impl;
|
||||
package com.jetbrains.python.psi.impl
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.jetbrains.python.psi.PyAugAssignmentStatement;
|
||||
import com.jetbrains.python.psi.PyElementVisitor;
|
||||
import com.intellij.lang.ASTNode
|
||||
import com.jetbrains.python.psi.PyAugAssignmentStatement
|
||||
import com.jetbrains.python.psi.PyElementVisitor
|
||||
|
||||
|
||||
public class PyAugAssignmentStatementImpl extends PyElementImpl implements PyAugAssignmentStatement {
|
||||
public PyAugAssignmentStatementImpl(ASTNode astNode) {
|
||||
super(astNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void acceptPyVisitor(PyElementVisitor pyVisitor) {
|
||||
pyVisitor.visitPyAugAssignmentStatement(this);
|
||||
class PyAugAssignmentStatementImpl(astNode: ASTNode?) : PyElementImpl(astNode), PyAugAssignmentStatement {
|
||||
override fun acceptPyVisitor(pyVisitor: PyElementVisitor) {
|
||||
pyVisitor.visitPyAugAssignmentStatement(this)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user