Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package net.sf.alchim.codeplus.spoonprocessor;
 
public class ToStringGenerator extends AbstractProcessor<CtClass<?>> {
    public void process(CtClass<?> type) {
        try {
            CtAnnotation<?> annotation = ProcessorHelper.findAnnotation(typeGenToString.class);
            if (annotation == null) {
                return;
            }
            final StringBuilder ops = new StringBuilder();
            ops.append("str.append(\"").append(type.getQualifiedName()).append("[\")");
            if ((type.getSuperclass() != null) && (type.getSuperclass().getAllFields() != null)) {
                for (CtFieldReference<?> field : type.getSuperclass().getAllFields()) {
                    if ((field.getAnnotation(NotInToString.class) == null) && !field.getModifiers().contains(.)) {
                        ops.append(".append(\"").append(field.getSimpleName()).append(":\").append(").append(field.getSimpleName()).append(").append(',')");
                    }
                }
            }
            if (type.getFields() != null) {
                for (CtField<?> field : type.getFields()) {
                    if (field.getAnnotation(NotInToString.class) == null) {
                        ops.append(".append(\"").append(field.getSimpleName()).append(":\").append(").append(field.getSimpleName()).append(").append(',')");
                    } else {
                        ProcessorHelper.removeAnnotation(fieldNotInToString.class);
                    }
                }
            }
            ops.append(".append(']');");
            CtBlock<?> block = getFactory().Core().createBlock();
            block.getStatements().add(getFactory().Code().createCodeSnippetStatement(ops.toString()));
            Substitution.insertAllMethods(typenew ToStringTemplate(block));
            ProcessorHelper.removeAnnotation(typeGenToString.class);
        } catch (Exception exc) {
            throw new ProcessingException(thistypeexc);
        }
    }
New to GrepCode? Check out our FAQ X