return true;
}
private BehaviorEntry isAnonymousClass( CtClass c, String outerClassName )
{
ClassEntry innerClassEntry = new ClassEntry( Descriptor.toJvmName( c.getName() ) );
// anonymous classes:
// can't be abstract
// have only one constructor
// it's called exactly once by the outer class
// the type the instance is assigned to can't be this type
// is abstract?
if( Modifier.isAbstract( c.getModifiers() ) )
{
return null;
}
// is there exactly one constructor?
if( c.getDeclaredConstructors().length != 1 )
{
return null;
}
CtConstructor constructor = c.getDeclaredConstructors()[0];
// is this constructor called exactly once?
ConstructorEntry constructorEntry = new ConstructorEntry( innerClassEntry, constructor.getMethodInfo().getDescriptor() );
Collection<EntryReference<BehaviorEntry,BehaviorEntry>> references = getBehaviorReferences( constructorEntry );
if( references.size() != 1 )
{
return null;
}
// does the caller use this type?
BehaviorEntry caller = references.iterator().next().context;
for( FieldEntry fieldEntry : getReferencedFields( caller ) )
{
ClassEntry fieldClass = getFieldClass( fieldEntry );
if( fieldClass != null && fieldClass.equals( innerClassEntry ) )
{
// caller references this type, so it can't be anonymous
return null;
}
}