mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
naming conventions: provide equals/hashcode for custom beans
This commit is contained in:
@@ -15,6 +15,8 @@ import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @see NamingConventionWithFallbackBean for default fallbacks
|
||||
*
|
||||
* When beans have custom fields, ensure to provide {@link #equals(Object)}/{@link #hashCode()} for correct serialization
|
||||
*/
|
||||
public class NamingConventionBean {
|
||||
public String m_regex;
|
||||
|
||||
+19
-2
@@ -3,13 +3,12 @@
|
||||
// found in the LICENSE file.
|
||||
package com.intellij.codeInspection.naming;
|
||||
|
||||
import com.intellij.psi.PsiNameIdentifierOwner;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class NamingConventionWithFallbackBean<T extends PsiNameIdentifierOwner> extends NamingConventionBean {
|
||||
public class NamingConventionWithFallbackBean extends NamingConventionBean {
|
||||
public boolean inheritDefaultSettings = false;
|
||||
|
||||
public NamingConventionWithFallbackBean(String regex, int minLength, int maxLength, String... predefinedNames) {
|
||||
@@ -20,6 +19,24 @@ public class NamingConventionWithFallbackBean<T extends PsiNameIdentifierOwner>
|
||||
return inheritDefaultSettings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof NamingConventionWithFallbackBean)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
NamingConventionWithFallbackBean bean = (NamingConventionWithFallbackBean)o;
|
||||
|
||||
if (inheritDefaultSettings != bean.inheritDefaultSettings) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * super.hashCode() + (inheritDefaultSettings ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
JPanel panel = new JPanel(new BorderLayout());
|
||||
|
||||
@@ -84,5 +84,22 @@ public class ConstantNamingConvention extends NamingConvention<PsiField> {
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ConstantNamingConventionBean)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
ConstantNamingConventionBean bean = (ConstantNamingConventionBean)o;
|
||||
|
||||
if (onlyCheckImmutables != bean.onlyCheckImmutables) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * super.hashCode() + (onlyCheckImmutables ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,5 +86,22 @@ public class StaticVariableNamingConvention extends NamingConvention<PsiField> {
|
||||
return panel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof ConstantNamingConventionBean)) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
|
||||
ConstantNamingConventionBean bean = (ConstantNamingConventionBean)o;
|
||||
|
||||
if (checkMutableFinals != bean.checkMutableFinals) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return 31 * super.hashCode() + (checkMutableFinals ? 1 : 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user