diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties index e676d65bcdec..353d85422bf0 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/GroovyBundle.properties @@ -341,3 +341,4 @@ cyclic.inheritance.involving.0=Cyclic inheritance involving ''{0}'' there.is.no.default.constructor.available.in.class.0=There is no default constructor available in class ''{0}'' groovy.library.is.not.configured.for.module=Groovy SDK is not configured for module ''{0}'' configure.groovy.library=Configure Groovy SDK... +create.instance.of.built-in.type=Instantiation of built-in type 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 6f701de2dbd7..39ecd932cd86 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/annotator/GroovyAnnotator.java @@ -490,7 +490,16 @@ public class GroovyAnnotator extends GroovyElementVisitor implements Annotator { @Override public void visitNewExpression(GrNewExpression newExpression) { + final GrTypeElement typeElement = newExpression.getTypeElement(); + + if (typeElement instanceof GrBuiltInTypeElement) { + if (newExpression.getArrayCount() == 0) { + myHolder.createErrorAnnotation(typeElement, GroovyBundle.message("create.instance.of.built-in.type")); + } + } + if (newExpression.getArrayCount() > 0) return; + GrCodeReferenceElement refElement = newExpression.getReferenceElement(); if (refElement == null) return; final PsiElement element = refElement.resolve(); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java index 648a2e418b26..8db00b5e3856 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/api/statements/expressions/GrNewExpression.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.Nullable; import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrCallExpression; import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; /** * @author ilyas @@ -31,6 +32,9 @@ public interface GrNewExpression extends GrCallExpression, GrConstructorCall { @Nullable GrCodeReferenceElement getReferenceElement(); + @Nullable + GrTypeElement getTypeElement(); + int getArrayCount(); @Nullable diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java index 22ff2fab9fc6..5d0cdf023224 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/lang/psi/impl/statements/expressions/GrNewExpressionImpl.java @@ -34,6 +34,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrNewExp import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrAnonymousClassDefinition; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrBuiltInTypeElement; import org.jetbrains.plugins.groovy.lang.psi.api.types.GrCodeReferenceElement; +import org.jetbrains.plugins.groovy.lang.psi.api.types.GrTypeElement; import org.jetbrains.plugins.groovy.lang.psi.impl.GrClassReferenceType; import org.jetbrains.plugins.groovy.lang.psi.impl.GroovyResolveResultImpl; import org.jetbrains.plugins.groovy.lang.psi.impl.PsiImplUtil; @@ -203,4 +204,9 @@ public class GrNewExpressionImpl extends GrCallExpressionImpl implements GrNewEx return result.toArray(new GroovyResolveResult[result.size()]); } + + @Override + public GrTypeElement getTypeElement() { + return findChildByClass(GrTypeElement.class); + } } diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java index 384e207e25c1..4a32219b6727 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/lang/GroovyHighlightingTest.java @@ -281,4 +281,6 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase { public void testNumberDuplicatesInMaps() throws Exception {doTest();} public void testMapNotAcceptedAsStringParameter() {doTest();} + + public void testBuiltInTypeInstantiation() {doTest();} } \ No newline at end of file diff --git a/plugins/groovy/testdata/highlighting/BuiltInTypeInstantiation.groovy b/plugins/groovy/testdata/highlighting/BuiltInTypeInstantiation.groovy new file mode 100644 index 000000000000..10566a8ba4ec --- /dev/null +++ b/plugins/groovy/testdata/highlighting/BuiltInTypeInstantiation.groovy @@ -0,0 +1 @@ +def x = new int() \ No newline at end of file