IDEADEV-31824 (Incorrect "manual array copy" warning)
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / naming / ClassNamingConventionInspection.java
blob2ce3ceb979702c6d5167850ad8af03a6bb4a2a01
1 /*
2 * Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.siyeh.ig.naming;
18 import com.intellij.psi.PsiClass;
19 import com.intellij.psi.PsiTypeParameter;
20 import com.siyeh.InspectionGadgetsBundle;
21 import com.siyeh.ig.BaseInspectionVisitor;
22 import com.siyeh.ig.InspectionGadgetsFix;
23 import com.siyeh.ig.fixes.RenameFix;
24 import org.jetbrains.annotations.NotNull;
26 public class ClassNamingConventionInspection extends ConventionInspection {
28 private static final int DEFAULT_MIN_LENGTH = 8;
29 private static final int DEFAULT_MAX_LENGTH = 64;
31 @NotNull
32 public String getDisplayName() {
33 return InspectionGadgetsBundle.message(
34 "class.naming.convention.display.name");
37 protected InspectionGadgetsFix buildFix(Object... infos) {
38 return new RenameFix();
41 protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
42 return true;
45 @NotNull
46 public String buildErrorString(Object... infos) {
47 final String className = (String)infos[0];
48 if (className.length() < getMinLength()) {
49 return InspectionGadgetsBundle.message(
50 "class.name.convention.problem.descriptor.short");
52 else if (className.length() > getMaxLength()) {
53 return InspectionGadgetsBundle.message(
54 "class.name.convention.problem.descriptor.long");
56 return InspectionGadgetsBundle.message(
57 "class.name.convention.problem.descriptor.regex.mismatch",
58 getRegex());
61 protected String getDefaultRegex() {
62 return "[A-Z][A-Za-z\\d]*";
65 protected int getDefaultMinLength() {
66 return DEFAULT_MIN_LENGTH;
69 protected int getDefaultMaxLength() {
70 return DEFAULT_MAX_LENGTH;
73 public BaseInspectionVisitor buildVisitor() {
74 return new NamingConventionsVisitor();
77 private class NamingConventionsVisitor extends BaseInspectionVisitor {
79 @Override public void visitClass(@NotNull PsiClass aClass) {
80 if (aClass.isInterface() || aClass.isAnnotationType() ||
81 aClass.isEnum()) {
82 return;
84 if (aClass instanceof PsiTypeParameter) {
85 return;
87 final String name = aClass.getName();
88 if (name == null) {
89 return;
91 if (isValid(name)) {
92 return;
94 registerClassError(aClass, name);