mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-97330 (Change default pattern of "Enumerated constant naming")
This commit is contained in:
+7
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -61,29 +61,23 @@ public class ConstantNamingConventionInspection extends ConventionInspection {
|
||||
public String buildErrorString(Object... infos) {
|
||||
final String fieldName = (String)infos[0];
|
||||
if (fieldName.length() < getMinLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"constant.naming.convention.problem.descriptor.short");
|
||||
return InspectionGadgetsBundle.message("constant.naming.convention.problem.descriptor.short");
|
||||
}
|
||||
else if (fieldName.length() > getMaxLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"constant.naming.convention.problem.descriptor.long");
|
||||
return InspectionGadgetsBundle.message("constant.naming.convention.problem.descriptor.long");
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"constant.naming.convention.problem.descriptor.regex.mismatch",
|
||||
getRegex());
|
||||
return InspectionGadgetsBundle.message("constant.naming.convention.problem.descriptor.regex.mismatch", getRegex());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<? extends JComponent> createExtraOptions() {
|
||||
return Arrays.asList(
|
||||
new CheckBox(InspectionGadgetsBundle.message(
|
||||
"constant.naming.convention.immutables.option"), this,
|
||||
"onlyCheckImmutables"));
|
||||
new CheckBox(InspectionGadgetsBundle.message("constant.naming.convention.immutables.option"), this, "onlyCheckImmutables"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultRegex() {
|
||||
return "[A-Z_\\d]*";
|
||||
return "[A-Z][A-Z_\\d]*";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -109,8 +103,7 @@ public class ConstantNamingConventionInspection extends ConventionInspection {
|
||||
if (field instanceof PsiEnumConstant) {
|
||||
return;
|
||||
}
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
!field.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
if (!field.hasModifierProperty(PsiModifier.STATIC) || !field.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return;
|
||||
}
|
||||
final String name = field.getName();
|
||||
|
||||
+7
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2012 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,8 +22,7 @@ import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class EnumeratedConstantNamingConventionInspection
|
||||
extends ConventionInspection {
|
||||
public class EnumeratedConstantNamingConventionInspection extends ConventionInspection {
|
||||
|
||||
private static final int DEFAULT_MIN_LENGTH = 5;
|
||||
private static final int DEFAULT_MAX_LENGTH = 32;
|
||||
@@ -31,8 +30,7 @@ public class EnumeratedConstantNamingConventionInspection
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"enumerated.constant.naming.convention.display.name");
|
||||
return InspectionGadgetsBundle.message("enumerated.constant.naming.convention.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -50,21 +48,17 @@ public class EnumeratedConstantNamingConventionInspection
|
||||
public String buildErrorString(Object... infos) {
|
||||
final String fieldName = (String)infos[0];
|
||||
if (fieldName.length() < getMinLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"enumerated.constant.naming.convention.problem.descriptor.short");
|
||||
return InspectionGadgetsBundle.message("enumerated.constant.naming.convention.problem.descriptor.short");
|
||||
}
|
||||
else if (fieldName.length() > getMaxLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"enumerated.constant.naming.convention.problem.descriptor.long");
|
||||
return InspectionGadgetsBundle.message("enumerated.constant.naming.convention.problem.descriptor.long");
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"enumerated.constant.naming.convention.problem.descriptor.regex.mismatch",
|
||||
getRegex());
|
||||
return InspectionGadgetsBundle.message("enumerated.constant.naming.convention.problem.descriptor.regex.mismatch", getRegex());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultRegex() {
|
||||
return "[A-Z][A-Za-z\\d]*";
|
||||
return "[A-Z][A-Z_\\d]*";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.siyeh.igtest.naming.constant_naming_convention;
|
||||
|
||||
class ConstantNamingConvention {
|
||||
static final String A_B_C_D3 = "";
|
||||
static final String a = "";
|
||||
static final String aaaaaa = "";
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>ConstantNamingConvention.java</file>
|
||||
<line>5</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constant naming convention</problem_class>
|
||||
<description>Constant name <code>a</code> is too short #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>ConstantNamingConvention.java</file>
|
||||
<line>6</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Constant naming convention</problem_class>
|
||||
<description>Constant <code>aaaaaa</code> doesn't match regex '[A-Z][A-Z_\d]*' #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package com.siyeh.igtest.naming.enumerated_constant_naming_convention;
|
||||
|
||||
enum EnumeratedConstantNamingConvention {
|
||||
A_B_C,
|
||||
A,
|
||||
aaaaaa
|
||||
}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems>
|
||||
<problem>
|
||||
<file>EnumeratedConstantNamingConvention.java</file>
|
||||
<line>5</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Enumerated constant naming convention</problem_class>
|
||||
<description>Enumerated constant name <code>A</code> is too short #loc</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>EnumeratedConstantNamingConvention.java</file>
|
||||
<line>6</line>
|
||||
<problem_class severity="WARNING" attribute_key="WARNING_ATTRIBUTES">Enumerated constant naming convention</problem_class>
|
||||
<description>Enumerated constant <code>aaaaaa</code> doesn't match regex '[A-Z][A-Z_\d]*' #loc</description>
|
||||
</problem>
|
||||
</problems>
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.siyeh.ig.naming;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class ConstantNamingConventionInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doTest("com/siyeh/igtest/naming/constant_naming_convention", new ConstantNamingConventionInspection());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
package com.siyeh.ig.naming;
|
||||
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
|
||||
public class EnumeratedConstantNamingConventionInspectionTest extends IGInspectionTestCase {
|
||||
|
||||
public void test() throws Exception {
|
||||
doTest("com/siyeh/igtest/naming/enumerated_constant_naming_convention", new EnumeratedConstantNamingConventionInspection());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user