@Nullable
 protected PsiElement replaceExpression(
     PsiElement expression, PyExpression newExpression, IntroduceOperation operation) {
   PyExpressionStatement statement =
       PsiTreeUtil.getParentOfType(expression, PyExpressionStatement.class);
   if (statement != null) {
     if (statement.getExpression() == expression
         && expression.getUserData(PyReplaceExpressionUtil.SELECTION_BREAKS_AST_NODE) == null) {
       statement.delete();
       return null;
     }
   }
   return PyReplaceExpressionUtil.replaceExpression(expression, newExpression);
 }
Ejemplo n.º 2
0
 @Nullable
 public static String extractDeprecationMessage(List<PyStatement> statements) {
   for (PyStatement statement : statements) {
     if (statement instanceof PyExpressionStatement) {
       PyExpressionStatement expressionStatement = (PyExpressionStatement) statement;
       if (expressionStatement.getExpression() instanceof PyCallExpression) {
         PyCallExpression callExpression = (PyCallExpression) expressionStatement.getExpression();
         if (callExpression.isCalleeText(PyNames.WARN)) {
           PyReferenceExpression warningClass =
               callExpression.getArgument(1, PyReferenceExpression.class);
           if (warningClass != null
               && (PyNames.DEPRECATION_WARNING.equals(warningClass.getReferencedName())
                   || PyNames.PENDING_DEPRECATION_WARNING.equals(
                       warningClass.getReferencedName()))) {
             return PyPsiUtils.strValue(callExpression.getArguments()[0]);
           }
         }
       }
     }
   }
   return null;
 }