Fix for #1783: Compiler bug : LazyPackage cannot be cast to TypeDeclaration

Make sure we only do this for members of types, as that would break for Java 8
static methods in interfaces
FIXUP
Test for #1783: Compiler bug : LazyPackage cannot be cast to TypeDeclaration

This is actually in the only Java 8 test we have.