Search in sources :

Example 1 with GenerateEqualsHelper

use of com.intellij.codeInsight.generation.GenerateEqualsHelper in project intellij-community by JetBrains.

the class GenerateEqualsTestCase method performTest.

private static void performTest(Function<PsiField[], PsiField[]> equals, Function<PsiField[], PsiField[]> hashCode, Function<PsiField[], PsiField[]> nonNull, boolean insertOverride, boolean useAccessors) {
    CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
    settings.GENERATE_FINAL_LOCALS = true;
    settings.INSERT_OVERRIDE_ANNOTATION = insertOverride;
    CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
    try {
        PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
        if (element == null)
            return;
        PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
        if (aClass == null)
            return;
        PsiField[] fields = aClass.getFields();
        new GenerateEqualsHelper(getProject(), aClass, equals.fun(fields), hashCode.fun(fields), nonNull.fun(fields), false, useAccessors).invoke();
        FileDocumentManager.getInstance().saveAllDocuments();
    } finally {
        CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
    }
}
Also used : CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) PsiField(com.intellij.psi.PsiField) GenerateEqualsHelper(com.intellij.codeInsight.generation.GenerateEqualsHelper) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GenerateEqualsHelper (com.intellij.codeInsight.generation.GenerateEqualsHelper)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 CodeStyleSettings (com.intellij.psi.codeStyle.CodeStyleSettings)1