private static List<? extends TypeMirror> computeArrayAccess( Set<ElementKind> types, CompilationInfo info, TreePath parent, Tree error, int offset) { ArrayAccessTree aat = (ArrayAccessTree) parent.getLeaf(); if (aat.getExpression() == error) { TreePath parentParent = parent.getParentPath(); List<? extends TypeMirror> upperTypes = resolveType(types, info, parentParent, aat, offset, null, null); if (upperTypes == null) { return null; } List<TypeMirror> arrayTypes = new ArrayList<TypeMirror>(); for (TypeMirror tm : upperTypes) { if (tm == null) continue; switch (tm.getKind()) { case VOID: case EXECUTABLE: case WILDCARD: case PACKAGE: continue; } arrayTypes.add(info.getTypes().getArrayType(tm)); } if (arrayTypes.isEmpty()) return null; return arrayTypes; } if (aat.getIndex() == error) { types.add(ElementKind.PARAMETER); types.add(ElementKind.LOCAL_VARIABLE); types.add(ElementKind.FIELD); return Collections.singletonList(info.getTypes().getPrimitiveType(TypeKind.INT)); } return null; }
/** Case 3: Check for array dereferencing */ @Override public Void visitArrayAccess(ArrayAccessTree node, Void p) { checkForNullability(node.getExpression(), ACCESSING_NULLABLE); return super.visitArrayAccess(node, p); }
@Override public Choice<Unifier> visitArrayAccess(ArrayAccessTree arrayAccess, Unifier unifier) { return getExpression() .unify(arrayAccess.getExpression(), unifier) .thenChoose(unifications(getIndex(), arrayAccess.getIndex())); }