IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / packaging / PackageInMultipleModulesInspection.java
blobd40e00e2a93d8d85077ac60d6b77236cdb47256a
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.RefModule;
26 import com.intellij.codeInspection.reference.RefPackage;
27 import com.siyeh.InspectionGadgetsBundle;
28 import com.siyeh.ig.BaseGlobalInspection;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
32 import java.util.HashSet;
33 import java.util.List;
34 import java.util.Set;
36 public class PackageInMultipleModulesInspection extends BaseGlobalInspection {
39 @Override
40 @NotNull
41 public String getGroupDisplayName() {
42 return GroupNames.PACKAGING_GROUP_NAME;
45 @Override
46 @Nullable
47 public CommonProblemDescriptor[] checkElement(
48 RefEntity refEntity, AnalysisScope analysisScope,
49 InspectionManager inspectionManager,
50 GlobalInspectionContext globalInspectionContext) {
51 if (!(refEntity instanceof RefPackage)) {
52 return null;
54 final List<RefEntity> children = refEntity.getChildren();
55 if (children == null) {
56 return null;
58 final Set<RefModule> modules = new HashSet<RefModule>();
59 for (RefEntity child : children) {
60 if (!(child instanceof RefClass)) {
61 continue;
63 final RefClass refClass = (RefClass) child;
64 final RefModule module = refClass.getModule();
65 modules.add(module);
67 if (modules.size() <= 1) {
68 return null;
70 final String errorString =
71 InspectionGadgetsBundle.message(
72 "package.in.multiple.modules.problem.descriptor",
73 refEntity.getQualifiedName());
75 return new CommonProblemDescriptor[]{
76 inspectionManager.createProblemDescriptor(errorString)};