update copyright
[fedora-idea.git] / plugins / ui-designer / src / com / intellij / uiDesigner / binding / FormWordsScanner.java
blob03f16503e1a7fe5f781c28b2e84a8f19f0ccf7fb
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.
17 package com.intellij.uiDesigner.binding;
19 import com.intellij.lang.cacheBuilder.SimpleWordsScanner;
20 import com.intellij.lang.cacheBuilder.WordOccurrence;
21 import com.intellij.util.Processor;
22 import com.intellij.uiDesigner.lw.LwRootContainer;
23 import com.intellij.uiDesigner.lw.IComponent;
24 import com.intellij.uiDesigner.compiler.Utils;
25 import com.intellij.uiDesigner.compiler.AlienFormFileException;
26 import com.intellij.uiDesigner.compiler.UnexpectedFormElementException;
27 import com.intellij.uiDesigner.FormEditingUtil;
28 import com.intellij.openapi.diagnostic.Logger;
29 import org.jdom.input.JDOMParseException;
31 /**
32 * @author yole
34 public class FormWordsScanner extends SimpleWordsScanner {
35 private static final Logger LOG = Logger.getInstance("#com.intellij.uiDesigner.binding.FormWordsScanner");
37 @Override
38 public void processWords(CharSequence fileText, final Processor<WordOccurrence> processor) {
39 super.processWords(fileText, processor);
41 try {
42 LwRootContainer container = Utils.getRootContainer(fileText.toString(), null/*no need component classes*/);
43 String className = container.getClassToBind();
44 if (className != null) {
45 processClassAndPackagesNames(className, processor);
48 FormEditingUtil.iterate(container,
49 new FormEditingUtil.ComponentVisitor() {
50 WordOccurrence occurence;
51 public boolean visit(IComponent iComponent) {
52 String componentClassName = iComponent.getComponentClassName();
53 processClassAndPackagesNames(componentClassName, processor);
54 final String binding = iComponent.getBinding();
55 if (binding != null) {
56 if (occurence == null) occurence = new WordOccurrence(binding, 0, binding.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE);
57 else occurence.init(binding, 0, binding.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE);
58 processor.process(occurence);
60 return true;
62 });
64 catch(AlienFormFileException ex) {
65 // ignore
67 catch(UnexpectedFormElementException ex) {
68 // ignore
70 catch(JDOMParseException ex) {
71 // ignore
73 catch (Exception e) {
74 LOG.error("Error indexing form file", e);
78 private static void processClassAndPackagesNames(String qName, final Processor<WordOccurrence> processor) {
79 WordOccurrence occurrence = new WordOccurrence(qName, 0, qName.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE);
80 processor.process(occurrence);
81 int idx = qName.lastIndexOf('.');
83 while (idx > 0) {
84 qName = qName.substring(0, idx);
85 occurrence.init(qName, 0,qName.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE);
86 processor.process(occurrence);
87 idx = qName.lastIndexOf('.');