ArrayTypeUsage implements TypeUsage { @Override public Symbol getInstanceField(String fieldName, Symbol instance) { if (fieldName.equals(LENGTH_FIELD_NAME)) { return new ArrayLength(instance); } else { throw new IllegalArgumentException("An array has no field named " + fieldName); } } ArrayTypeUsage(TypeUsage componentType); TypeUsage getComponentType(); @Override boolean equals(Object o); @Override int hashCode(); @Override boolean isArray(); @Override boolean isReference(); @Override ArrayTypeUsage asArrayTypeUsage(); @Override JvmType jvmType(); @Override boolean hasInstanceField(String fieldName, Symbol instance); @Override Symbol getInstanceField(String fieldName, Symbol instance); @Override Optional<Invokable> getMethod(String method, boolean staticContext); @Override boolean canBeAssignedTo(TypeUsage type); @Override String toString(); @Override TypeUsage replaceTypeVariables(Map<String, T> typeParams); @Override boolean sameType(TypeUsage other); @Override String describe();  }
@Test public void testGetInstanceFieldUnexisting() { Symbol instance = EasyMock.createMock(Symbol.class); EasyMock.replay(instance); int exceptions = 0; try { arrayOfBoolean.getInstanceField("foo", instance); } catch (IllegalArgumentException uoe) { exceptions++; } try { arrayOfString.getInstanceField("foo", instance); } catch (IllegalArgumentException uoe) { exceptions++; } try { arrayOfArrayOfString.getInstanceField("foo", instance); } catch (IllegalArgumentException uoe) { exceptions++; } assertEquals(3, exceptions); EasyMock.verify(instance); }