NPE & SOE on array access converting

This commit is contained in:
Maxim Medvedev
2011-05-03 15:45:52 +04:00
parent 70887bec0b
commit 345771a1d2
7 changed files with 14 additions and 2 deletions
@@ -448,9 +448,10 @@ public class PsiImplUtil {
TypesUtil.isAssignable(PsiType.INT, argTypes[0], manager, resolveScope);
}
public static GroovyResolveResult getIndexPropertyMethodCandidate(PsiType thisType,
public static GroovyResolveResult getIndexPropertyMethodCandidate(@Nullable PsiType thisType,
PsiType[] argTypes,
GroovyPsiElement place) {
if (thisType == null) return GroovyResolveResult.EMPTY_RESULT;
GroovyResolveResult[] candidates = ResolveUtil.getMethodCandidates(thisType, "getAt", place, argTypes);
if (candidates.length != 1) {
final GrTupleType tupleType = new GrTupleType(argTypes, JavaPsiFacade.getInstance(place.getProject()), place.getResolveScope());
@@ -758,7 +758,7 @@ public class ExpressionGenerator extends Generator {
final GrNamedArgument[] namedArgs = argList.getNamedArguments();
if (PsiImplUtil.isSimpleArrayAccess(thisType, argTypes, manager, resolveScope)) {
expression.accept(this);
selectedExpression.accept(this);
builder.append("[");
final GrExpression arg = exprArgs[0];
arg.accept(this);
@@ -150,4 +150,7 @@ public final class Matcher {
void testAnonymousFromMap() {doTest()}
void testClosure() {doTest()}
void _testListAsArray() {doTest()}
void testUnresolvedArrayAccess() {doTest()}
void testArrayAccess() {doTest()}
}
@@ -0,0 +1,2 @@
int[] foo = [1, 2, 3]
print foo[2]
@@ -0,0 +1,2 @@
java.lang.Integer[] foo = new java.lang.Integer[]{1, 2, 3};
print(foo[2]);
@@ -0,0 +1,2 @@
def foo
print(foo[1])
@@ -0,0 +1,2 @@
java.lang.Object foo;
print(foo.getAt(1));