IDEA-57432 report 'create new instance of built-in types'

This commit is contained in:
Maxim Medvedev
2010-08-11 13:30:16 +04:00
parent 8eae113fb8
commit 5f1314dc30
6 changed files with 23 additions and 0 deletions
@@ -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
@@ -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();
@@ -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
@@ -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);
}
}
@@ -281,4 +281,6 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
public void testNumberDuplicatesInMaps() throws Exception {doTest();}
public void testMapNotAcceptedAsStringParameter() {doTest();}
public void testBuiltInTypeInstantiation() {doTest();}
}
@@ -0,0 +1 @@
def x = new <error descr="Instantiation of built-in type">int</error>()