[java-highlighting] IDEA-246970 Local annotations should not be allowed in Java15-preview

GitOrigin-RevId: 1a1de1372304095197fdecf0c7b10bd8e9780442
This commit is contained in:
Tagir Valeev
2020-07-30 17:54:45 +07:00
committed by intellij-monorepo-bot
parent 5aeac35507
commit 4242b62d14
3 changed files with 12 additions and 1 deletions

View File

@@ -618,7 +618,7 @@ public final class HighlightClassUtil {
}
else if (aClass.isInterface()) {
token = JavaTokenType.INTERFACE_KEYWORD;
feature = HighlightingFeature.LOCAL_INTERFACES;
feature = aClass.isAnnotationType() ? null : HighlightingFeature.LOCAL_INTERFACES;
}
else {
return null;
@@ -628,6 +628,12 @@ public final class HighlightClassUtil {
.findFirst(e -> e instanceof PsiKeyword && ((PsiKeyword)e).getTokenType().equals(token))
.orElseThrow(NoSuchElementException::new);
PsiFile file = aClass.getContainingFile();
if (feature == null) {
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR)
.range(anchor)
.descriptionAndTooltip(JavaErrorBundle.message("annotation.cannot.be.local"))
.create();
}
return HighlightUtil.checkFeature(anchor, feature, PsiUtil.getLanguageLevel(file), file);
}

View File

@@ -494,3 +494,4 @@ local.classes.must.not.extend.sealed.classes=Local classes must not extend seale
anonymous.classes.must.not.extend.sealed.classes=Anonymous classes must not extend sealed classes
class.not.allowed.to.extend.sealed.class.from.another.package=Class is not allowed to extend sealed class from another package
class.not.allowed.to.extend.sealed.class.from.another.module=Class is not allowed to extend sealed class from another module
annotation.cannot.be.local=Local annotations are not allowed

View File

@@ -8,6 +8,10 @@ class X {
Foo foo = () -> {};
}
void annotation() {
@<error descr="Local annotations are not allowed">interface</error> Anno {}
}
void modifiers() {
<error descr="Modifier 'static' not allowed here">static</error> interface Intf1 {}
<error descr="Modifier 'private' not allowed here">private</error> interface Intf2 {}