List<TypeAnnotationWriteHelper> ( StringBuilder sb, Type type, List<String> nestedTypes, List<TypeAnnotationWriteHelper> typeAnnWriteHelpers ) { List<ClassesProcessor.ClassNode> enclosingClasses = enclosingClassList(); StringBuilder curPathBldr = new StringBuilder(type.getValue().substring(0, type.getValue().lastIndexOf('/') + 1)); for (int i = 0; i < nestedTypes.size(); i++) { String nestedType = nestedTypes.get(i); boolean shouldWrite = true; if (!enclosingClasses.isEmpty() && i != nestedTypes.size() - 1) { String enclosingType = enclosingClasses.remove(0).simpleName; shouldWrite = !nestedType.equals(enclosingType); } if (i == 0) { // first annotation can be written already if (!sb.toString().isEmpty()) shouldWrite = true; // write if annotation exists } else { if (canWriteNestedTypeAnnotation(curPathBldr + nestedType + '$', nestedTypes.subList(i + 1, nestedTypes.size()))) { List<TypeAnnotationWriteHelper> notWrittenTypeAnnotations = writeNestedTypeAnnotations(sb, typeAnnWriteHelpers); shouldWrite |= (notWrittenTypeAnnotations.size() != typeAnnWriteHelpers.size()); typeAnnWriteHelpers = notWrittenTypeAnnotations; if (i != nestedTypes.size() - 1) popNestedTypeAnnotation(typeAnnWriteHelpers); } } if (shouldWrite) { sb.append(nestedType); curPathBldr.append(nestedType); if (i != nestedTypes.size() - 1) { curPathBldr.append('$'); sb.append('.'); } } } return typeAnnWriteHelpers; }