mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java] missing annotations on method return types
This commit is contained in:
@@ -28,6 +28,7 @@ import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.CharTable;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import com.intellij.util.containers.Stack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -92,7 +93,9 @@ public class JavaSharedImplUtil {
|
||||
if (modifierList != null) {
|
||||
PsiAnnotation[] annotations = modifierList.getAnnotations();
|
||||
if (annotations.length > 0) {
|
||||
TypeAnnotationProvider provider = new FilteringTypeAnnotationProvider(annotations);
|
||||
TypeAnnotationProvider original =
|
||||
modifierList.getParent() instanceof PsiMethod ? type.getAnnotationProvider() : TypeAnnotationProvider.EMPTY;
|
||||
TypeAnnotationProvider provider = new FilteringTypeAnnotationProvider(annotations, original);
|
||||
if (type instanceof PsiArrayType) {
|
||||
Stack<PsiArrayType> types = new Stack<PsiArrayType>();
|
||||
do {
|
||||
@@ -196,10 +199,12 @@ public class JavaSharedImplUtil {
|
||||
|
||||
private static class FilteringTypeAnnotationProvider implements TypeAnnotationProvider {
|
||||
private final PsiAnnotation[] myCandidates;
|
||||
private final TypeAnnotationProvider myOriginalProvider;
|
||||
private volatile PsiAnnotation[] myCache;
|
||||
|
||||
private FilteringTypeAnnotationProvider(PsiAnnotation[] candidates) {
|
||||
private FilteringTypeAnnotationProvider(PsiAnnotation[] candidates, TypeAnnotationProvider originalProvider) {
|
||||
myCandidates = candidates;
|
||||
myOriginalProvider = originalProvider;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -207,12 +212,15 @@ public class JavaSharedImplUtil {
|
||||
public PsiAnnotation[] getAnnotations() {
|
||||
PsiAnnotation[] result = myCache;
|
||||
if (result == null) {
|
||||
List<PsiAnnotation> filtered = ContainerUtil.filter(myCandidates, new Condition<PsiAnnotation>() {
|
||||
@Override
|
||||
public boolean value(PsiAnnotation annotation) {
|
||||
return AnnotationTargetUtil.isTypeAnnotation(annotation);
|
||||
}
|
||||
});
|
||||
List<PsiAnnotation> filtered = JBIterable.of(myCandidates)
|
||||
.filter(new Condition<PsiAnnotation>() {
|
||||
@Override
|
||||
public boolean value(PsiAnnotation annotation) {
|
||||
return AnnotationTargetUtil.isTypeAnnotation(annotation);
|
||||
}
|
||||
})
|
||||
.append(myOriginalProvider.getAnnotations())
|
||||
.toList();
|
||||
myCache = result = filtered.isEmpty() ? PsiAnnotation.EMPTY_ARRAY : filtered.toArray(new PsiAnnotation[filtered.size()]);
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,9 +36,7 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
@interface A { }
|
||||
@Target(ElementType.TYPE_USE) @interface TA { int value() default 42; }
|
||||
|
||||
class O {
|
||||
class I { }
|
||||
}
|
||||
class O { class I { } }
|
||||
|
||||
@SuppressWarnings("ExceptionClassNameDoesntEndWithException") class E1 extends Exception { }
|
||||
@SuppressWarnings("ExceptionClassNameDoesntEndWithException") class E2 extends Exception { }""".stripIndent())
|
||||
@@ -101,9 +99,9 @@ class AnnotatedTypeTest extends LightCodeInsightFixtureTestCase {
|
||||
}
|
||||
|
||||
public void testMethodReturnType() {
|
||||
def psi = factory.createMethodFromText("@A @TA(1) String m() { return null; }", context)
|
||||
assertTypeText psi.returnType, "java.lang.@pkg.TA(1) String", "java.lang.String"
|
||||
assertAnnotations psi.returnType, "@TA(1)"
|
||||
def psi = factory.createMethodFromText("@A @TA(1) <T> @TA(2) String m() { return null; }", context)
|
||||
assertTypeText psi.returnType, "java.lang.@pkg.TA(1) @pkg.TA(2) String", "java.lang.String"
|
||||
assertAnnotations psi.returnType, "@TA(1)", "@TA(2)"
|
||||
}
|
||||
|
||||
private void doTest(String text, String annotated, String canonical) {
|
||||
|
||||
Reference in New Issue
Block a user