Thank you, Alain!

I've added to that template possibility to investigate Arrays  - here is the
code:
public String toString()
    {
        try
        {
            StringBuffer sb = new StringBuffer(super.toString() + " : \n");
            Field[] fields = this.getClass().getDeclaredFields();
            for (int i = 0; i < fields.length; i++)
            {
                Object value = fields[i].get(this);
                String name = fields[i].getName();
                if(fields[i].getType().isArray())
                {
                    int index = java.lang.reflect.Array.getLength(value);
                    sb.append(name).append("[] : \n");
                    for (int j = 0; j < index; j++)
                       sb.append("  name[").append(j).append("] =
").append(java.lang.reflect.Array.get(value,j)).append("\n");
                }
                else
                    sb.append(name).append(" = ").append(value).append(";");
            }
            return sb.toString();
        } catch (Exception e)
        {
            throw new RuntimeException(e.toString());
        }
    }

"Alain Ravet" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Another way :
>
http://www.intellij.org/twiki/bin/view/Main/LiveTemplateContribs#Canonical_c
lass
>
>
>
>
>
>
>
> Alain Ravet wrote:
> > Ilya Kharmatsky wrote:
> >
> >> Hi, All!
> >> Is it possible to somehow (live templates, refactoring etc.) to
> >> automatically create "toString"
> >> as a method, which will convert all data members of class to String
> >> object?
> >
> >
> > Lucky you :
http://www.intellij.org/twiki/bin/view/Main/CanonicizerDoclet
>


_______________________________________________
Eap-features mailing list
[EMAIL PROTECTED]
http://lists.jetbrains.com/mailman/listinfo/eap-features

Reply via email to