[groovy] highlight void array types with error (IDEA-184355)

This commit is contained in:
Daniil Ovchinnikov
2018-01-12 21:25:40 +03:00
parent 835ad7e380
commit cebbe3a311
3 changed files with 22 additions and 26 deletions
@@ -389,6 +389,7 @@ trait.method.cannot.be.protected=Trait methods are not allowed to be protected
traits.are.not.supported.in.groovy.0=Traits are not supported in Groovy {0}
non.static.classes.not.allowed=Non-static inner classes are not allowed in traits
selfType.class.does.not.inherit=@SelfType: Class ''{0}'' does not inherit ''{1}''
illegal.type.void=Illegal type: 'void'
select.module.description=Which module to use classpath of?
select.module.title=Select module...
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package org.jetbrains.plugins.groovy.annotator;
@@ -955,6 +943,18 @@ public class GroovyAnnotator extends GroovyElementVisitor {
}
}
@Override
public void visitArrayTypeElement(@NotNull GrArrayTypeElement typeElement) {
GrTypeElement componentTypeElement = typeElement.getComponentTypeElement();
PsiType componentType = componentTypeElement.getType();
if (PsiType.VOID.equals(componentType)) {
myHolder.createErrorAnnotation(componentTypeElement, GroovyBundle.message("illegal.type.void"));
}
else {
super.visitArrayTypeElement(typeElement);
}
}
@Override
public void visitModifierList(@NotNull GrModifierList modifierList) {
final PsiElement parent = modifierList.getParent();
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2017 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package org.jetbrains.plugins.groovy.lang.highlighting
@@ -181,6 +169,13 @@ class A {
void testBuiltInTypeInstantiation() { doTest() }
void 'test void array type'() {
testHighlighting '''\
<error descr="Illegal type: 'void'">void</error>[] foo() {}
<error descr="Illegal type: 'void'">void</error>[] bar = foo()
'''
}
void testSOEInFieldDeclarations() { doTest() }
void testWrongAnnotation() { doTest() }