// 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.inspections.quickfix;

import com.intellij.codeInspection.LocalQuickFix;
import com.intellij.codeInspection.ProblemDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiReference;
import com.jetbrains.python.PyPsiBundle;
import com.jetbrains.python.psi.*;
import com.jetbrains.python.refactoring.PyPsiRefactoringUtil;
import org.jetbrains.annotations.NotNull;

import java.util.Map;

public class PyAddPropertyForFieldQuickFix implements LocalQuickFix {
  private String myName = PyPsiBundle.message("QFIX.add.property");

  public PyAddPropertyForFieldQuickFix(String name) {
    myName = name;
  }

  @Override
  @NotNull
  public String getFamilyName() {
    return myName;
  }

  @Override
  public void applyFix(@NotNull final Project project, @NotNull final ProblemDescriptor descriptor) {
    final PsiElement element = descriptor.getPsiElement();
    if (element instanceof PyReferenceExpression) {
      final PsiReference reference = element.getReference();
      if (reference == null) return;
      final PsiElement resolved = reference.resolve();
      if (resolved instanceof PyTargetExpression) {
        PyTargetExpression target = (PyTargetExpression)resolved;
        final PyClass containingClass = target.getContainingClass();
        if (containingClass != null) {
          final String name = target.getName();
          if (name == null) return;
          String propertyName = StringUtil.trimStart(name, "_");
          final Map<String,Property> properties = containingClass.getProperties();
          final PyElementGenerator generator = PyElementGenerator.getInstance(project);
          if (!properties.containsKey(propertyName)) {
            final PyFunction property = generator.createProperty(LanguageLevel.forElement(containingClass), propertyName, name, AccessDirection.READ);
            PyPsiRefactoringUtil.addElementToStatementList(property, containingClass.getStatementList(), false);
          }
          final PyExpression qualifier = ((PyReferenceExpression)element).getQualifier();
          if (qualifier != null) {
            String newElementText = qualifier.getText() + "." + propertyName;
            final PyExpression newElement = generator.createExpressionFromText(LanguageLevel.forElement(containingClass), newElementText);
            element.replace(newElement);
          }
        }
      }
    }
  }
}

@@ -290,16 +290,77 @@
 riptor;%0A
+import com.intellij.codeInspection.util.IntentionFamilyName;%0A
 import c
@@ -524,49 +524,8 @@
 ce;%0A
-import com.jetbrains.python.PyPsiBundle;%0A
 impo
@@ -767,64 +767,48 @@
 ate 
-String myName = PyPsiBundle.message(%22QFIX.add.property%22)
+final @IntentionFamilyName String myName
 ;%0A%0A 
@@ -845,16 +845,46 @@
 uickFix(
+@NotNull @IntentionFamilyName 
 String n

Annotate PyAddPropertyForFieldQuickFix