|
13 | 13 | * See the License for the specific language governing permissions and |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | | - |
17 | 16 | package com.intellij.uiDesigner.impl.binding; |
18 | 17 |
|
19 | | -import consulo.language.cacheBuilder.WordOccurrence; |
20 | | -import consulo.application.util.function.Processor; |
21 | | -import com.intellij.uiDesigner.lw.LwRootContainer; |
22 | | -import com.intellij.uiDesigner.lw.IComponent; |
23 | | -import com.intellij.uiDesigner.compiler.Utils; |
24 | 18 | import com.intellij.uiDesigner.compiler.AlienFormFileException; |
25 | 19 | import com.intellij.uiDesigner.compiler.UnexpectedFormElementException; |
| 20 | +import com.intellij.uiDesigner.compiler.Utils; |
26 | 21 | import com.intellij.uiDesigner.impl.FormEditingUtil; |
| 22 | +import com.intellij.uiDesigner.lw.IComponent; |
| 23 | +import com.intellij.uiDesigner.lw.LwRootContainer; |
27 | 24 | import consulo.language.cacheBuilder.SimpleWordsScanner; |
| 25 | +import consulo.language.cacheBuilder.WordOccurrence; |
28 | 26 | import consulo.logging.Logger; |
29 | 27 | import org.jdom.input.JDOMParseException; |
30 | 28 |
|
| 29 | +import java.util.function.Predicate; |
| 30 | + |
31 | 31 | /** |
32 | 32 | * @author yole |
33 | 33 | */ |
34 | | -public class FormWordsScanner extends SimpleWordsScanner |
35 | | -{ |
36 | | - private static final Logger LOG = Logger.getInstance(FormWordsScanner.class); |
| 34 | +public class FormWordsScanner extends SimpleWordsScanner { |
| 35 | + private static final Logger LOG = Logger.getInstance(FormWordsScanner.class); |
37 | 36 |
|
38 | | - @Override |
39 | | - public void processWords(CharSequence fileText, final Processor<WordOccurrence> processor) { |
40 | | - super.processWords(fileText, processor); |
| 37 | + @Override |
| 38 | + public void processWords(CharSequence fileText, final Predicate<WordOccurrence> processor) { |
| 39 | + super.processWords(fileText, processor); |
41 | 40 |
|
42 | | - try { |
43 | | - LwRootContainer container = Utils.getRootContainer(fileText.toString(), null/*no need component classes*/); |
44 | | - String className = container.getClassToBind(); |
45 | | - if (className != null) { |
46 | | - processClassAndPackagesNames(className, processor); |
47 | | - } |
| 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); |
| 46 | + } |
48 | 47 |
|
49 | | - FormEditingUtil.iterate(container, |
50 | | - new FormEditingUtil.ComponentVisitor() { |
51 | | - WordOccurrence occurence; |
52 | | - public boolean visit(IComponent iComponent) { |
53 | | - String componentClassName = iComponent.getComponentClassName(); |
54 | | - processClassAndPackagesNames(componentClassName, processor); |
55 | | - final String binding = iComponent.getBinding(); |
56 | | - if (binding != null) { |
57 | | - if (occurence == null) occurence = new WordOccurrence(binding, 0, binding.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE); |
58 | | - else occurence.init(binding, 0, binding.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE); |
59 | | - processor.process(occurence); |
60 | | - } |
61 | | - return true; |
62 | | - } |
63 | | - }); |
64 | | - } |
65 | | - catch(AlienFormFileException ex) { |
66 | | - // ignore |
67 | | - } |
68 | | - catch(UnexpectedFormElementException ex) { |
69 | | - // ignore |
70 | | - } |
71 | | - catch(JDOMParseException ex) { |
72 | | - // ignore |
73 | | - } |
74 | | - catch (Exception e) { |
75 | | - LOG.error("Error indexing form file", e); |
| 48 | + FormEditingUtil.iterate( |
| 49 | + container, |
| 50 | + new FormEditingUtil.ComponentVisitor() { |
| 51 | + WordOccurrence occurence; |
| 52 | + |
| 53 | + @Override |
| 54 | + public boolean visit(IComponent iComponent) { |
| 55 | + String componentClassName = iComponent.getComponentClassName(); |
| 56 | + processClassAndPackagesNames(componentClassName, processor); |
| 57 | + String binding = iComponent.getBinding(); |
| 58 | + if (binding != null) { |
| 59 | + if (occurence == null) { |
| 60 | + occurence = new WordOccurrence(binding, 0, binding.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE); |
| 61 | + } |
| 62 | + else { |
| 63 | + occurence.init(binding, 0, binding.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE); |
| 64 | + } |
| 65 | + processor.test(occurence); |
| 66 | + } |
| 67 | + return true; |
| 68 | + } |
| 69 | + } |
| 70 | + ); |
| 71 | + } |
| 72 | + catch (AlienFormFileException | UnexpectedFormElementException | JDOMParseException ex) { |
| 73 | + // ignore |
| 74 | + } |
| 75 | + catch (Exception e) { |
| 76 | + LOG.error("Error indexing form file", e); |
| 77 | + } |
76 | 78 | } |
77 | | - } |
78 | 79 |
|
79 | | - private static void processClassAndPackagesNames(String qName, final Processor<WordOccurrence> processor) { |
80 | | - WordOccurrence occurrence = new WordOccurrence(qName, 0, qName.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE); |
81 | | - processor.process(occurrence); |
82 | | - int idx = qName.lastIndexOf('.'); |
83 | | - |
84 | | - while (idx > 0) { |
85 | | - qName = qName.substring(0, idx); |
86 | | - occurrence.init(qName, 0,qName.length(),WordOccurrence.Kind.FOREIGN_LANGUAGE); |
87 | | - processor.process(occurrence); |
88 | | - idx = qName.lastIndexOf('.'); |
| 80 | + private static void processClassAndPackagesNames(String qName, Predicate<WordOccurrence> processor) { |
| 81 | + WordOccurrence occurrence = new WordOccurrence(qName, 0, qName.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE); |
| 82 | + processor.test(occurrence); |
| 83 | + int idx = qName.lastIndexOf('.'); |
| 84 | + |
| 85 | + while (idx > 0) { |
| 86 | + qName = qName.substring(0, idx); |
| 87 | + occurrence.init(qName, 0, qName.length(), WordOccurrence.Kind.FOREIGN_LANGUAGE); |
| 88 | + processor.test(occurrence); |
| 89 | + idx = qName.lastIndexOf('.'); |
| 90 | + } |
89 | 91 | } |
90 | | - } |
91 | 92 | } |
0 commit comments