mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: don't generate instanceof class check in equals for final classes (IDEA-209430)
GitOrigin-RevId: 73f6b3e28dd466b9975f0c169b9c3d52fdf9ff82
This commit is contained in:
committed by
intellij-monorepo-bot
parent
9b2fe7815f
commit
053caa01b5
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.codeInsight.generation;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
@@ -127,12 +113,12 @@ public class GenerateEqualsHandler extends GenerateMembersHandlerBase {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] originalMembers) throws IncorrectOperationException {
|
||||
Project project = aClass.getProject();
|
||||
final boolean useInstanceofToCheckParameterType = CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER;
|
||||
protected List<? extends GenerationInfo> generateMemberPrototypes(PsiClass aClass, ClassMember[] originalMembers) {
|
||||
boolean isFinal = aClass.hasModifierProperty(PsiModifier.FINAL);
|
||||
final boolean useInstanceofToCheckParameterType = !isFinal && CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER;
|
||||
final boolean useAccessors = CodeInsightSettings.getInstance().USE_ACCESSORS_IN_EQUALS_HASHCODE;
|
||||
|
||||
GenerateEqualsHelper helper = new GenerateEqualsHelper(project, aClass, myEqualsFields, myHashCodeFields, myNonNullFields,
|
||||
GenerateEqualsHelper helper = new GenerateEqualsHelper(aClass.getProject(), aClass, myEqualsFields, myHashCodeFields, myNonNullFields,
|
||||
useInstanceofToCheckParameterType, useAccessors);
|
||||
return OverrideImplementUtil.convert2GenerationInfos(helper.generateMembers());
|
||||
}
|
||||
|
||||
@@ -252,7 +252,7 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
@Override
|
||||
protected void addSteps() {
|
||||
if (myEqualsPanel != null) {
|
||||
addStep(new TemplateChooserStep(myClass.hasModifierProperty(PsiModifier.FINAL), myClass));
|
||||
addStep(new TemplateChooserStep(myClass));
|
||||
}
|
||||
super.addSteps();
|
||||
}
|
||||
@@ -337,7 +337,7 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
private final class TemplateChooserStep extends StepAdapter {
|
||||
private final JComponent myPanel;
|
||||
|
||||
private TemplateChooserStep(boolean isFinal, PsiClass psiClass) {
|
||||
private TemplateChooserStep(PsiClass psiClass) {
|
||||
myPanel = new JPanel(new VerticalFlowLayout());
|
||||
final JPanel templateChooserPanel = new JPanel(new BorderLayout());
|
||||
final JLabel templateChooserLabel = new JLabel(JavaBundle.message("generate.equals.hashcode.template"));
|
||||
@@ -365,6 +365,7 @@ public class GenerateEqualsWizard extends AbstractGenerateEqualsWizard<PsiClass,
|
||||
myPanel.add(templateChooserPanel);
|
||||
|
||||
final JCheckBox checkbox = new NonFocusableCheckBox(JavaBundle.message("generate.equals.hashcode.accept.sublcasses"));
|
||||
boolean isFinal = myClass.hasModifierProperty(PsiModifier.FINAL);
|
||||
checkbox.setSelected(!isFinal && CodeInsightSettings.getInstance().USE_INSTANCEOF_ON_EQUALS_PARAMETER);
|
||||
checkbox.setEnabled(!isFinal);
|
||||
checkbox.addActionListener(new ActionListener() {
|
||||
|
||||
Reference in New Issue
Block a user