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
;
35 public List
<String
> getSuggestions(@NotNull String text
) {
37 String
[] words
= NameUtil
.nameToWords(text
);
40 List
[] res
= new List
[words
.length
];
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
>();
51 List
<String
> variants
= manager
.getRawSuggestions(word
);
58 int[] counter
= new int[i
];
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
++) {
70 all
[k
] += res
[j
].get(counter
[j
]);
72 if (counter
[j
] >= res
[j
].size()) {
78 return Arrays
.asList(all
);