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
.psi
.filters
.getters
;
19 import com
.intellij
.codeInsight
.completion
.CompletionContext
;
20 import com
.intellij
.codeInsight
.completion
.CompletionUtil
;
21 import com
.intellij
.openapi
.util
.text
.StringUtil
;
22 import com
.intellij
.psi
.PsiElement
;
23 import com
.intellij
.psi
.filters
.ContextGetter
;
24 import com
.intellij
.psi
.impl
.cache
.impl
.id
.IdTableBuilding
;
25 import com
.intellij
.util
.ArrayUtil
;
27 import java
.util
.ArrayList
;
28 import java
.util
.List
;
30 public class AllWordsGetter
implements ContextGetter
{
31 public Object
[] get(final PsiElement context
, final CompletionContext completionContext
) {
32 final int offset
= completionContext
.getStartOffset();
33 return getAllWords(context
, offset
);
36 public static String
[] getAllWords(final PsiElement context
, final int offset
) {
37 if (StringUtil
.isEmpty(CompletionUtil
.findJavaIdentifierPrefix(context
, offset
))) {
38 return ArrayUtil
.EMPTY_STRING_ARRAY
;
41 final CharSequence chars
= context
.getContainingFile().getViewProvider().getContents(); // ??
42 final List
<String
> objs
= new ArrayList
<String
>();
43 IdTableBuilding
.scanWords(new IdTableBuilding
.ScanWordProcessor() {
44 public void run(final CharSequence chars
, final int start
, final int end
) {
45 if (start
> offset
|| offset
> end
) {
46 objs
.add(chars
.subSequence(start
, end
).toString());
49 }, chars
, 0, chars
.length());
50 return ArrayUtil
.toStringArray(objs
);