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
.codeInsight
.completion
;
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.psi
.PsiFile
;
20 import com
.intellij
.psi
.PsiReference
;
21 import com
.intellij
.psi
.impl
.source
.resolve
.reference
.impl
.PsiMultiReference
;
22 import com
.intellij
.psi
.impl
.source
.resolve
.reference
.impl
.providers
.JavaClassReference
;
23 import org
.jetbrains
.annotations
.NotNull
;
28 public class JavaClassReferenceCompletionContributor
extends CompletionContributor
{
30 public void beforeCompletion(@NotNull final CompletionInitializationContext context
) {
31 final PsiFile file
= context
.getFile();
32 final Project project
= context
.getProject();
34 JavaCompletionUtil
.initOffsets(file
, project
, context
.getOffsetMap());
36 PsiReference reference
= file
.findReferenceAt(context
.getStartOffset());
37 if (reference
instanceof PsiMultiReference
) {
38 for (final PsiReference psiReference
: ((PsiMultiReference
)reference
).getReferences()) {
39 if (psiReference
instanceof JavaClassReference
) {
40 reference
= psiReference
;
45 if (reference
instanceof JavaClassReference
) {
46 final JavaClassReference classReference
= (JavaClassReference
)reference
;
47 if (classReference
.getExtendClassNames() != null) {
48 final PsiReference
[] references
= classReference
.getJavaClassReferenceSet().getReferences();
49 final PsiReference lastReference
= references
[references
.length
- 1];
50 final int endOffset
= lastReference
.getRangeInElement().getEndOffset() + lastReference
.getElement().getTextRange().getStartOffset();
51 context
.getOffsetMap().addOffset(CompletionInitializationContext
.IDENTIFIER_END_OFFSET
, endOffset
);