[java-highlighting] IDEA-160446 Java. "Array type has too many dimensions" error is not highlighted

GitOrigin-RevId: 40ae7025e52f6be0486ad2e1cf3bf4a85e9904ea
This commit is contained in:
Tagir Valeev
2022-07-11 15:56:33 +00:00
committed by intellij-monorepo-bot
parent 56d1fb8fb1
commit 0e66f0b536
5 changed files with 26 additions and 1 deletions
@@ -2873,6 +2873,21 @@ public final class HighlightUtil {
.navigationShift(navigationShift).create();
}
public static HighlightInfo checkArrayType(PsiTypeElement type) {
int dimensions = 0;
for (PsiElement child = type.getFirstChild(); child != null; child = child.getNextSibling()) {
if (PsiUtil.isJavaToken(child, JavaTokenType.LBRACKET)) {
dimensions++;
}
}
if (dimensions > 255) {
// JVM Specification, 4.3.2: no more than 255 dimensions allowed
return HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(type.getTextRange())
.description(JavaErrorBundle.message("too.many.array.dimensions")).create();
}
return null;
}
@FunctionalInterface
interface IncompatibleTypesTooltipComposer {
@NotNull @NlsContexts.Tooltip
@@ -1751,6 +1751,7 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkVarTypeApplicability(type));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkReferenceTypeUsedAsTypeArgument(type, myLanguageLevel));
if (!myHolder.hasErrorResults()) myHolder.add(GenericsHighlightUtil.checkWildcardUsage(type));
if (!myHolder.hasErrorResults()) myHolder.add(HighlightUtil.checkArrayType(type));
if (!myHolder.hasErrorResults()) type.accept(myPreviewFeatureVisitor);
}
@@ -541,4 +541,5 @@ text.class.is.not.accessible={0} is not accessible in current context
text.class.cannot.access=Cannot access {0}
auto.closeable.resource=auto-closeable resource
annotation.type.permits=No permits clause allowed for annotation type
safevararg.annotation.cannot.be.applied.for.record.component=@SafeVarargs annotation cannot be applied for a record component
safevararg.annotation.cannot.be.applied.for.record.component=@SafeVarargs annotation cannot be applied for a record component
too.many.array.dimensions=Too many array dimensions
@@ -0,0 +1,6 @@
class C {
void t() {
byte[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][] b1;
<error descr="Too many array dimensions">byte[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][]</error> b2;
}
}
@@ -409,6 +409,8 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
doTest(false);
}
public void testTooManyArrayDimensions() { doTest(false);}
public void testInsane() {
configureFromFileText("x.java", "class X { \nx_x_x_x\n }");
List<HighlightInfo> infos = highlightErrors();