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.
18 * Created by IntelliJ IDEA.
23 package com
.intellij
.codeInsight
.intention
.impl
;
25 import com
.intellij
.codeInsight
.AnnotationUtil
;
26 import com
.intellij
.codeInsight
.intention
.AddAnnotationFix
;
27 import com
.intellij
.openapi
.editor
.Editor
;
28 import com
.intellij
.openapi
.project
.Project
;
29 import com
.intellij
.psi
.*;
30 import org
.jetbrains
.annotations
.NotNull
;
31 import org
.jetbrains
.annotations
.Nullable
;
33 public class AddNullableNotNullAnnotationFix
extends AddAnnotationFix
{
34 public AddNullableNotNullAnnotationFix(final String annotation
, final String annotationToRemove
) {
35 super(annotation
, annotationToRemove
);
38 public AddNullableNotNullAnnotationFix(final String fqn
, final PsiModifierListOwner owner
, final String annotationToRemove
) {
39 super(fqn
, owner
, annotationToRemove
);
43 public boolean isAvailable(@NotNull final Project project
, final Editor editor
, @Nullable final PsiElement element
) {
44 if (!super.isAvailable(project
, editor
, element
)) {
47 PsiModifierListOwner owner
= getContainer(element
);
48 if (owner
== null || AnnotationUtil
.isAnnotated(owner
, getAnnotationsToRemove()[0], false)) {
51 if (owner
instanceof PsiMethod
) {
52 PsiType returnType
= ((PsiMethod
)owner
).getReturnType();
54 return returnType
!= null && !(returnType
instanceof PsiPrimitiveType
);