update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / hint / ClassDeclarationRangeHandler.java
blob9bb92668dc669c78e2fc12090fed00dfd44c66aa
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.codeInsight.hint;
18 import org.jetbrains.annotations.NotNull;
19 import com.intellij.openapi.util.TextRange;
20 import com.intellij.psi.*;
22 public class ClassDeclarationRangeHandler implements DeclarationRangeHandler {
23 @NotNull
24 public TextRange getDeclarationRange(@NotNull final PsiElement container) {
25 PsiClass aClass = (PsiClass)container;
26 if (aClass instanceof PsiAnonymousClass){
27 PsiConstructorCall call = (PsiConstructorCall)aClass.getParent();
28 int startOffset = call.getTextRange().getStartOffset();
29 int endOffset = call.getArgumentList().getTextRange().getEndOffset();
30 return new TextRange(startOffset, endOffset);
32 else{
33 final PsiModifierList modifierList = aClass.getModifierList();
34 int startOffset = modifierList == null ? aClass.getTextRange().getStartOffset() : modifierList.getTextRange().getStartOffset();
35 final PsiReferenceList implementsList = aClass.getImplementsList();
36 int endOffset = implementsList == null ? aClass.getTextRange().getEndOffset() : implementsList.getTextRange().getEndOffset();
37 return new TextRange(startOffset, endOffset);