Inspections - pass onTheFly into ProblemDescriptors & use it to create LAZY refs...
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / inspections / FormFileErrorCollector.java
blob4adf77d8faf32692d4e2cba95ebe665511373078
1 /*
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.codeInspection.InspectionManager;
19 import com.intellij.codeInspection.LocalQuickFix;
20 import com.intellij.codeInspection.ProblemDescriptor;
21 import com.intellij.codeInspection.ProblemHighlightType;
22 import com.intellij.codeInspection.ex.ProblemDescriptorImpl;
23 import com.intellij.openapi.util.JDOMUtil;
24 import com.intellij.psi.PsiFile;
25 import com.intellij.uiDesigner.lw.IComponent;
26 import com.intellij.uiDesigner.lw.IProperty;
27 import com.intellij.uiDesigner.make.FormElementNavigatable;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
31 import java.util.ArrayList;
32 import java.util.List;
34 /**
35 * @author yole
37 public class FormFileErrorCollector extends FormErrorCollector {
38 private final InspectionManager myManager;
39 private final PsiFile myFile;
40 private boolean myOnTheFly;
41 private final List<ProblemDescriptor> myProblems = new ArrayList<ProblemDescriptor>();
43 public FormFileErrorCollector(final PsiFile file, final InspectionManager manager, boolean onTheFly) {
44 myManager = manager;
45 myFile = file;
46 myOnTheFly = onTheFly;
49 public void addError(final String inspectionId, final IComponent component, @Nullable IProperty prop,
50 @NotNull String errorMessage,
51 @Nullable EditorQuickFixProvider editorQuickFixProvider) {
52 final ProblemDescriptor problemDescriptor = myManager.createProblemDescriptor(myFile, JDOMUtil.escapeText(errorMessage),
53 (LocalQuickFix)null,
54 ProblemHighlightType.GENERIC_ERROR_OR_WARNING, myOnTheFly);
55 if (problemDescriptor instanceof ProblemDescriptorImpl && component != null) {
56 FormElementNavigatable navigatable = new FormElementNavigatable(myFile.getProject(), myFile.getVirtualFile(),
57 component.getId());
58 ((ProblemDescriptorImpl) problemDescriptor).setNavigatable(navigatable);
60 myProblems.add(problemDescriptor);
63 public ProblemDescriptor[] result() {
64 return myProblems.toArray(new ProblemDescriptor[myProblems.size()]);