update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / i18n / InvalidPropertyKeyFormInspection.java
blobae07c215004274109e4c78edf816058702a9956e
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.i18n;
18 import com.intellij.lang.properties.PropertiesReferenceManager;
19 import com.intellij.lang.properties.psi.PropertiesFile;
20 import com.intellij.lang.properties.psi.Property;
21 import com.intellij.openapi.module.Module;
22 import com.intellij.uiDesigner.UIDesignerBundle;
23 import com.intellij.uiDesigner.inspections.FormErrorCollector;
24 import com.intellij.uiDesigner.inspections.StringDescriptorInspection;
25 import com.intellij.uiDesigner.lw.IComponent;
26 import com.intellij.uiDesigner.lw.IProperty;
27 import com.intellij.uiDesigner.lw.StringDescriptor;
28 import org.jetbrains.annotations.Nullable;
30 import java.util.List;
32 /**
33 * @author yole
35 public class InvalidPropertyKeyFormInspection extends StringDescriptorInspection {
36 public InvalidPropertyKeyFormInspection() {
37 super("UnresolvedPropertyKey");
40 protected void checkStringDescriptor(final Module module,
41 final IComponent component,
42 final IProperty prop,
43 final StringDescriptor descriptor,
44 final FormErrorCollector collector) {
45 String error = checkDescriptor(descriptor, module);
46 if (error != null) {
47 collector.addError(getID(), component, prop, error, null);
51 @Nullable
52 private static String checkDescriptor(final StringDescriptor descriptor, final Module module) {
53 final String bundleName = descriptor.getDottedBundleName();
54 final String key = descriptor.getKey();
55 if (bundleName == null && key == null) return null;
56 if (bundleName == null) {
57 return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.bundle.not.specified");
60 if (key == null) {
61 return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.property.key.not.specified");
64 PropertiesReferenceManager manager = PropertiesReferenceManager.getInstance(module.getProject());
65 List<PropertiesFile> propFiles = manager.findPropertiesFiles(module, bundleName);
67 if (propFiles.size() == 0) {
68 return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.bundle.not.found", bundleName);
71 for(PropertiesFile propFile: propFiles) {
72 final Property property = propFile.findPropertyByKey(key);
73 if (property == null) {
74 return UIDesignerBundle.message("inspection.invalid.property.in.form.quickfix.error.key.not.found",
75 key, bundleName, propFile.getLocale().getDisplayName());
78 return null;