unit.accept(visitor);
List<AbstractTypeDeclaration> declarations = visitor.getTypeDeclarations();
if (!declarations.isEmpty())
{
AbstractTypeDeclaration declaration = declarations.get(0);
return getJavaSource(null, document, unit, declaration);
}
else if (visitor.getPackageDeclaration() != null)
{
return getJavaSource(null, document, unit, visitor.getPackageDeclaration());