2 * Copyright 2000-2009 JetBrains s.r.o.
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
.intellij
.uiDesigner
.inspections
;
18 import com
.intellij
.codeInsight
.daemon
.HighlightDisplayKey
;
19 import com
.intellij
.codeInspection
.*;
20 import com
.intellij
.openapi
.fileTypes
.StdFileTypes
;
21 import com
.intellij
.openapi
.module
.Module
;
22 import com
.intellij
.openapi
.module
.ModuleUtil
;
23 import com
.intellij
.openapi
.vfs
.VirtualFile
;
24 import com
.intellij
.profile
.codeInspection
.InspectionProjectProfileManager
;
25 import com
.intellij
.psi
.PsiElement
;
26 import com
.intellij
.psi
.PsiFile
;
27 import com
.intellij
.uiDesigner
.ErrorInfo
;
28 import com
.intellij
.uiDesigner
.FormEditingUtil
;
29 import com
.intellij
.uiDesigner
.PsiPropertiesProvider
;
30 import com
.intellij
.uiDesigner
.UIDesignerBundle
;
31 import com
.intellij
.uiDesigner
.compiler
.Utils
;
32 import com
.intellij
.uiDesigner
.designSurface
.GuiEditor
;
33 import com
.intellij
.uiDesigner
.lw
.IComponent
;
34 import com
.intellij
.uiDesigner
.lw
.IRootContainer
;
35 import com
.intellij
.uiDesigner
.lw
.LwRootContainer
;
36 import com
.intellij
.uiDesigner
.quickFixes
.FormInspectionTool
;
37 import com
.intellij
.uiDesigner
.radComponents
.RadComponent
;
38 import org
.jetbrains
.annotations
.Nls
;
39 import org
.jetbrains
.annotations
.NonNls
;
40 import org
.jetbrains
.annotations
.NotNull
;
41 import org
.jetbrains
.annotations
.Nullable
;
46 public abstract class BaseFormInspection
extends BaseJavaLocalInspectionTool
implements FileCheckingInspection
, FormInspectionTool
{
47 private final String myInspectionKey
;
49 public BaseFormInspection(@NonNls @NotNull String inspectionKey
) {
50 myInspectionKey
= inspectionKey
;
54 public String
getDisplayName() {
59 public String
getGroupDisplayName() {
60 return UIDesignerBundle
.message("form.inspections.group");
63 @NotNull @NonNls public String
getShortName() {
64 return myInspectionKey
;
67 @Override public boolean isEnabledByDefault() {
71 public boolean isActive(PsiElement psiRoot
) {
72 final InspectionProfile profile
= InspectionProjectProfileManager
.getInstance(psiRoot
.getProject()).getInspectionProfile();
73 HighlightDisplayKey key
= HighlightDisplayKey
.find(myInspectionKey
);
74 return key
!= null && profile
.isToolEnabled(key
, psiRoot
);
77 @Nullable public ProblemDescriptor
[] checkFile(@NotNull PsiFile file
, @NotNull InspectionManager manager
, boolean isOnTheFly
) {
78 if (file
.getFileType().equals(StdFileTypes
.GUI_DESIGNER_FORM
)) {
79 final VirtualFile virtualFile
= file
.getVirtualFile();
80 if (virtualFile
== null) {
83 final Module module
= ModuleUtil
.findModuleForFile(virtualFile
, file
.getProject());
88 final LwRootContainer rootContainer
;
90 rootContainer
= Utils
.getRootContainer(file
.getText(), new PsiPropertiesProvider(module
));
96 if (rootContainer
.isInspectionSuppressed(getShortName(), null)) {
99 final FormFileErrorCollector collector
= new FormFileErrorCollector(file
, manager
, isOnTheFly
);
100 startCheckForm(rootContainer
);
101 FormEditingUtil
.iterate(rootContainer
, new FormEditingUtil
.ComponentVisitor() {
102 public boolean visit(final IComponent component
) {
103 if (!rootContainer
.isInspectionSuppressed(getShortName(), component
.getId())) {
104 checkComponentProperties(module
, component
, collector
);
109 doneCheckForm(rootContainer
);
110 return collector
.result();
115 public void startCheckForm(IRootContainer rootContainer
) {
118 public void doneCheckForm(IRootContainer rootContainer
) {
122 public ErrorInfo
[] checkComponent(@NotNull GuiEditor editor
, @NotNull RadComponent component
) {
123 FormEditorErrorCollector collector
= new FormEditorErrorCollector(editor
, component
);
124 checkComponentProperties(component
.getModule(), component
, collector
);
125 return collector
.result();
128 protected abstract void checkComponentProperties(Module module
, IComponent component
, FormErrorCollector collector
);