mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 21:11:28 +07:00
IDEA-96228 (restrict annotation owner at lower language levels)
This commit is contained in:
@@ -27,6 +27,7 @@ import com.intellij.psi.impl.source.JavaStubPsiElement;
|
||||
import com.intellij.psi.meta.PsiMetaData;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.PairFunction;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -80,7 +81,8 @@ public class PsiAnnotationImpl extends JavaStubPsiElement<PsiAnnotationStub> imp
|
||||
|
||||
@Override
|
||||
public <T extends PsiAnnotationMemberValue> T setDeclaredAttributeValue(@NonNls String attributeName, @Nullable T value) {
|
||||
return (T)PsiImplUtil.setDeclaredAttributeValue(this, attributeName, value, ANNOTATION_CREATOR);
|
||||
@SuppressWarnings("unchecked") T t = (T)PsiImplUtil.setDeclaredAttributeValue(this, attributeName, value, ANNOTATION_CREATOR);
|
||||
return t;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
@@ -94,7 +96,8 @@ public class PsiAnnotationImpl extends JavaStubPsiElement<PsiAnnotationStub> imp
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable public String getQualifiedName() {
|
||||
@Nullable
|
||||
public String getQualifiedName() {
|
||||
final PsiJavaCodeReferenceElement nameRef = getNameReferenceElement();
|
||||
if (nameRef == null) return null;
|
||||
return nameRef.getCanonicalText();
|
||||
@@ -119,6 +122,10 @@ public class PsiAnnotationImpl extends JavaStubPsiElement<PsiAnnotationStub> imp
|
||||
@Override
|
||||
public PsiAnnotationOwner getOwner() {
|
||||
PsiElement parent = getParent();
|
||||
if (!PsiUtil.isLanguageLevel8OrHigher(this)) {
|
||||
return parent instanceof PsiModifierList ? (PsiAnnotationOwner)parent : null;
|
||||
}
|
||||
|
||||
if (parent instanceof PsiTypeElement) {
|
||||
return ((PsiTypeElement)parent).getOwner(this);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import java.util.Collection;
|
||||
|
||||
@interface Anno {
|
||||
Anno[] nested() default {};
|
||||
}
|
||||
@@ -13,4 +15,12 @@ abstract class C {
|
||||
void notWrong() { }
|
||||
}
|
||||
|
||||
class B extends <error descr="Annotations are not allowed here">@Deprecated</error> Object{}
|
||||
class B extends <error descr="Annotations are not allowed here">@Deprecated</error> Object { }
|
||||
|
||||
enum E {
|
||||
@Anno E1
|
||||
}
|
||||
|
||||
interface I {
|
||||
@<error descr="Duplicate annotation">Anno</error> public @<error descr="Duplicate annotation">Anno</error> Collection<<error descr="Annotations are not allowed here">@Anno</error> String> method(@<error descr="Duplicate annotation">Anno</error> @<error descr="Duplicate annotation">Anno</error> Object o);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight.daemon;
|
||||
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,7 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/daemonCodeAnalyzer/annotations";
|
||||
|
||||
private void doTest(boolean checkWarnings) {
|
||||
setLanguageLevel(LanguageLevel.JDK_1_7);
|
||||
doTest(BASE_PATH + "/" + getTestName(true) + ".java", checkWarnings, false);
|
||||
}
|
||||
|
||||
@@ -43,7 +45,9 @@ public class AnnotationsHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testInapplicable() { doTest(false); }
|
||||
public void testDuplicateAttribute() { doTest(false); }
|
||||
public void testDuplicateTarget() { doTest(false); }
|
||||
//public void testTypeAnnotations() { doTest(false); }
|
||||
|
||||
public void testInvalidPackageAnnotationTarget() { doTest(BASE_PATH + "/" + getTestName(true) + "/package-info.java", false, false); }
|
||||
public void testPackageAnnotationNotInPackageInfo() { doTest(BASE_PATH + "/" + getTestName(true) + "/notPackageInfo.java", false, false); }
|
||||
|
||||
//public void testTypeAnnotations() { doTest(false); } // todo[r.sh] make separate test with correct language level
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user