Returns a new {@link StringBuilder} with the common directives appended.
Note that the first two characters ({@code ", "} must be stripped.
332237
protected final StringBuilder newHeaderValueBuffer() {
        final StringBuilder buf = new StringBuilder(40);
        if (noCache) {
            buf.append(", no-cache");
        }
        if (noStore) {
            buf.append(", no-store");
        }
        if (noTransform) {
            buf.append(", no-transform");
        }
        if (maxAgeSeconds >= 0) {
            buf.append(", max-age=").append(maxAgeSeconds);
        }
        return buf;
    }
468118
private static void htmlEncode(final CharSequence unsafeStr, final boolean turnNewlineIntoBreak,
            final StringBuilder buf) {
        for (int i = 0, n = unsafeStr.length(); i < n; i++) {
            final char c = unsafeStr.charAt(i);
            switch (c) {
            case '&':
                buf.append("&amp;");
                break;
            case '<':
                buf.append("&lt;");
                break;
            case '>':
                buf.append("&gt;");
                break;
            case '"':
                buf.append("&quot;");
                break;
            case '\'':
                buf.append("&#x27;"); // See http://goo.gl/FzoP6m
                break;
            case '\\':
                buf.append("&lsol;");
                break;
            case '/':
                buf.append("&#x2F;"); // '/' can be a dangerous char if attr values are not quoted
                break;
            // Encode a few common characters that like to get screwed up in some charset/browser variants
            case '—':
                buf.append("&mdash;");
                break;
            case '–':
                buf.append("&ndash;");
                break;
            case '“':
                buf.append("&ldquo;");
                break;
            case '”':
                buf.append("&rdquo;");
                break;
            case '‘':
                buf.append("&lsquo;");
                break;
            case '’':
                buf.append("&rsquo;");
                break;
            case '«':
                buf.append("&laquo;");
                break;
            case '»':
                buf.append("&raquo;");
                break;
            case '£':
                buf.append("&pound;");
                break;
            case '©':
                buf.append("&copy;");
                break;
            case '®':
                buf.append("&reg;");
                break;
            case (char) 0x00A0:
                buf.append("&nbsp;");
                break;
            case '\n':
                if (turnNewlineIntoBreak) {
                    buf.append("<br>");
                } else {
                    buf.append(' '); // Newlines function as whitespace in HTML text
                }
                break;
            default:
                if (c <= 32 || isUnicodeWhitespace(c)) {
                    buf.append(' ');
                } else {
                    buf.append(c);
                }
                break;
            }
        }
    }
1159018
private static void appendDescriptor(final StringBuilder stringBuilder, final Class<?> clazz) {
    Class<?> currentClass = clazz;
    while (currentClass.isArray()) {
      stringBuilder.append('[');
      currentClass = currentClass.getComponentType();
    }
    if (currentClass.isPrimitive()) {
      char descriptor;
      if (currentClass == Integer.TYPE) {
        descriptor = 'I';
      } else if (currentClass == Void.TYPE) {
        descriptor = 'V';
      } else if (currentClass == Boolean.TYPE) {
        descriptor = 'Z';
      } else if (currentClass == Byte.TYPE) {
        descriptor = 'B';
      } else if (currentClass == Character.TYPE) {
        descriptor = 'C';
      } else if (currentClass == Short.TYPE) {
        descriptor = 'S';
      } else if (currentClass == Double.TYPE) {
        descriptor = 'D';
      } else if (currentClass == Float.TYPE) {
        descriptor = 'F';
      } else if (currentClass == Long.TYPE) {
        descriptor = 'J';
      } else {
        throw new AssertionError();
      }
      stringBuilder.append(descriptor);
    } else {
      stringBuilder.append('L');
      String name = currentClass.getName();
      int nameLength = name.length();
      for (int i = 0; i < nameLength; ++i) {
        char car = name.charAt(i);
        stringBuilder.append(car == '.' ? '/' : car);
      }
      stringBuilder.append(';');
    }
  }
1084262
@SuppressWarnings("checkstyle:all")
	protected StringConcatenationClient generateMembers(boolean forInterface, boolean forAppender) {
		final TypeReference adapter = getCodeElementExtractor().getInnerBlockDocumentationAdapter();
		return new StringConcatenationClient() {
			@Override
			protected void appendTo(TargetStringConcatenation it) {
				if (!forInterface && !forAppender) {
					it.append("\t@"); //$NON-NLS-1$
					it.append(Inject.class);
					it.newLine();
					it.append("\tprivate "); //$NON-NLS-1$
					it.append(ITaskTagProvider.class);
					it.append(" taskTagProvider;"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\t@"); //$NON-NLS-1$
					it.append(Inject.class);
					it.newLine();
					it.append("\tprivate "); //$NON-NLS-1$
					it.append(Provider.class);
					it.append("<"); //$NON-NLS-1$
					it.append(getExpressionBuilderInterface());
					it.append("> expressionProvider;"); //$NON-NLS-1$
					it.newLine();
					it.append("\tprivate "); //$NON-NLS-1$
					it.append(XBlockExpression.class);
					it.append(" block;"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\t/** Replies the provider of task tags."); //$NON-NLS-1$
					it.newLine();
					it.append("\t *"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the provider."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\tprotected "); //$NON-NLS-1$
					it.append(ITaskTagProvider.class);
					it.append(" getTaskTagProvider() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn this.taskTagProvider;"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else {
					it.append("\t/** Find the reference to the type with the given name."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param typeName the fully qualified name of the type"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the type reference."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					if (!forInterface) {
						it.append("public "); //$NON-NLS-1$
					}
					it.append(JvmParameterizedTypeReference.class);
					it.append(" newTypeRef(String typeName)"); //$NON-NLS-1$
					if (forInterface) {
						it.append(";"); //$NON-NLS-1$
					} else {
						it.append(" {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn this.builder.newTypeRef(typeName);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t}"); //$NON-NLS-1$
					}
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\t/** Find the reference to the type with the given name."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param context the context for the type reference use"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param typeName the fully qualified name of the type"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the type reference."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					if (!forInterface) {
						it.append("public "); //$NON-NLS-1$
					}
					it.append(JvmParameterizedTypeReference.class);
					it.append(" newTypeRef("); //$NON-NLS-1$
					it.append(Notifier.class);
					it.append(" context, String typeName)"); //$NON-NLS-1$
					if (forInterface) {
						it.append(";"); //$NON-NLS-1$
					} else {
						it.append(" {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn this.builder.newTypeRef(context, typeName);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t}"); //$NON-NLS-1$
					}
					it.newLineIfNotEmpty();
					it.newLine();
				}
				if (forInterface) {
					it.append("\t/** Replies the context for type resolution."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the context or <code>null</code> if the Ecore object is the context."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					it.append(IJvmTypeProvider.class);
					it.append(" getTypeResolutionContext();"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else if (forAppender) {
					it.append("\tpublic "); //$NON-NLS-1$
					it.append(IJvmTypeProvider.class);
					it.append(" getTypeResolutionContext() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn this.builder.getTypeResolutionContext();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}
				it.append("\t/** Create the XBlockExpression."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("void eInit("); //$NON-NLS-1$
				it.append(IJvmTypeProvider.class);
				it.append(" context)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\tthis.builder.eInit(context);"); //$NON-NLS-1$
					} else {
						it.append("\t\tsetTypeResolutionContext(context);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tif (this.block == null) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\tthis.block = "); //$NON-NLS-1$
						it.append(XbaseFactory.class);
						it.append(".eINSTANCE.createXBlockExpression();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t}"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** Replies the string for \"auto-generated\" comments."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @return the comment text."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("String getAutoGeneratedActionString()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\treturn this.builder.getAutoGeneratedActionString();"); //$NON-NLS-1$
					} else {
						it.append("\t\treturn getAutoGeneratedActionString(getXBlockExpression().eResource());"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** Replies the string for \"auto-generated\" comments."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param resource the resource for which the comment must be determined."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @return the comment text."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("String getAutoGeneratedActionString("); //$NON-NLS-1$
				it.append(Resource.class);
				it.append(" resource)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\treturn this.builder.getAutoGeneratedActionString(resource);"); //$NON-NLS-1$
					} else {
						it.append("\t\t"); //$NON-NLS-1$
						it.append(TaskTags.class);
						it.append(" tags = getTaskTagProvider().getTaskTags(resource);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tString taskTag;"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tif (tags != null && tags.getTaskTags() != null && !tags.getTaskTags().isEmpty()) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\ttaskTag = tags.getTaskTags().get(0).getName();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t} else {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\ttaskTag = \"TODO\";"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t}"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn taskTag + \" "); //$NON-NLS-1$
						it.append(Strings.convertToJavaString(getCodeBuilderConfig().getAutoGeneratedComment()));
						it.append("\";"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** An empty block expression."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @return the block expression."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append(XBlockExpression.class);
				it.append(" getXBlockExpression()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\treturn this.builder.getXBlockExpression();"); //$NON-NLS-1$
					} else {
						it.append("\t\treturn this.block;"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** Replies the resource to which the XBlockExpression is attached."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append(Resource.class);
				it.append(" eResource()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn getXBlockExpression().eResource();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append(generateCommentFunction(forInterface, false, "getXBlockExpression()", //$NON-NLS-1$
						"setInnerDocumentation", //$NON-NLS-1$
						"getXBlockExpression()", //$NON-NLS-1$
						adapter));
				it.append("\t/** Add an expression inside the block."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @return the expression builder."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append(getExpressionBuilderInterface());
				it.append(" addExpression()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\treturn this.builder.addExpression();"); //$NON-NLS-1$
					} else {
						it.append("\t\tfinal "); //$NON-NLS-1$
						it.append(getExpressionBuilderInterface());
						it.append(" builder = this.expressionProvider.get();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tbuilder.eInit(getXBlockExpression(), new "); //$NON-NLS-1$
						it.append(Procedures.class);
						it.append(".Procedure1<"); //$NON-NLS-1$
						it.append(XExpression.class);
						it.append(">() {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\tprivate int index = -1;"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\tpublic void apply("); //$NON-NLS-1$
						it.append(XExpression.class);
						it.append(" it) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\tif (this.index >= 0) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\t\tgetXBlockExpression().getExpressions().set(index, it);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\t} else {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\t\tgetXBlockExpression().getExpressions().add(it);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\t\tthis.index = getXBlockExpression().getExpressions().size() - 1;"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t\t}"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t\t}"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\t}, getTypeResolutionContext());"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn builder;"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** Fill the block with the standard \"auto-generated\" content."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * <p>Any previously added content is removed."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param type the expected type of the block (the last instruction), or"); //$NON-NLS-1$
				it.newLine();
				it.append("\t    <code>null</code> for no type."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("void setDefaultAutoGeneratedContent(String type)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\tthis.builder.setDefaultAutoGeneratedContent(type);"); //$NON-NLS-1$
					} else {
						it.append("\t\tgetXBlockExpression().getExpressions().clear();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tif ("); //$NON-NLS-1$
						it.append(Strings.class);
						it.append(".isEmpty(type)) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\tsetInnerDocumentation(getAutoGeneratedActionString());"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t} else {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t"); //$NON-NLS-1$
						it.append(getExpressionBuilderInterface());
						it.append(" expr = addExpression();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\tString defaultValue = expr.getDefaultValueForType(type);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\tif ("); //$NON-NLS-1$
						it.append(Strings.class);
						it.append(".isEmpty(defaultValue)) {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\tsetInnerDocumentation(getAutoGeneratedActionString());"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t} else {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\texpr.setExpression(defaultValue);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t\texpr.setDocumentation(getAutoGeneratedActionString());"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t\t}"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\t}"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				if (!forInterface) {
					it.append("\t@"); //$NON-NLS-1$
					it.append(Override.class);
					it.newLine();
					it.append("\t@"); //$NON-NLS-1$
					it.append(Pure.class);
					it.newLine();
					it.append("\tpublic "); //$NON-NLS-1$
					it.append(String.class);
					it.append(" toString() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn "); //$NON-NLS-1$
					if (forAppender) {
						it.append("this.builder.toString();"); //$NON-NLS-1$
					} else {
						it.append(EmfFormatter.class);
						it.append(".objToStr(getXBlockExpression());"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}
				if (forInterface) {
					it.append("\t/** Dispose the resource."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\tvoid dispose();"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else if (forAppender) {
					it.append("\t/** Dispose the resource."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\tpublic void dispose() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\tthis.builder.dispose();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}
			}
		};
	}
693993
public static String encodeXML( final String    str )
    {
        if ( str == null )
        {
            return null;
        }

        StringCharacterIterator    iterator = new StringCharacterIterator( str );
        StringBuilder              result   = new StringBuilder();
        char                       c;

        for( c  = iterator.current();
             c != CharacterIterator.DONE;
             c  = iterator.next() )
        {
            if ( c == '>' )
            {
                result.append( "&gt;" );
            }
            else if ( c == '<' )
            {
                result.append( "&lt;" );
            }
            else if ( c == '&' )
            {
                result.append( "&amp;" );
            }
            else if ( c == '"' )
            {
                result.append( "&quot;" );
            }
            else if ( c == '\'' )
            {
                result.append( "&#39;" );
            }
            else
            {
                result.append( c );
            }
        }

        return result.toString();
    }
1000673
public static void callStringBuilderAppendChar(CodeBuilder b) {
        // Because of JDK1.5 bug which exposes AbstractStringBuilder class,
        // cannot use reflection to get method signature.
        TypeDesc stringBuilder = TypeDesc.forClass(StringBuilder.class);
        b.invokeVirtual(stringBuilder, "append", stringBuilder, new TypeDesc[] {TypeDesc.CHAR});
    }
1354598
@Override
  StringBuilder appendTo(StringBuilder sb, boolean forAnnotations) {
    if (!isPrettyPrint() || this == registry.getNativeType(JSTypeNative.FUNCTION_INSTANCE_TYPE)) {
      return sb.append(forAnnotations ? "!Function" : "Function");
    }

    if (hasInstanceType() && getSource() != null) {
      // Render function types known to be type definitions as "(typeof Foo)". This includes types
      // defined like "/** @constructor */ function Foo() { }" but not to those defined like "@param
      // {function(new:Foo)}". Only the former will have a source node.
      sb.append("(typeof ");
      getInstanceType().appendTo(sb, forAnnotations);
      sb.append(")");
      return sb;
    }

    setPrettyPrint(false);

    sb.append("function(");
    int paramNum = call.parameters.getChildCount();
    boolean hasKnownTypeOfThis = !(typeOfThis instanceof UnknownType);
    if (hasKnownTypeOfThis) {
      if (isConstructor()) {
        sb.append("new:");
      } else {
        sb.append("this:");
      }
      typeOfThis.appendTo(sb, forAnnotations);
    }
    if (paramNum > 0) {
      if (hasKnownTypeOfThis) {
        sb.append(", ");
      }
      Node p = call.parameters.getFirstChild();
      appendArgString(sb, p, forAnnotations);

      p = p.getNext();
      while (p != null) {
        sb.append(", ");
        appendArgString(sb, p, forAnnotations);
        p = p.getNext();
      }
    }
    sb.append("): ");
    call.returnType.appendAsNonNull(sb, forAnnotations);

    setPrettyPrint(true);
    return sb;
  }
13877
private static void appendToBuilder(long l, int radix, StringBuilder builder, char[] bufferConversion)
    {
        if (radix < Character.MIN_RADIX || radix > Character.MAX_RADIX)
        {
            radix = 10;
        }
        if (l == 0)
        {
            builder.append('0');
            return;
        }

        int count = 2;
        long j = l;
        boolean negative = l < 0;
        if (!negative)
        {
            count = 1;
            j = -l;
        }
        while ((l /= radix) != 0)
        {
            count++;
        }

        if (bufferConversion.length < count)
        {
            bufferConversion = new char[count];
        }
        int finalCount = count;

        char[] buffer = bufferConversion;
        do 
        {
            int ch = 0 - (int) (j % radix);
            if (ch > 9)
            {
                ch = ch - 10 + 'a';
            }
            else
            {
                ch += '0';
            }
            buffer[--count] = (char) ch;
            j /= radix;
        }
        while (j != 0);
        if (negative)
        {
            buffer[0] = '-';
        }
        for (int i = 0; i < finalCount; i++)
        {
            builder.append(buffer[i]);
        }
        //return new String(0, buffer.length, buffer);
    }
696397
@SuppressWarnings("checkstyle:all")
	protected StringConcatenationClient generateMembers(boolean forInterface, boolean forAppender) {
		final CodeElementExtractor.ElementDescription parameter = getCodeElementExtractor().getTypeParameter();
		return new StringConcatenationClient() {
			@Override
			protected void appendTo(TargetStringConcatenation it) {
				if (!forInterface && !forAppender) {
					it.append("\tprivate "); //$NON-NLS-1$
					it.append(EObject.class);
					it.append(" context;"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\tprivate "); //$NON-NLS-1$
					it.append(parameter.getElementType());
					it.append(" parameter;"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\t@"); //$NON-NLS-1$
					it.append(Inject.class);
					it.newLine();
					it.append("\t\tprivate "); //$NON-NLS-1$
					it.append(TypesFactory.class);
					it.append(" jvmTypesFactory;"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else {
					it.append("\t/** Find the reference to the type with the given name."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param typeName the fully qualified name of the type"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the type reference."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					if (!forInterface) {
						it.append("public "); //$NON-NLS-1$
					}
					it.append(JvmParameterizedTypeReference.class);
					it.append(" newTypeRef(String typeName)"); //$NON-NLS-1$
					if (forInterface) {
						it.append(";"); //$NON-NLS-1$
					} else {
						it.append(" {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn this.builder.newTypeRef(typeName);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t}"); //$NON-NLS-1$
					}
					it.newLineIfNotEmpty();
					it.newLine();
					it.append("\t/** Find the reference to the type with the given name."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param context the context for the type reference use"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @param typeName the fully qualified name of the type"); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the type reference."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					if (!forInterface) {
						it.append("public "); //$NON-NLS-1$
					}
					it.append(JvmParameterizedTypeReference.class);
					it.append(" newTypeRef("); //$NON-NLS-1$
					it.append(Notifier.class);
					it.append(" context, String typeName)"); //$NON-NLS-1$
					if (forInterface) {
						it.append(";"); //$NON-NLS-1$
					} else {
						it.append(" {"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\treturn this.builder.newTypeRef(context, typeName);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t}"); //$NON-NLS-1$
					}
					it.newLineIfNotEmpty();
					it.newLine();
				}

				it.append("\t/** Initialize the type parameter."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * <p>Caution: This initialization function does not add the type parameter in its container."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * The container is responsible of adding the type parameter in its internal object."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param name the name of the type parameter."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param typeContext the provider of types or null."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("void eInit("); //$NON-NLS-1$
				it.append(EObject.class);
				it.append(" context, String name, "); //$NON-NLS-1$
				it.append(IJvmTypeProvider.class);
				it.append(" typeContext)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\tthis.builder.eInit(context, name, typeContext);"); //$NON-NLS-1$
					} else {
						it.append("\t\tsetTypeResolutionContext(typeContext);"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tthis.context = context;"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tthis.parameter = this.jvmTypesFactory.create"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
						it.append("();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tthis.parameter.set"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(getCodeBuilderConfig().getParameterNameGrammarName()));
						it.append("(name);"); //$NON-NLS-1$
						it.newLine();
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				if (forInterface) {
					it.append("\t/** Replies the context for type resolution."); //$NON-NLS-1$
					it.newLine();
					it.append("\t * @return the context or <code>null</code> if the Ecore object is the context."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\t"); //$NON-NLS-1$
					it.append(IJvmTypeProvider.class);
					it.append(" getTypeResolutionContext();"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else if (forAppender) {
					it.append("\tpublic "); //$NON-NLS-1$
					it.append(IJvmTypeProvider.class);
					it.append(" getTypeResolutionContext() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn this.builder.getTypeResolutionContext();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}
				it.append("\t/** Replies the created parameter."); //$NON-NLS-1$
				it.newLine();
				it.append("\t *"); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @return the parameter."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append(parameter.getElementType());
				it.append(" get"); //$NON-NLS-1$
				it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
				it.append("()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					if (forAppender) {
						it.append("\t\treturn this.builder.get"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
						it.append("();"); //$NON-NLS-1$
					} else {
						it.append("\t\treturn this.parameter;"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				it.append("\t/** Replies the resource to which the type parameter is attached."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t@"); //$NON-NLS-1$
				it.append(Pure.class);
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append(Resource.class);
				it.append(" eResource()"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn get"); //$NON-NLS-1$
					it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
					it.append("().eResource();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
				if (!forAppender && !forInterface) {
					it.append("\t@"); //$NON-NLS-1$
					it.append(Override.class);
					it.newLine();
					it.append("\t@"); //$NON-NLS-1$
					it.append(Pure.class);
					it.newLine();
					it.append("\tpublic "); //$NON-NLS-1$
					it.append(String.class);
					it.append(" toString() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\treturn "); //$NON-NLS-1$
					if (forAppender) {
						it.append("this.builder.toString();"); //$NON-NLS-1$
					} else {
						it.append(EmfFormatter.class);
						it.append(".objToStr(get"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
						it.append("());"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}
				if (forInterface) {
					it.append("\t/** Dispose the resource."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\tvoid dispose();"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				} else if (forAppender) {
					it.append("\t/** Dispose the resource."); //$NON-NLS-1$
					it.newLine();
					it.append("\t */"); //$NON-NLS-1$
					it.newLine();
					it.append("\tpublic void dispose() {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\tthis.builder.dispose();"); //$NON-NLS-1$
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
					it.newLineIfNotEmpty();
					it.newLine();
				}

				it.append("\t/** Add upper type bounds."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param type the type."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("void addUpperConstraint(String type)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\t"); //$NON-NLS-1$
					if (forAppender) {
						it.append("this.builder.addUpperConstraint(type);"); //$NON-NLS-1$
					} else {
						it.append("final "); //$NON-NLS-1$
						it.append(JvmUpperBound.class);
						it.append(" constraint = this.jvmTypesFactory.createJvmUpperBound();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tconstraint.setTypeReference(newTypeRef(this.context, type));"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tget"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
						it.append("().getConstraints().add(constraint);"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();

				it.append("\t/** Add lower type bounds."); //$NON-NLS-1$
				it.newLine();
				it.append("\t * @param type the type."); //$NON-NLS-1$
				it.newLine();
				it.append("\t */"); //$NON-NLS-1$
				it.newLine();
				it.append("\t"); //$NON-NLS-1$
				if (!forInterface) {
					it.append("public "); //$NON-NLS-1$
				}
				it.append("void addLowerConstraint(String type)"); //$NON-NLS-1$
				if (forInterface) {
					it.append(";"); //$NON-NLS-1$
				} else {
					it.append(" {"); //$NON-NLS-1$
					it.newLine();
					it.append("\t\t"); //$NON-NLS-1$
					if (forAppender) {
						it.append("this.builder.addLowerConstraint(type);"); //$NON-NLS-1$
					} else {
						it.append("final "); //$NON-NLS-1$
						it.append(JvmLowerBound.class);
						it.append(" constraint = this.jvmTypesFactory.createJvmLowerBound();"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tconstraint.setTypeReference(newTypeRef(this.context, type));"); //$NON-NLS-1$
						it.newLine();
						it.append("\t\tget"); //$NON-NLS-1$
						it.append(Strings.toFirstUpper(parameter.getElementType().getSimpleName()));
						it.append("().getConstraints().add(constraint);"); //$NON-NLS-1$
					}
					it.newLine();
					it.append("\t}"); //$NON-NLS-1$
				}
				it.newLineIfNotEmpty();
				it.newLine();
			}
		};
	}
685950
private StringBuilder format(final MapFormat format, final StringBuilder sb) {
        if (format == null) {
            appendMap(sb);
        } else {
            switch (format) {
                case XML : {
                    asXml(sb);
                    break;
                }
                case JSON : {
                    asJson(sb);
                    break;
                }
                case JAVA : {
                    asJava(sb);
                    break;
                }
                default : {
                    appendMap(sb);
                }
            }
        }
        return sb;
    }
147307
public SpannableStringBuilder build() {
        if (mBeforeStringBuilder.length() > 0) {
            mStringBuilder.insert(0, mBeforeStringBuilder);

            // reset SpecialUnit start pos
            if (!mFinalSpecialUnit.isEmpty()) {
                for (BaseSpecialUnit specialUnit : mFinalSpecialUnit) {
                    int[] tempStartPoss = specialUnit.getStartPoss();

                    if (null == tempStartPoss || tempStartPoss.length == 0) continue;

                    for (int i = 0; i < tempStartPoss.length; i++) {
                        int oldStartPos = tempStartPoss[i];
                        tempStartPoss[i] = oldStartPos + mBeforeStringBuilder.length();
                    }
                }
            }

            // reset Cache SpecialClickableUnit start pos
            if (!mCacheSpecialClickableUnitMap.isEmpty()) {
                for (Map.Entry<SpecialClickableUnit, PositionInfo> cm : mCacheSpecialClickableUnitMap.entrySet()) {
                    cm.getValue().startPos += mBeforeStringBuilder.length();
                }
            }
        }

        if (!mBeforeCacheSpecialClickableUnitMap.isEmpty()) {
            mCacheSpecialClickableUnitMap.putAll(mBeforeCacheSpecialClickableUnitMap);
        }

        if (!mBeforeSpecialUnit.isEmpty()) {
            mFinalSpecialUnit.addAll(mBeforeSpecialUnit);
        }

        if (mStringBuilder.length() == 0) return null;
        if (mFinalSpecialUnit.isEmpty())
            return new SpannableStringBuilder(mStringBuilder.toString());

        if (mNormalSizeText.length() == 0) mNormalSizeText.append(mStringBuilder);

        String normalSizeText = mNormalSizeText.toString();
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(mStringBuilder);
        boolean isInitClickListener = false;
        for (BaseSpecialUnit st : mFinalSpecialUnit) {
            String specialText = st.getText();
            int[] startPoss = st.getStartPoss();

            if (TextUtils.isEmpty(specialText) || null == startPoss || startPoss.length == 0)
                continue;

            int specialTextLength = specialText.length();
            if (st instanceof SpecialTextUnit) {
                // text span
                SpecialTextUnit specialTextUnit = (SpecialTextUnit) st;

                final SpecialClickableUnit internalSpecialClickableUnit = specialTextUnit.getSpecialClickableUnit();
                if (null != internalSpecialClickableUnit) {
                    if (internalSpecialClickableUnit.getNormalTextColor() == 0) {
                        internalSpecialClickableUnit.setNormalTextColor(specialTextUnit.getTextColor());
                    }
                    if (internalSpecialClickableUnit.getNormalBgColor() == 0) {
                        internalSpecialClickableUnit.setNormalBgColor(specialTextUnit.getTextBackgroundColor());
                    }
                }
                for (int startPos : startPoss) {
                    // Set Text Color
                    if (specialTextUnit.getTextColor() != 0) {
                        spannableStringBuilder.setSpan(new ForegroundColorSpan(specialTextUnit.getTextColor()), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Set Text Background Color
                    if (specialTextUnit.getTextBackgroundColor() != 0 && null == internalSpecialClickableUnit) {
                        spannableStringBuilder.setSpan(new BackgroundColorSpan(specialTextUnit.getTextBackgroundColor()), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Add Underline
                    if (specialTextUnit.isShowUnderline()) {
                        spannableStringBuilder.setSpan(new UnderlineSpan(), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Add StrikeThrough
                    if (specialTextUnit.isShowStrikeThrough()) {
                        spannableStringBuilder.setSpan(new StrikethroughSpan(), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Set Text Bold
                    if (specialTextUnit.isTextBold()) {
                        spannableStringBuilder.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Set Text Italic
                    if (specialTextUnit.isTextItalic()) {
                        spannableStringBuilder.setSpan(new StyleSpan(Typeface.ITALIC), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Set Text Style
                    if (specialTextUnit.getTextStyle() != Typeface.NORMAL) {
                        spannableStringBuilder.setSpan(new StyleSpan(specialTextUnit.getTextStyle()), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }

                    // Set Text Size
                    if (specialTextUnit.getTextSize() > 0) {
                        TextView curTextView = specialTextUnit.getCurTextView();
                        int gravity = specialTextUnit.getGravity();
                        if (gravity != SpecialGravity.BOTTOM && null != curTextView) {
                            spannableStringBuilder.setSpan(new CustomAbsoluteSizeSpan(normalSizeText, specialTextUnit.getText(), Math.round(specialTextUnit.getTextSize()), curTextView, gravity), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        } else {
                            spannableStringBuilder.setSpan(new AbsoluteSizeSpan(Math.round(specialTextUnit.getTextSize()), true), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                        }
                    }

                    // set clickable
                    if (null != internalSpecialClickableUnit) {
                        if (!isInitClickListener) {
                            isInitClickListener = true;
                            TextView curTextView = internalSpecialClickableUnit.getCurTextView();
                            if (null != curTextView) {
                                curTextView.setMovementMethod(CustomLinkMovementMethod.getInstance());
                            }
                        }
                        spannableStringBuilder.setSpan(new CustomClickableSpan(internalSpecialClickableUnit), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                }
            } else if (st instanceof SpecialImageUnit) {
                // image Span
                SpecialImageUnit specialImageUnit = (SpecialImageUnit) st;
                Bitmap bitmap = specialImageUnit.getBitmap();
                int imgWidth = specialImageUnit.getWidth();
                int imgHeight = specialImageUnit.getHeight();
                if (imgWidth > 0 && imgHeight > 0) {
                    int bitWidth = bitmap.getWidth();
                    int bitHeight = bitmap.getHeight();

                    if (imgWidth < bitWidth && imgHeight < bitHeight) {
                        Bitmap newBitmap = ThumbnailUtils.extractThumbnail(bitmap, imgWidth, imgHeight);
                        if (null != newBitmap) {
                            bitmap.recycle();
                            specialImageUnit.setBitmap(newBitmap);
                        }
                    }
                }

                for (int startPos : startPoss) {
                    CustomImageSpan curCustomImageSpan = new CustomImageSpan(normalSizeText, specialImageUnit);
                    spannableStringBuilder.setSpan(curCustomImageSpan, startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    if (specialImageUnit.isClickable()) {
                        addClickStateChangeListeners(startPos, startPos + specialTextLength, curCustomImageSpan);
                    }
                }
            } else if (st instanceof SpecialLabelUnit) {
                // label span
                SpecialLabelUnit specialLabelUnit = (SpecialLabelUnit) st;
                for (int startPos : startPoss) {
                    CustomLabelSpan curCustomLabelSpan = new CustomLabelSpan(normalSizeText, specialLabelUnit);
                    spannableStringBuilder.setSpan(curCustomLabelSpan, startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

                    if (specialLabelUnit.isClickable()) {
                        addClickStateChangeListeners(startPos, startPos + specialTextLength, curCustomLabelSpan);
                    }
                }
            } else if (st instanceof SpecialClickableUnit) {
                // clickable span
                SpecialClickableUnit specialClickableUnit = (SpecialClickableUnit) st;

                if (!isInitClickListener) {
                    isInitClickListener = true;
                    TextView curTextView = specialClickableUnit.getCurTextView();
                    if (null != curTextView) {
                        curTextView.setMovementMethod(CustomLinkMovementMethod.getInstance());
                    }
                }

                int startPos = startPoss[0];
                spannableStringBuilder.setSpan(new CustomClickableSpan(specialClickableUnit), startPos, startPos + specialTextLength, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            } else if (st instanceof SpecialRawSpanUnit) {
                // raw span
                SpecialRawSpanUnit specialRawSpanUnit = (SpecialRawSpanUnit) st;

                int startPos = startPoss[0];
                spannableStringBuilder.setSpan(specialRawSpanUnit.getSpanObj(), startPos, startPos + specialTextLength, specialRawSpanUnit.getFlags());

                // Temporarily unable to support all
            }
        }

        return spannableStringBuilder;
    }
23772
public SpannableStringBuilder insert(int where, CharSequence tb, int start, int end) {
        return replace(where, where, tb, start, end);
    }
496344
public JsCodeBuilder append(String... codeFragments) {
    for (String codeFragment : codeFragments) {
      code.append(codeFragment);
    }
    return this;
  }
933841
public static StringBuilder toStringBuilder(Collection<? extends Object> collection, String delimiter) {
        StringBuilder sb = new StringBuilder(collection.size() * 20);
        for (Iterator<? extends Object> it = collection.iterator(); it.hasNext();) {
            Object cs = it.next();
            sb.append(cs);
            if (it.hasNext()) {
                sb.append(delimiter);
            }
        }
        return sb;
    }
240574
private void getStringFromValue(final StringBuilder builder, final String directive, final String value) {
        if (value != null) {
            builder.append(directive).append(" ").append(value).append(";");
        }
    }
551843
StringBuilder subBuf(int start, int end) {
		if (start > end) {
			return null;
		}
		StringBuilder ret = new StringBuilder(end - start + 1);
		for (int i=start; i<=end; i++) {
			ret.append(buf[i]);
		}
		return ret;
	}
452973
@Override
    public TextObject append(CharSequence text) {
        if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this;

        text = textFilter.filter(text);

        //unfortunately this code can't be put into a TextFilter because:
        //1) the limit could not be detected early, a lot of work would be done to waste time and memory
        //2) the last character of the existing string builder could not be seen. if it is a space, we don't want
        //   to add yet another space.
        char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1);
        for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) {
            char c = CharNormalizer.normalize(text.charAt(i));
            if (c != ' ' || pre != ' ') {
                stringBuilder.append(c);
            }
            pre = c;
        }

        return this;
    }