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
;
33 import java
.util
.List
;
35 public class PackageWithTooFewClassesInspection
extends BaseGlobalInspection
{
37 @SuppressWarnings({"PublicField"})
42 public String
getGroupDisplayName() {
43 return GroupNames
.PACKAGING_GROUP_NAME
;
48 public CommonProblemDescriptor
[] checkElement(
50 AnalysisScope analysisScope
,
51 InspectionManager inspectionManager
,
52 GlobalInspectionContext globalInspectionContext
) {
53 if (!(refEntity
instanceof RefPackage
)) {
56 final List
<RefEntity
> children
= refEntity
.getChildren();
57 if (children
== null) {
61 for (RefEntity child
: children
) {
62 if(child
instanceof RefClass
) {
66 if(numClasses
>= limit
|| numClasses
== 0) {
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
)
79 public JComponent
createOptionsPanel() {
80 return new SingleIntegerFieldOptionsPanel(
81 InspectionGadgetsBundle
.message(
82 "package.with.too.few.classes.min.option"),