Spellchecker - do not produce out-of-element inspection highlight ranges
[fedora-idea.git] / plugins / spellchecker / src / com / intellij / spellchecker / BaseSuggestionProvider.java
blob20657aa6be71c69352379dc8807139a7931e3638
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.spellchecker;
18 import com.intellij.psi.codeStyle.NameUtil;
19 import com.intellij.spellchecker.engine.SuggestionProvider;
20 import org.jetbrains.annotations.NotNull;
22 import java.util.ArrayList;
23 import java.util.Arrays;
24 import java.util.List;
26 public class BaseSuggestionProvider implements SuggestionProvider {
28 private final SpellCheckerManager manager;
30 public BaseSuggestionProvider(@NotNull SpellCheckerManager manager) {
31 this.manager = manager;
34 @NotNull
35 public List<String> getSuggestions(@NotNull String text) {
37 String[] words = NameUtil.nameToWords(text);
39 int index = 0;
40 List[] res = new List[words.length];
41 int i = 0;
42 for (String word : words) {
43 int start = text.indexOf(word, index);
44 int end = start + word.length();
45 if (!manager.hasProblem(word)) {
46 List<String> variants = new ArrayList<String>();
47 variants.add(word);
48 res[i++] = variants;
50 else {
51 List<String> variants = manager.getRawSuggestions(word);
52 res[i++] = variants;
54 index = end;
57 String[] all = null;
58 int[] counter = new int[i];
59 int size = 1;
60 for (int j = 0; j < i; j++) {
61 size *= res[j].size();
63 all = new String[size];
65 for (int k = 0; k < size; k++) {
66 for (int j = 0; j < i; j++) {
67 if (all[k] == null) {
68 all[k] = "";
70 all[k] += res[j].get(counter[j]);
71 counter[j]++;
72 if (counter[j] >= res[j].size()) {
73 counter[j] = 0;
78 return Arrays.asList(all);