mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 05:21:29 +07:00
[java] ExternalAnnotationsManager.findExternalAnnotations: NotNull
GitOrigin-RevId: cbd3821a7d6d43d7a0c77039312b612ee0137b73
This commit is contained in:
committed by
intellij-monorepo-bot
parent
04b872d204
commit
1d83886b74
@@ -1084,12 +1084,10 @@ public class JavaSafeDeleteProcessor extends SafeDeleteProcessorDelegateBase {
|
||||
if (!referencedElement.isValid()) return;
|
||||
ExternalAnnotationsManager annotationsManager = ExternalAnnotationsManager.getInstance(referencedElement.getProject());
|
||||
PsiAnnotation[] externalAnnotations = annotationsManager.findExternalAnnotations((PsiModifierListOwner)referencedElement);
|
||||
if (externalAnnotations != null) {
|
||||
for (PsiAnnotation annotation : externalAnnotations) {
|
||||
String qualifiedName = annotation.getQualifiedName();
|
||||
if (qualifiedName == null) continue;
|
||||
annotationsManager.deannotate((PsiModifierListOwner)referencedElement, qualifiedName);
|
||||
}
|
||||
for (PsiAnnotation annotation : externalAnnotations) {
|
||||
String qualifiedName = annotation.getQualifiedName();
|
||||
if (qualifiedName == null) continue;
|
||||
annotationsManager.deannotate((PsiModifierListOwner)referencedElement, qualifiedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ public final class ExternalAnnotationsRefactoringListenerProvider implements Ref
|
||||
Project project = element.getProject();
|
||||
ExternalAnnotationsManager externalAnnotationsManager = ExternalAnnotationsManager.getInstance(project);
|
||||
PsiAnnotation[] annotations = externalAnnotationsManager.findExternalAnnotations(modifierListOwner);
|
||||
if (annotations != null) {
|
||||
if (annotations.length > 0) {
|
||||
String oldExternalName = PsiFormatUtil.getExternalName(modifierListOwner, false, Integer.MAX_VALUE);
|
||||
if (oldExternalName == null) {
|
||||
return null;
|
||||
|
||||
@@ -21,11 +21,11 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public final class MakeExternalAnnotationExplicit implements ModCommandAction {
|
||||
@@ -84,17 +84,17 @@ public final class MakeExternalAnnotationExplicit implements ModCommandAction {
|
||||
|
||||
private static PsiAnnotation @NotNull [] getAnnotations(@NotNull Project project, PsiModifierListOwner owner) {
|
||||
PsiAnnotation[] annotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(owner);
|
||||
if (annotations == null) {
|
||||
if (annotations.length == 0) {
|
||||
return PsiAnnotation.EMPTY_ARRAY;
|
||||
}
|
||||
else {
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
return Arrays.stream(annotations).filter(anno -> {
|
||||
return StreamEx.of(annotations).filter(anno -> {
|
||||
String qualifiedName = anno.getQualifiedName();
|
||||
return qualifiedName != null &&
|
||||
facade.findClass(qualifiedName, owner.getResolveScope()) != null &&
|
||||
!owner.hasAnnotation(qualifiedName);
|
||||
}).toArray(PsiAnnotation[]::new);
|
||||
}).toArray(PsiAnnotation.EMPTY_ARRAY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ class AnnotationInlayProvider : InlayHintsProvider<AnnotationInlayProvider.Setti
|
||||
if (element is PsiModifierListOwner) {
|
||||
var annotations = emptySequence<PsiAnnotation>()
|
||||
if (settings.showExternal) {
|
||||
annotations += ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element).orEmpty()
|
||||
annotations += ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(element)
|
||||
}
|
||||
if (settings.showInferred) {
|
||||
annotations += InferredAnnotationsManager.getInstance(project).findInferredAnnotations(element)
|
||||
|
||||
@@ -49,7 +49,7 @@ public class DeannotateIntentionAction implements ModCommandAction {
|
||||
if (listOwner != null) {
|
||||
final ExternalAnnotationsManager externalAnnotationsManager = ExternalAnnotationsManager.getInstance(context.project());
|
||||
final PsiAnnotation[] annotations = externalAnnotationsManager.findExternalAnnotations(listOwner);
|
||||
if (annotations != null && annotations.length > 0) {
|
||||
if (annotations.length > 0) {
|
||||
String message;
|
||||
if (annotations.length == 1) {
|
||||
message = JavaBundle.message("deannotate.intention.action.text", "@" + annotations[0].getQualifiedName());
|
||||
@@ -78,7 +78,7 @@ public class DeannotateIntentionAction implements ModCommandAction {
|
||||
return annotationsManager.deannotateModCommand(List.of(listOwner), List.of(myAnnotationName));
|
||||
}
|
||||
final PsiAnnotation[] externalAnnotations = annotationsManager.findExternalAnnotations(listOwner);
|
||||
if (externalAnnotations == null) return ModCommand.nop();
|
||||
if (externalAnnotations.length == 0) return ModCommand.nop();
|
||||
return ModCommand.chooseAction(JavaBundle.message("deannotate.intention.chooser.title"),
|
||||
ContainerUtil.map(externalAnnotations, anno -> new DeannotateIntentionAction(
|
||||
Objects.requireNonNull(anno.getQualifiedName()))));
|
||||
|
||||
@@ -478,9 +478,7 @@ public class AnnotationUtil {
|
||||
|
||||
final Project project = owner.getProject();
|
||||
final PsiAnnotation[] externalAnnotations = ExternalAnnotationsManager.getInstance(project).findExternalAnnotations(owner);
|
||||
if (externalAnnotations != null) {
|
||||
annotations = ArrayUtil.mergeArrays(annotations, externalAnnotations, PsiAnnotation.ARRAY_FACTORY);
|
||||
}
|
||||
annotations = ArrayUtil.mergeArrays(annotations, externalAnnotations, PsiAnnotation.ARRAY_FACTORY);
|
||||
if (withInferred) {
|
||||
final PsiAnnotation[] inferredAnnotations = InferredAnnotationsManager.getInstance(project).findInferredAnnotations(owner);
|
||||
annotations = ArrayUtil.mergeArrays(annotations, inferredAnnotations, PsiAnnotation.ARRAY_FACTORY);
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class ExternalAnnotationsManager {
|
||||
// Method used in Kotlin plugin
|
||||
public abstract boolean isExternalAnnotationWritable(@NotNull PsiModifierListOwner listOwner, @NotNull String annotationFQN);
|
||||
|
||||
public abstract PsiAnnotation @Nullable [] findExternalAnnotations(@NotNull PsiModifierListOwner listOwner);
|
||||
public abstract @NotNull PsiAnnotation @NotNull [] findExternalAnnotations(@NotNull PsiModifierListOwner listOwner);
|
||||
|
||||
/**
|
||||
* Returns external annotations associated with default
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.util.containers.ConcurrentMostlySingularMultiMap;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.MostlySingularMultiMap;
|
||||
import com.intellij.util.text.CharSequenceReader;
|
||||
import one.util.streamex.StreamEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.xml.sax.Attributes;
|
||||
@@ -146,10 +147,11 @@ public abstract class BaseExternalAnnotationsManager extends ExternalAnnotations
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiAnnotation @Nullable [] findExternalAnnotations(final @NotNull PsiModifierListOwner listOwner) {
|
||||
public @NotNull PsiAnnotation @NotNull [] findExternalAnnotations(final @NotNull PsiModifierListOwner listOwner) {
|
||||
final List<AnnotationData> result = collectExternalAnnotations(listOwner);
|
||||
return result.isEmpty() ? null : ContainerUtil.map2Array(result, PsiAnnotation.EMPTY_ARRAY,
|
||||
data -> data.getAnnotation(this));
|
||||
return result.isEmpty() ? PsiAnnotation.EMPTY_ARRAY : StreamEx.of(result)
|
||||
.map(data -> data.getAnnotation(this))
|
||||
.toArray(PsiAnnotation.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private static final List<AnnotationData> NO_DATA = new ArrayList<>(1);
|
||||
|
||||
@@ -46,7 +46,7 @@ public class PsiClassReferenceListStubImpl extends StubBase<PsiReferenceList> im
|
||||
private boolean shouldSkipSoleObject() {
|
||||
final boolean compiled = ((JavaClassReferenceListElementType)getStubType()).isCompiled(this);
|
||||
return compiled && myInfos.length == 1 && myInfos[0].getKind() == TypeInfo.TypeKind.JAVA_LANG_OBJECT &&
|
||||
myInfos[0].getTypeAnnotations().isEmpty();
|
||||
myInfos[0].getTypeAnnotations() == TypeAnnotationContainer.EMPTY;
|
||||
}
|
||||
|
||||
private PsiClassType @NotNull [] createTypes() {
|
||||
|
||||
Reference in New Issue
Block a user