コード例 #1
0
 @Override
 protected PsiElement replaceExpression(
     PsiElement expression, PyExpression newExpression, IntroduceOperation operation) {
   if (operation.getInitPlace() != InitPlace.SAME_METHOD) {
     return PyReplaceExpressionUtil.replaceExpression(expression, newExpression);
   }
   return super.replaceExpression(expression, newExpression, operation);
 }
コード例 #2
0
 @Nullable
 @Override
 protected PsiElement addDeclaration(
     @NotNull PsiElement expression,
     @NotNull PsiElement declaration,
     @NotNull IntroduceOperation operation) {
   final PsiElement expr = expression instanceof PyClass ? expression : expression.getParent();
   PsiElement anchor = PyUtil.getContainingClassOrSelf(expr);
   assert anchor instanceof PyClass;
   final PyClass clazz = (PyClass) anchor;
   final Project project = anchor.getProject();
   if (operation.getInitPlace() == InitPlace.CONSTRUCTOR && !inConstructor(expression)) {
     return AddFieldQuickFix.addFieldToInit(
         project, clazz, "", new AddFieldDeclaration(declaration));
   } else if (operation.getInitPlace() == InitPlace.SET_UP) {
     return addFieldToSetUp(clazz, new AddFieldDeclaration(declaration));
   }
   return PyIntroduceVariableHandler.doIntroduceVariable(
       expression, declaration, operation.getOccurrences(), operation.isReplaceAll());
 }