Exemple #1
0
 /**
  * Given a string, replace all occurraces of 'newStr' with 'oldStr'.
  *
  * @param originalStr the string to modify.
  * @param oldStr the string to replace.
  * @param newStr the string to insert in place of the old string.
  */
 public static String replaceText(String originalStr, String oldStr, String newStr) {
   if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
     return originalStr;
   }
   StringBuffer result = new StringBuffer(originalStr);
   int startIndex = 0;
   while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
     result = result.replace(startIndex, startIndex + oldStr.length(), newStr);
     startIndex += newStr.length();
   }
   return result.toString();
 }
Exemple #2
0
 /**
  * Given a string, replace all tabs with the appropriate number of spaces.
  *
  * @param tabLength the length of each tab.
  * @param s the String to scan.
  */
 public static void replaceTabs(int tabLength, StringBuffer s) {
   int index, col;
   StringBuffer whitespace;
   while ((index = s.indexOf("\t")) != -1) {
     whitespace = new StringBuffer();
     col = index;
     do {
       whitespace.append(" ");
       col++;
     } while ((col % tabLength) != 0);
     s.replace(index, index + 1, whitespace.toString());
   }
 }
Exemple #3
0
  /**
   * Given an array of <code>Tag</code>s representing this custom tag, return its string
   * representation.
   *
   * @param tags the array of <code>Tag</code>s representing of this custom tag.
   */
  public String toString(Tag[] tags) {
    StringBuffer ret;

    if (0 == tags.length) return (null);
    else {
      ret = new StringBuffer(512);
      for (int i = 0; i < tags.length; i++) {
        if (i > 0) ret.append("<br>\n");
        ret.append(format(tags[i].text()));
      }
      return (ret.toString());
    }
  }
  /**
   * Computing the hash for a method is useful so as to create an alternate key from the method name
   * + signature.
   *
   * @param qualifiedMethodName
   * @param methodSignature
   * @return
   */
  public static String computeHash(String qualifiedMethodName, String methodSignature) {
    String fullMethodName = qualifiedMethodName + methodSignature;

    byte[] bytes = fullMethodName.getBytes();
    md5.reset();
    md5.update(bytes);

    byte[] messageBytes = md5.digest();

    StringBuffer message = new StringBuffer();
    for (byte aByte : messageBytes) {
      String expanded = Integer.toHexString(0xFF & aByte);
      if (expanded.length() == 1) {
        // normalize length of all strings
        message.append("0");
      }

      message.append(expanded);
    }

    return message.toString();
  }
 private String makeSignature(boolean full) {
   StringBuffer result = new StringBuffer();
   result.append("(");
   for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {
     Type t = (Type) types.head;
     result.append(TypeMaker.getTypeString(env, t, full));
     types = types.tail;
     if (types.nonEmpty()) {
       result.append(", ");
     }
   }
   if (isVarArgs()) {
     int len = result.length();
     result.replace(len - 2, len, "...");
   }
   result.append(")");
   return result.toString();
 }
Exemple #6
0
  /**
   * Format the given string to appear "as is" within a JavaDoc comment. This method is more
   * complicated than it needs to be, since you might say why not just use PRE tags surrounding the
   * text. Unfortunately, PRE is a block level tag that breaks the flow of text, preventing inline
   * operation. Instead we manually format the whitespace (actually just spaces and newlines) within
   * the string to preserve the format.
   */
  protected String format(String s) {
    int base;
    int offset;
    StringBuffer ret;

    ret = new StringBuffer(512);

    base = 0;
    offset = 0;
    while (-1 != (offset = s.indexOf('\n', base))) {
      ret.append(Translate.encode(s.substring(base, offset)));
      ret.append("<br>\n");
      base = offset + 1;
    }
    if (base != s.length()) ret.append(Translate.encode(s.substring(base)));

    s = ret.toString();
    ret.setLength(0);
    for (int i = 0; i < s.length(); i++)
      if (' ' == s.charAt(i)) ret.append("&nbsp;");
      else ret.append(s.charAt(i));

    return (ret.toString());
  }
 /* Do unicode to ansi C identifier conversion.
 %%% This may not be right, but should be called more often. */
 protected final String nameToIdentifier(String name) {
   int len = name.length();
   StringBuffer buf = new StringBuffer(len);
   for (int i = 0; i < len; i++) {
     char c = name.charAt(i);
     if (isASCIILetterOrDigit(c)) buf.append(c);
     else if (c == '/') buf.append('_');
     else if (c == '.') buf.append('_');
     else if (c == '_') buf.append("_1");
     else if (c == ';') buf.append("_2");
     else if (c == '[') buf.append("_3");
     else buf.append("_0" + ((int) c));
   }
   return new String(buf);
 }
 /**
  * Build the signature of the current annotation type.
  *
  * @param node the XML element that specifies which components to document
  * @param annotationInfoTree the content tree to which the documentation will be added
  */
 public void buildAnnotationTypeSignature(XMLNode node, Content annotationInfoTree) {
   StringBuffer modifiers = new StringBuffer(annotationTypeDoc.modifiers() + " ");
   writer.addAnnotationTypeSignature(
       Util.replaceText(modifiers.toString(), "interface", "@interface"), annotationInfoTree);
 }
 /**
  * Get Html Hyper Link string.
  *
  * @param link String name of the file.
  * @param where Position of the link in the file. Character '#' is not needed.
  * @param label Tag for the link.
  * @param bold Boolean that sets label to bold.
  * @param stylename String style of text defined in style sheet.
  * @param title String that describes the link's content for accessibility.
  * @param target Target frame.
  * @return String Hyper Link.
  */
 public String getHyperLink(
     String link,
     String where,
     String label,
     boolean bold,
     String stylename,
     String title,
     String target) {
   StringBuffer retlink = new StringBuffer();
   retlink.append("<A HREF=\"");
   retlink.append(link);
   if (where != null && where.length() != 0) {
     retlink.append("#");
     retlink.append(where);
   }
   retlink.append("\"");
   if (title != null && title.length() != 0) {
     retlink.append(" title=\"" + title + "\"");
   }
   if (target != null && target.length() != 0) {
     retlink.append(" target=\"" + target + "\"");
   }
   retlink.append(">");
   if (stylename != null && stylename.length() != 0) {
     retlink.append("<FONT CLASS=\"");
     retlink.append(stylename);
     retlink.append("\">");
   }
   if (bold) {
     retlink.append("<B>");
   }
   retlink.append(label);
   if (bold) {
     retlink.append("</B>");
   }
   if (stylename != null && stylename.length() != 0) {
     retlink.append("</FONT>");
   }
   retlink.append("</A>");
   return retlink.toString();
 }