IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / packaging / PackageWithTooFewClassesInspection.java
blob74362d30fc7c94fb0e7aaa8593066aebf2f85274
1 /*
2 * Copyright 2006-2008 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.packaging;
18 import com.intellij.analysis.AnalysisScope;
19 import com.intellij.codeInsight.daemon.GroupNames;
20 import com.intellij.codeInspection.CommonProblemDescriptor;
21 import com.intellij.codeInspection.GlobalInspectionContext;
22 import com.intellij.codeInspection.InspectionManager;
23 import com.intellij.codeInspection.reference.RefClass;
24 import com.intellij.codeInspection.reference.RefEntity;
25 import com.intellij.codeInspection.reference.RefPackage;
26 import com.siyeh.InspectionGadgetsBundle;
27 import com.siyeh.ig.BaseGlobalInspection;
28 import com.intellij.codeInspection.ui.SingleIntegerFieldOptionsPanel;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
32 import javax.swing.*;
33 import java.util.List;
35 public class PackageWithTooFewClassesInspection extends BaseGlobalInspection {
37 @SuppressWarnings({"PublicField"})
38 public int limit = 3;
40 @Override
41 @NotNull
42 public String getGroupDisplayName() {
43 return GroupNames.PACKAGING_GROUP_NAME;
46 @Override
47 @Nullable
48 public CommonProblemDescriptor[] checkElement(
49 RefEntity refEntity,
50 AnalysisScope analysisScope,
51 InspectionManager inspectionManager,
52 GlobalInspectionContext globalInspectionContext) {
53 if (!(refEntity instanceof RefPackage)) {
54 return null;
56 final List<RefEntity> children = refEntity.getChildren();
57 if (children == null) {
58 return null;
60 int numClasses = 0;
61 for (RefEntity child : children) {
62 if(child instanceof RefClass) {
63 numClasses++;
66 if(numClasses >= limit || numClasses == 0) {
67 return null;
69 final String errorString = InspectionGadgetsBundle.message(
70 "package.with.too.few.classes.problem.descriptor",
71 refEntity.getQualifiedName(), Integer.valueOf(numClasses),
72 Integer.valueOf(limit));
73 return new CommonProblemDescriptor[]{
74 inspectionManager.createProblemDescriptor(errorString)
78 @Override
79 public JComponent createOptionsPanel() {
80 return new SingleIntegerFieldOptionsPanel(
81 InspectionGadgetsBundle.message(
82 "package.with.too.few.classes.min.option"),
83 this, "limit");