update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / codeInsight / intention / impl / AddNullableNotNullAnnotationFix.java
blob0e0c056a31ca19f6b4dbcd08a0fdf8efeac894c5
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.
18 * Created by IntelliJ IDEA.
19 * User: cdr
20 * Date: Jul 20, 2007
21 * Time: 2:57:59 PM
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);
42 @Override
43 public boolean isAvailable(@NotNull final Project project, final Editor editor, @Nullable final PsiElement element) {
44 if (!super.isAvailable(project, editor, element)) {
45 return false;
47 PsiModifierListOwner owner = getContainer(element);
48 if (owner == null || AnnotationUtil.isAnnotated(owner, getAnnotationsToRemove()[0], false)) {
49 return false;
51 if (owner instanceof PsiMethod) {
52 PsiType returnType = ((PsiMethod)owner).getReturnType();
54 return returnType != null && !(returnType instanceof PsiPrimitiveType);
56 return true;