From 91085d8fe3a91e12dd1dd1b7043959b6bbc2f40d Mon Sep 17 00:00:00 2001 From: Max Medvedev Date: Mon, 14 Apr 2014 17:59:02 +0400 Subject: [PATCH] IDEA-123484 anonymous from traits are not allowed --- .../jetbrains/plugins/groovy/GroovyBundle.properties | 1 + .../plugins/groovy/annotator/GroovyAnnotator.java | 10 +++++++--- .../lang/highlighting/GroovyHighlightingTest.groovy | 8 ++++++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties index b7ba437d00f4..e6769e78a436 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties @@ -376,3 +376,4 @@ declared.type.0.have.to.extend.script=Declared type ''{0}'' does not extend 'gro base.script.annotation.is.allowed.only.inside.scripts=Annotation @BaseScript can only be used within a script 0.expressions.on.trait.fields.properties.are.not.supported.in.traits={0} expressions on trait fields/properties are not supported in traits only.traits.expected.here=Only traits are expected here +anonymous.classes.cannot.be.created.from.traits=Anonymous classes cannot be created from traits diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java index 1c0b4c3a7771..b6c50c7cbeed 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -2001,9 +2001,13 @@ public class GroovyAnnotator extends GroovyElementVisitor { final GroovyConfigUtils configUtils = GroovyConfigUtils.getInstance(); if (typeDefinition.isAnonymous()) { if (!configUtils.isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_7)) { - holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.are.not.supported", - configUtils - .getSDKVersion(typeDefinition))); + holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), + GroovyBundle.message("anonymous.classes.are.not.supported", configUtils.getSDKVersion(typeDefinition))); + } + + PsiElement superClass = ((PsiAnonymousClass)typeDefinition).getBaseClassReference().resolve(); + if (superClass instanceof GrTypeDefinition && ((GrTypeDefinition)superClass).isTrait()) { + holder.createErrorAnnotation(typeDefinition.getNameIdentifierGroovy(), GroovyBundle.message("anonymous.classes.cannot.be.created.from.traits")); } } else if (typeDefinition.getContainingClass() != null && !(typeDefinition instanceof GrEnumTypeDefinition)) { diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy index e884bf3367ae..6e4a00604bd7 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/highlighting/GroovyHighlightingTest.groovy @@ -1868,6 +1868,14 @@ trait C { x++ } } +''') + } + + void testTraitAsAnonymous() { + testHighlighting(''' +trait T {} + +new T(){} ''') } }