mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed PY-2796 Py2.4 compatibility: missing highlighting when yield value is assigned to a variable
This commit is contained in:
@@ -20,6 +20,7 @@ import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
@@ -572,10 +573,24 @@ public class PyCompatibilityInspection extends PyInspection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792
|
||||
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
|
||||
if (myVersionsToProcess.contains(LanguageLevel.PYTHON24)) {
|
||||
if (node.getAssignedValue() instanceof PyConditionalExpression)
|
||||
PyExpression assignedValue = node.getAssignedValue();
|
||||
if (assignedValue instanceof PyConditionalExpression) // PY-2792
|
||||
registerProblem(node, "Python version 2.4 doesn't support this syntax.");
|
||||
|
||||
Stack<PsiElement> st = new Stack<PsiElement>(); // PY-2796
|
||||
st.push(assignedValue);
|
||||
while (!st.isEmpty()) {
|
||||
PsiElement el = st.pop();
|
||||
if (el instanceof PyYieldExpression)
|
||||
registerProblem(node, "Python version 2.4 doesn't support this syntax." +
|
||||
"In Python <= 2.4, yield was a statement; it didn’t return any value.");
|
||||
else {
|
||||
for (PsiElement e : el.getChildren())
|
||||
st.push(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.jetbrains.python.psi.impl.PyQualifiedName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
* @author Alexey.Ivanov
|
||||
@@ -298,6 +299,7 @@ public class UnsupportedFeatures extends PyAnnotator {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyFromImportStatement(PyFromImportStatement node) {
|
||||
PyReferenceExpression importSource = node.getImportSource();
|
||||
@@ -306,21 +308,38 @@ public class UnsupportedFeatures extends PyAnnotator {
|
||||
getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyAssignmentStatement(PyAssignmentStatement node) { // PY-2792
|
||||
public void visitPyAssignmentStatement(PyAssignmentStatement node) {
|
||||
if (getLanguageLevel(node) == LanguageLevel.PYTHON24) {
|
||||
if (node.getAssignedValue() instanceof PyConditionalExpression)
|
||||
PyExpression assignedValue = node.getAssignedValue();
|
||||
if (assignedValue instanceof PyConditionalExpression) // PY-2792
|
||||
getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax.");
|
||||
|
||||
Stack<PsiElement> st = new Stack<PsiElement>(); // PY-2796
|
||||
st.push(assignedValue);
|
||||
while (!st.isEmpty()) {
|
||||
PsiElement el = st.pop();
|
||||
if (el instanceof PyYieldExpression)
|
||||
getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax." +
|
||||
"In Python <= 2.4, yield was a statement; it didn’t return any value.");
|
||||
else {
|
||||
for (PsiElement e : el.getChildren())
|
||||
st.push(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitPyTryExceptStatement(PyTryExceptStatement node) { // PY-2795
|
||||
if (getLanguageLevel(node) == LanguageLevel.PYTHON24) {
|
||||
PyExceptPart[] excepts = node.getExceptParts();
|
||||
PyFinallyPart finallyPart = node.getFinallyPart();
|
||||
if (excepts.length != 0 && finallyPart != null)
|
||||
getHolder().createWarningAnnotation(node, "Python version 2.4 doesn't support this syntax. You could use a finally block to ensure " +
|
||||
"that code is always executed, or one or more except blocks to catch specific exceptions.");
|
||||
getHolder().createWarningAnnotation(node,
|
||||
"Python version 2.4 doesn't support this syntax. You could use a finally block to ensure " +
|
||||
"that code is always executed, or one or more except blocks to catch specific exceptions.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user