Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.intellij.java.language.psi.util.PsiUtil;
import com.siyeh.ig.psiutils.CommentTracker;
import consulo.annotation.access.RequiredReadAction;
import consulo.annotation.access.RequiredWriteAction;
import consulo.java.analysis.localize.JavaAnalysisLocalize;
import consulo.language.editor.WriteCommandAction;
import consulo.language.editor.inspection.LocalQuickFixOnPsiElement;
Expand Down Expand Up @@ -260,6 +261,7 @@ private ExternalAnnotationsManager.AnnotationPlace choosePlace(@Nonnull PsiModif
*/
@Deprecated
//@ApiStatus.ScheduledForRemoval(inVersion = "2020.3")
@RequiredWriteAction
public static PsiAnnotation addPhysicalAnnotation(String fqn, PsiNameValuePair[] pairs, PsiModifierList modifierList) {
return addPhysicalAnnotationTo(fqn, pairs, modifierList);
}
Expand All @@ -278,7 +280,7 @@ public static PsiAnnotation addPhysicalAnnotation(String fqn, PsiNameValuePair[]
* @return added physical annotation; null if annotation already exists (in this case, no changes are performed)
*/
@Nullable
@RequiredReadAction
@RequiredWriteAction
public static PsiAnnotation addPhysicalAnnotationIfAbsent(
@Nonnull String fqn,
@Nonnull PsiNameValuePair[] pairs,
Expand Down Expand Up @@ -306,7 +308,7 @@ public static PsiAnnotation addPhysicalAnnotationIfAbsent(
return addPhysicalAnnotationTo(fqn, pairs, owner);
}

@RequiredReadAction
@RequiredWriteAction
public static PsiAnnotation addPhysicalAnnotationTo(String fqn, PsiNameValuePair[] pairs, PsiAnnotationOwner owner) {
owner = expandParameterIfNecessary(owner);
PsiAnnotation inserted;
Expand All @@ -332,7 +334,7 @@ public static PsiAnnotation addPhysicalAnnotationTo(String fqn, PsiNameValuePair
return inserted;
}

@RequiredReadAction
@RequiredWriteAction
private static PsiAnnotationOwner expandParameterIfNecessary(PsiAnnotationOwner owner) {
if (owner instanceof PsiModifierList modifierList) {
PsiParameter parameter = ObjectUtil.tryCast(modifierList.getParent(), PsiParameter.class);
Expand Down Expand Up @@ -366,6 +368,7 @@ private static PsiAnnotationOwner expandParameterIfNecessary(PsiAnnotationOwner
return owner;
}

@RequiredWriteAction
public static void removePhysicalAnnotations(@Nonnull PsiModifierListOwner owner, @Nonnull String... fqns) {
for (String fqn : fqns) {
PsiAnnotation annotation = AnnotationUtil.findAnnotation(owner, true, fqn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/*
* Created by IntelliJ IDEA.
* User: cdr
* Date: Jul 20, 2007
* Time: 2:57:59 PM
*/
package com.intellij.java.analysis.impl.codeInsight.intention.impl;

import consulo.annotation.access.RequiredReadAction;
import jakarta.annotation.Nonnull;

import com.intellij.java.language.codeInsight.AnnotationUtil;
Expand All @@ -35,31 +29,40 @@
import com.intellij.java.language.psi.PsiPrimitiveType;
import com.intellij.java.language.psi.PsiType;

public class AddNullableNotNullAnnotationFix extends AddAnnotationPsiFix
{
public AddNullableNotNullAnnotationFix(@Nonnull String fqn, @Nonnull PsiModifierListOwner owner, @Nonnull String... annotationToRemove)
{
super(fqn, owner, PsiNameValuePair.EMPTY_ARRAY, annotationToRemove);
}
/**
* @author cdr
* @since 2007-07-20
*/
public class AddNullableNotNullAnnotationFix extends AddAnnotationPsiFix {
@RequiredReadAction
public AddNullableNotNullAnnotationFix(
@Nonnull String fqn,
@Nonnull PsiModifierListOwner owner,
@Nonnull String... annotationToRemove
) {
super(fqn, owner, PsiNameValuePair.EMPTY_ARRAY, annotationToRemove);
}

@Override
public boolean isAvailable(@Nonnull Project project, @Nonnull PsiFile file, @Nonnull PsiElement startElement, @Nonnull PsiElement endElement)
{
if(!super.isAvailable(project, file, startElement, endElement))
{
return false;
}
PsiModifierListOwner owner = getContainer(file, startElement.getTextRange().getStartOffset());
if(owner == null || AnnotationUtil.isAnnotated(owner, getAnnotationsToRemove()[0], false, false))
{
return false;
}
if(owner instanceof PsiMethod)
{
PsiType returnType = ((PsiMethod) owner).getReturnType();
@Override
@RequiredReadAction
public boolean isAvailable(
@Nonnull Project project,
@Nonnull PsiFile file,
@Nonnull PsiElement startElement,
@Nonnull PsiElement endElement
) {
if (!super.isAvailable(project, file, startElement, endElement)) {
return false;
}
PsiModifierListOwner owner = getContainer(file, startElement.getTextRange().getStartOffset());
if (owner == null || AnnotationUtil.isAnnotated(owner, getAnnotationsToRemove()[0], false, false)) {
return false;
}
if (owner instanceof PsiMethod method) {
PsiType returnType = method.getReturnType();

return returnType != null && !(returnType instanceof PsiPrimitiveType);
}
return true;
}
return returnType != null && !(returnType instanceof PsiPrimitiveType);
}
return true;
}
}
Loading
Loading