提交 d485c90d 编写于 作者: J jjg

6866185: Util.getPackageSourcePath should use lastIndexOf not indexOf and related cleanup

Reviewed-by: bpatel
上级 2c2ee4d7
/* /*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -156,7 +156,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -156,7 +156,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
if (index < 0) { if (index < 0) {
return htmlstr; return htmlstr;
} }
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
int previndex = 0; int previndex = 0;
while (true) { while (true) {
// Search for lowercase version of {@docRoot} // Search for lowercase version of {@docRoot}
...@@ -2279,7 +2279,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -2279,7 +2279,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
*/ */
public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags, public String commentTagsToString(Tag holderTag, Doc doc, Tag[] tags,
boolean isFirstSentence) { boolean isFirstSentence) {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
// Array of all possible inline tags for this javadoc run // Array of all possible inline tags for this javadoc run
configuration.tagletManager.checkTags(doc, tags, true); configuration.tagletManager.checkTags(doc, tags, true);
for (int i = 0; i < tags.length; i++) { for (int i = 0; i < tags.length; i++) {
...@@ -2315,7 +2315,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -2315,7 +2315,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
StringTokenizer lines = new StringTokenizer(text, "\r\n", true); StringTokenizer lines = new StringTokenizer(text, "\r\n", true);
StringBuffer textBuff = new StringBuffer(); StringBuffer textBuff = new StringBuffer();
while (lines.hasMoreTokens()) { while (lines.hasMoreTokens()) {
StringBuffer line = new StringBuffer(lines.nextToken()); StringBuilder line = new StringBuilder(lines.nextToken());
Util.replaceTabs(configuration.sourcetab, line); Util.replaceTabs(configuration.sourcetab, line);
textBuff.append(line.toString()); textBuff.append(line.toString());
} }
...@@ -2473,7 +2473,7 @@ public class HtmlDocletWriter extends HtmlDocWriter { ...@@ -2473,7 +2473,7 @@ public class HtmlDocletWriter extends HtmlDocWriter {
return text; return text;
} }
int endindex = startindex + tobe.length(); int endindex = startindex + tobe.length();
StringBuffer replaced = new StringBuffer(); StringBuilder replaced = new StringBuilder();
if (startindex > 0) { if (startindex > 0) {
replaced.append(text.substring(0, startindex)); replaced.append(text.substring(0, startindex));
} }
......
/* /*
* Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,6 @@ import java.util.*; ...@@ -30,7 +30,6 @@ import java.util.*;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import com.sun.tools.doclets.internal.toolkit.*; import com.sun.tools.doclets.internal.toolkit.*;
import com.sun.tools.doclets.internal.toolkit.taglets.*; import com.sun.tools.doclets.internal.toolkit.taglets.*;
import com.sun.tools.doclets.internal.toolkit.util.*;
import com.sun.tools.doclets.formats.html.markup.*; import com.sun.tools.doclets.formats.html.markup.*;
/** /**
...@@ -53,7 +52,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl ...@@ -53,7 +52,7 @@ public class HtmlSerialFieldWriter extends FieldWriterImpl
} }
public List<FieldDoc> members(ClassDoc cd) { public List<FieldDoc> members(ClassDoc cd) {
return Util.asList(cd.serializableFields()); return Arrays.asList(cd.serializableFields());
} }
protected void printTypeLinkNoDimension(Type type) { protected void printTypeLinkNoDimension(Type type) {
......
/* /*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -266,7 +266,7 @@ public class SourceToHTMLConverter { ...@@ -266,7 +266,7 @@ public class SourceToHTMLConverter {
private static void addLine(Content pre, String line, int tabLength, private static void addLine(Content pre, String line, int tabLength,
int currentLineNo) { int currentLineNo) {
if (line != null) { if (line != null) {
StringBuffer lineBuffer = new StringBuffer(Util.escapeHtmlChars(line)); StringBuilder lineBuffer = new StringBuilder(Util.escapeHtmlChars(line));
Util.replaceTabs(tabLength, lineBuffer); Util.replaceTabs(tabLength, lineBuffer);
pre.addContent(new RawHtml(lineBuffer.toString())); pre.addContent(new RawHtml(lineBuffer.toString()));
Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo)); Content anchor = HtmlTree.A_NAME("line." + Integer.toString(currentLineNo));
......
/* /*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -375,8 +375,7 @@ public class SerializedFormBuilder extends AbstractBuilder { ...@@ -375,8 +375,7 @@ public class SerializedFormBuilder extends AbstractBuilder {
*/ */
public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) { public void buildFieldSerializationOverview(ClassDoc classDoc, Content classContentTree) {
if (classDoc.definesSerializableFields()) { if (classDoc.definesSerializableFields()) {
FieldDoc serialPersistentField = FieldDoc serialPersistentField = classDoc.serializableFields()[0];
Util.asList(classDoc.serializableFields()).get(0);
// Check to see if there are inline comments, tags or deprecation // Check to see if there are inline comments, tags or deprecation
// information to be printed. // information to be printed.
if (fieldWriter.shouldPrintOverview(serialPersistentField)) { if (fieldWriter.shouldPrintOverview(serialPersistentField)) {
......
/* /*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -382,7 +382,7 @@ public class Util { ...@@ -382,7 +382,7 @@ public class Util {
out.close(); out.close();
} }
} catch (IOException ie) { } catch (IOException ie) {
ie.printStackTrace(); ie.printStackTrace(System.err);
throw new DocletAbortException(); throw new DocletAbortException();
} }
} }
...@@ -399,12 +399,12 @@ public class Util { ...@@ -399,12 +399,12 @@ public class Util {
String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc); String pkgPath = DirectoryManager.getDirectoryPath(pkgDoc);
String completePath = new SourcePath(configuration.sourcepath). String completePath = new SourcePath(configuration.sourcepath).
getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR; getDirectory(pkgPath) + DirectoryManager.URL_FILE_SEPARATOR;
//Make sure that both paths are using the same seperators. //Make sure that both paths are using the same separators.
completePath = Util.replaceText(completePath, File.separator, completePath = Util.replaceText(completePath, File.separator,
DirectoryManager.URL_FILE_SEPARATOR); DirectoryManager.URL_FILE_SEPARATOR);
pkgPath = Util.replaceText(pkgPath, File.separator, pkgPath = Util.replaceText(pkgPath, File.separator,
DirectoryManager.URL_FILE_SEPARATOR); DirectoryManager.URL_FILE_SEPARATOR);
return completePath.substring(0, completePath.indexOf(pkgPath)); return completePath.substring(0, completePath.lastIndexOf(pkgPath));
} catch (Exception e){ } catch (Exception e){
return ""; return "";
} }
...@@ -536,15 +536,6 @@ public class Util { ...@@ -536,15 +536,6 @@ public class Util {
findAllInterfaceTypes(results, (ClassDoc) type, true, configuration); findAllInterfaceTypes(results, (ClassDoc) type, true, configuration);
} }
public static <T extends ProgramElementDoc> List<T> asList(T[] members) {
List<T> list = new ArrayList<T>();
for (int i = 0; i < members.length; i++) {
list.add(members[i]);
}
return list;
}
/** /**
* Enclose in quotes, used for paths and filenames that contains spaces * Enclose in quotes, used for paths and filenames that contains spaces
*/ */
...@@ -583,14 +574,7 @@ public class Util { ...@@ -583,14 +574,7 @@ public class Util {
if (oldStr == null || newStr == null || oldStr.equals(newStr)) { if (oldStr == null || newStr == null || oldStr.equals(newStr)) {
return originalStr; return originalStr;
} }
StringBuffer result = new StringBuffer(originalStr); return originalStr.replace(oldStr, newStr);
int startIndex = 0;
while ((startIndex = result.indexOf(oldStr, startIndex)) != -1) {
result = result.replace(startIndex, startIndex + oldStr.length(),
newStr);
startIndex += newStr.length();
}
return result.toString();
} }
/** /**
...@@ -833,19 +817,17 @@ public class Util { ...@@ -833,19 +817,17 @@ public class Util {
* @param tabLength the length of each tab. * @param tabLength the length of each tab.
* @param s the String to scan. * @param s the String to scan.
*/ */
public static void replaceTabs(int tabLength, StringBuffer s) { public static void replaceTabs(int tabLength, StringBuilder s) {
int index, col; if (whitespace == null || whitespace.length() < tabLength)
StringBuffer whitespace; whitespace = String.format("%" + tabLength + "s", " ");
while ((index = s.indexOf("\t")) != -1) { int index = 0;
whitespace = new StringBuffer(); while ((index = s.indexOf("\t", index)) != -1) {
col = index; int spaceCount = tabLength - index % tabLength;
do { s.replace(index, index+1, whitespace.substring(0, spaceCount));
whitespace.append(" "); index += spaceCount;
col++;
} while ((col%tabLength) != 0);
s.replace(index, index+1, whitespace.toString());
} }
} }
private static String whitespace;
/** /**
* The documentation for values() and valueOf() in Enums are set by the * The documentation for values() and valueOf() in Enums are set by the
......
/* /*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -92,8 +92,9 @@ public class AnnotationDescImpl implements AnnotationDesc { ...@@ -92,8 +92,9 @@ public class AnnotationDescImpl implements AnnotationDesc {
* @com.example.foo * @com.example.foo
* Omit parens for marker annotations, and omit "value=" when allowed. * Omit parens for marker annotations, and omit "value=" when allowed.
*/ */
@Override
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer("@"); StringBuilder sb = new StringBuilder("@");
sb.append(annotation.type.tsym); sb.append(annotation.type.tsym);
ElementValuePair vals[] = elementValues(); ElementValuePair vals[] = elementValues();
...@@ -153,6 +154,7 @@ public class AnnotationDescImpl implements AnnotationDesc { ...@@ -153,6 +154,7 @@ public class AnnotationDescImpl implements AnnotationDesc {
* Returns a string representation of this pair * Returns a string representation of this pair
* of the form "name=value". * of the form "name=value".
*/ */
@Override
public String toString() { public String toString() {
return meth.name + "=" + value(); return meth.name + "=" + value();
} }
......
/* /*
* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,6 @@ import com.sun.javadoc.*; ...@@ -30,7 +30,6 @@ import com.sun.javadoc.*;
import com.sun.tools.javac.code.Attribute; import com.sun.tools.javac.code.Attribute;
import com.sun.tools.javac.code.Symbol.*; import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.TypeTags; import com.sun.tools.javac.code.TypeTags;
...@@ -114,6 +113,7 @@ public class AnnotationValueImpl implements AnnotationValue { ...@@ -114,6 +113,7 @@ public class AnnotationValueImpl implements AnnotationValue {
* @return the text of a Java language annotation value expression * @return the text of a Java language annotation value expression
* whose value is the value of this annotation type element. * whose value is the value of this annotation type element.
*/ */
@Override
public String toString() { public String toString() {
ToStringVisitor tv = new ToStringVisitor(); ToStringVisitor tv = new ToStringVisitor();
attr.accept(tv); attr.accept(tv);
...@@ -121,8 +121,9 @@ public class AnnotationValueImpl implements AnnotationValue { ...@@ -121,8 +121,9 @@ public class AnnotationValueImpl implements AnnotationValue {
} }
private class ToStringVisitor implements Attribute.Visitor { private class ToStringVisitor implements Attribute.Visitor {
private final StringBuffer sb = new StringBuffer(); private final StringBuilder sb = new StringBuilder();
@Override
public String toString() { public String toString() {
return sb.toString(); return sb.toString();
} }
......
/* /*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -64,7 +64,6 @@ import com.sun.tools.javac.util.Name; ...@@ -64,7 +64,6 @@ import com.sun.tools.javac.util.Name;
import com.sun.tools.javac.util.Names; import com.sun.tools.javac.util.Names;
import com.sun.tools.javac.util.Position; import com.sun.tools.javac.util.Position;
import static com.sun.tools.javac.code.Flags.*;
import static com.sun.tools.javac.code.Kinds.*; import static com.sun.tools.javac.code.Kinds.*;
/** /**
...@@ -147,6 +146,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -147,6 +146,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is a class, not an interface. * Return true if this is a class, not an interface.
*/ */
@Override
public boolean isClass() { public boolean isClass() {
return !Modifier.isInterface(getModifiers()); return !Modifier.isInterface(getModifiers());
} }
...@@ -155,6 +155,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -155,6 +155,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is a ordinary class, * Return true if this is a ordinary class,
* not an enumeration, exception, an error, or an interface. * not an enumeration, exception, an error, or an interface.
*/ */
@Override
public boolean isOrdinaryClass() { public boolean isOrdinaryClass() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
...@@ -172,6 +173,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -172,6 +173,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is an enumeration. * Return true if this is an enumeration.
* (For legacy doclets, return false.) * (For legacy doclets, return false.)
*/ */
@Override
public boolean isEnum() { public boolean isEnum() {
return (getFlags() & Flags.ENUM) != 0 return (getFlags() & Flags.ENUM) != 0
&& &&
...@@ -182,6 +184,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -182,6 +184,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return true if this is an interface, but not an annotation type. * Return true if this is an interface, but not an annotation type.
* Overridden by AnnotationTypeDocImpl. * Overridden by AnnotationTypeDocImpl.
*/ */
@Override
public boolean isInterface() { public boolean isInterface() {
return Modifier.isInterface(getModifiers()); return Modifier.isInterface(getModifiers());
} }
...@@ -189,6 +192,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -189,6 +192,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is an exception class * Return true if this is an exception class
*/ */
@Override
public boolean isException() { public boolean isException() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
...@@ -204,6 +208,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -204,6 +208,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return true if this is an error class * Return true if this is an error class
*/ */
@Override
public boolean isError() { public boolean isError() {
if (isEnum() || isInterface() || isAnnotationType()) { if (isEnum() || isInterface() || isAnnotationType()) {
return false; return false;
...@@ -275,6 +280,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -275,6 +280,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
/** /**
* Return the package that this class is contained in. * Return the package that this class is contained in.
*/ */
@Override
public PackageDoc containingPackage() { public PackageDoc containingPackage() {
PackageDocImpl p = env.getPackageDoc(tsym.packge()); PackageDocImpl p = env.getPackageDoc(tsym.packge());
if (p.setDocPath == false) { if (p.setDocPath == false) {
...@@ -374,6 +380,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -374,6 +380,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the qualified name and any type parameters. * Return the qualified name and any type parameters.
* Each parameter is a type variable with optional bounds. * Each parameter is a type variable with optional bounds.
*/ */
@Override
public String toString() { public String toString() {
return classToString(env, tsym, true); return classToString(env, tsym, true);
} }
...@@ -401,7 +408,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -401,7 +408,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* qualified by their enclosing class(es) only. * qualified by their enclosing class(es) only.
*/ */
static String classToString(DocEnv env, ClassSymbol c, boolean full) { static String classToString(DocEnv env, ClassSymbol c, boolean full) {
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
if (!c.isInner()) { // if c is not an inner class if (!c.isInner()) { // if c is not an inner class
s.append(getClassName(c, full)); s.append(getClassName(c, full));
} else { } else {
...@@ -449,10 +456,12 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -449,10 +456,12 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the modifier string for this class. If it's an interface * Return the modifier string for this class. If it's an interface
* exclude 'abstract' keyword from the modifier string * exclude 'abstract' keyword from the modifier string
*/ */
@Override
public String modifiers() { public String modifiers() {
return Modifier.toString(modifierSpecifier()); return Modifier.toString(modifierSpecifier());
} }
@Override
public int modifierSpecifier() { public int modifierSpecifier() {
int modifiers = getModifiers(); int modifiers = getModifiers();
return (isInterface() || isAnnotationType()) return (isInterface() || isAnnotationType())
...@@ -1285,6 +1294,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc { ...@@ -1285,6 +1294,7 @@ public class ClassDocImpl extends ProgramElementDocImpl implements ClassDoc {
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (tsym.sourcefile == null) return null; if (tsym.sourcefile == null) return null;
return SourcePositionImpl.make(tsym.sourcefile, return SourcePositionImpl.make(tsym.sourcefile,
......
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -226,7 +226,7 @@ public abstract class ExecutableMemberDocImpl ...@@ -226,7 +226,7 @@ public abstract class ExecutableMemberDocImpl
} }
private String makeSignature(boolean full) { private String makeSignature(boolean full) {
StringBuffer result = new StringBuffer(); StringBuilder result = new StringBuilder();
result.append("("); result.append("(");
for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) { for (List<Type> types = sym.type.getParameterTypes(); types.nonEmpty(); ) {
Type t = types.head; Type t = types.head;
...@@ -251,6 +251,7 @@ public abstract class ExecutableMemberDocImpl ...@@ -251,6 +251,7 @@ public abstract class ExecutableMemberDocImpl
/** /**
* Generate a key for sorting. * Generate a key for sorting.
*/ */
@Override
CollationKey generateKey() { CollationKey generateKey() {
String k = name() + flatSignature() + typeParametersString(); String k = name() + flatSignature() + typeParametersString();
// ',' and '&' are between '$' and 'a': normalize to spaces. // ',' and '&' are between '$' and 'a': normalize to spaces.
...@@ -263,6 +264,7 @@ public abstract class ExecutableMemberDocImpl ...@@ -263,6 +264,7 @@ public abstract class ExecutableMemberDocImpl
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (sym.enclClass().sourcefile == null) return null; if (sym.enclClass().sourcefile == null) return null;
return SourcePositionImpl.make(sym.enclClass().sourcefile, return SourcePositionImpl.make(sym.enclClass().sourcefile,
......
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -142,7 +142,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -142,7 +142,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : ""); return v + (suffix == 'f' || suffix == 'F' ? "" + suffix : "");
} }
private static String sourceForm(char c) { private static String sourceForm(char c) {
StringBuffer buf = new StringBuffer(8); StringBuilder buf = new StringBuilder(8);
buf.append('\''); buf.append('\'');
sourceChar(c, buf); sourceChar(c, buf);
buf.append('\''); buf.append('\'');
...@@ -152,7 +152,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -152,7 +152,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return "0x" + Integer.toString(c & 0xff, 16); return "0x" + Integer.toString(c & 0xff, 16);
} }
private static String sourceForm(String s) { private static String sourceForm(String s) {
StringBuffer buf = new StringBuffer(s.length() + 5); StringBuilder buf = new StringBuilder(s.length() + 5);
buf.append('\"'); buf.append('\"');
for (int i=0; i<s.length(); i++) { for (int i=0; i<s.length(); i++) {
char c = s.charAt(i); char c = s.charAt(i);
...@@ -161,7 +161,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -161,7 +161,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
buf.append('\"'); buf.append('\"');
return buf.toString(); return buf.toString();
} }
private static void sourceChar(char c, StringBuffer buf) { private static void sourceChar(char c, StringBuilder buf) {
switch (c) { switch (c) {
case '\b': buf.append("\\b"); return; case '\b': buf.append("\\b"); return;
case '\t': buf.append("\\t"); return; case '\t': buf.append("\\t"); return;
...@@ -179,7 +179,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -179,7 +179,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
return; return;
} }
} }
private static void unicodeEscape(char c, StringBuffer buf) { private static void unicodeEscape(char c, StringBuilder buf) {
final String chars = "0123456789abcdef"; final String chars = "0123456789abcdef";
buf.append("\\u"); buf.append("\\u");
buf.append(chars.charAt(15 & (c>>12))); buf.append(chars.charAt(15 & (c>>12)));
...@@ -201,6 +201,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -201,6 +201,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
/** /**
* Is this Doc item a field (but not an enum constant? * Is this Doc item a field (but not an enum constant?
*/ */
@Override
public boolean isField() { public boolean isField() {
return !isEnumConstant(); return !isEnumConstant();
} }
...@@ -209,6 +210,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -209,6 +210,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
* Is this Doc item an enum constant? * Is this Doc item an enum constant?
* (For legacy doclets, return false.) * (For legacy doclets, return false.)
*/ */
@Override
public boolean isEnumConstant() { public boolean isEnumConstant() {
return (getFlags() & Flags.ENUM) != 0 && return (getFlags() & Flags.ENUM) != 0 &&
!env.legacyDoclet; !env.legacyDoclet;
...@@ -257,6 +259,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc { ...@@ -257,6 +259,7 @@ public class FieldDocImpl extends MemberDocImpl implements FieldDoc {
* Return the source position of the entity, or null if * Return the source position of the entity, or null if
* no position is available. * no position is available.
*/ */
@Override
public SourcePosition position() { public SourcePosition position() {
if (sym.enclClass().sourcefile == null) return null; if (sym.enclClass().sourcefile == null) return null;
return SourcePositionImpl.make(sym.enclClass().sourcefile, return SourcePositionImpl.make(sym.enclClass().sourcefile,
......
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,15 +25,11 @@ ...@@ -25,15 +25,11 @@
package com.sun.tools.javadoc; package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
...@@ -55,6 +51,7 @@ public class ParameterizedTypeImpl ...@@ -55,6 +51,7 @@ public class ParameterizedTypeImpl
/** /**
* Return the generic class or interface that declared this type. * Return the generic class or interface that declared this type.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)type.tsym); return env.getClassDoc((ClassSymbol)type.tsym);
} }
...@@ -111,14 +108,17 @@ public class ParameterizedTypeImpl ...@@ -111,14 +108,17 @@ public class ParameterizedTypeImpl
// Asking for the "name" of a parameterized type doesn't exactly make // Asking for the "name" of a parameterized type doesn't exactly make
// sense. It's a type expression. Return the name of its generic // sense. It's a type expression. Return the name of its generic
// type. // type.
@Override
public String typeName() { public String typeName() {
return TypeMaker.getTypeName(type, false); return TypeMaker.getTypeName(type, false);
} }
@Override
public ParameterizedType asParameterizedType() { public ParameterizedType asParameterizedType() {
return this; return this;
} }
@Override
public String toString() { public String toString() {
return parameterizedTypeToString(env, (ClassType)type, true); return parameterizedTypeToString(env, (ClassType)type, true);
} }
...@@ -128,7 +128,7 @@ public class ParameterizedTypeImpl ...@@ -128,7 +128,7 @@ public class ParameterizedTypeImpl
if (env.legacyDoclet) { if (env.legacyDoclet) {
return TypeMaker.getTypeName(cl, full); return TypeMaker.getTypeName(cl, full);
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
if (cl.getEnclosingType().tag != CLASS) { // if not an inner class... if (cl.getEnclosingType().tag != CLASS) { // if not an inner class...
s.append(TypeMaker.getTypeName(cl, full)); s.append(TypeMaker.getTypeName(cl, full));
} else { } else {
......
/* /*
* Copyright (c) 1997, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -358,14 +358,14 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters { ...@@ -358,14 +358,14 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
String parameters; String parameters;
StringBuffer typeId; StringBuilder typeId;
ListBuffer<String> paramList; ListBuffer<String> paramList;
ParameterParseMachine(String parameters) { ParameterParseMachine(String parameters) {
this.parameters = parameters; this.parameters = parameters;
this.paramList = new ListBuffer<String>(); this.paramList = new ListBuffer<String>();
typeId = new StringBuffer(); typeId = new StringBuilder();
} }
public String[] parseParameters() { public String[] parseParameters() {
...@@ -464,6 +464,7 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters { ...@@ -464,6 +464,7 @@ class SeeTagImpl extends TagImpl implements SeeTag, LayoutCharacters {
/** /**
* Return the kind of this tag. * Return the kind of this tag.
*/ */
@Override
public String kind() { public String kind() {
return "@see"; return "@see";
} }
......
/* /*
* Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,15 +27,12 @@ package com.sun.tools.javadoc; ...@@ -27,15 +27,12 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.code.Type.ClassType; import com.sun.tools.javac.code.Type.ClassType;
import com.sun.tools.javac.code.Type.TypeVar; import com.sun.tools.javac.code.Type.TypeVar;
import com.sun.tools.javac.code.Type.ArrayType; import com.sun.tools.javac.code.Type.ArrayType;
import com.sun.tools.javac.code.Types;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
import static com.sun.tools.javac.code.TypeTags.*; import static com.sun.tools.javac.code.TypeTags.*;
...@@ -109,12 +106,13 @@ public class TypeMaker { ...@@ -109,12 +106,13 @@ public class TypeMaker {
public static String getTypeName(Type t, boolean full) { public static String getTypeName(Type t, boolean full) {
switch (t.tag) { switch (t.tag) {
case ARRAY: case ARRAY:
StringBuffer dimension = new StringBuffer(); StringBuilder s = new StringBuilder();
while (t.tag == ARRAY) { while (t.tag == ARRAY) {
dimension = dimension.append("[]"); s.append("[]");
t = ((ArrayType)t).elemtype; t = ((ArrayType)t).elemtype;
} }
return getTypeName(t, full) + dimension; s.insert(0, getTypeName(t, full));
return s.toString();
case CLASS: case CLASS:
return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full); return ClassDocImpl.getClassName((ClassSymbol)t.tsym, full);
default: default:
...@@ -130,12 +128,13 @@ public class TypeMaker { ...@@ -130,12 +128,13 @@ public class TypeMaker {
static String getTypeString(DocEnv env, Type t, boolean full) { static String getTypeString(DocEnv env, Type t, boolean full) {
switch (t.tag) { switch (t.tag) {
case ARRAY: case ARRAY:
StringBuffer dimension = new StringBuffer(); StringBuilder s = new StringBuilder();
while (t.tag == ARRAY) { while (t.tag == ARRAY) {
dimension = dimension.append("[]"); s.append("[]");
t = env.types.elemtype(t); t = env.types.elemtype(t);
} }
return getTypeString(env, t, full) + dimension; s.insert(0, getTypeString(env, t, full));
return s.toString();
case CLASS: case CLASS:
return ParameterizedTypeImpl. return ParameterizedTypeImpl.
parameterizedTypeToString(env, (ClassType)t, full); parameterizedTypeToString(env, (ClassType)t, full);
...@@ -157,7 +156,7 @@ public class TypeMaker { ...@@ -157,7 +156,7 @@ public class TypeMaker {
if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) { if (env.legacyDoclet || sym.type.getTypeArguments().isEmpty()) {
return ""; return "";
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for (Type t : sym.type.getTypeArguments()) { for (Type t : sym.type.getTypeArguments()) {
s.append(s.length() == 0 ? "<" : ", "); s.append(s.length() == 0 ? "<" : ", ");
s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full)); s.append(TypeVariableImpl.typeVarToString(env, (TypeVar)t, full));
...@@ -175,7 +174,7 @@ public class TypeMaker { ...@@ -175,7 +174,7 @@ public class TypeMaker {
if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) { if (env.legacyDoclet || cl.getTypeArguments().isEmpty()) {
return ""; return "";
} }
StringBuffer s = new StringBuffer(); StringBuilder s = new StringBuilder();
for (Type t : cl.getTypeArguments()) { for (Type t : cl.getTypeArguments()) {
s.append(s.length() == 0 ? "<" : ", "); s.append(s.length() == 0 ? "<" : ", ");
s.append(getTypeString(env, t, full)); s.append(getTypeString(env, t, full));
...@@ -213,9 +212,9 @@ public class TypeMaker { ...@@ -213,9 +212,9 @@ public class TypeMaker {
* For example, a two dimensional array of String returns '[][]'. * For example, a two dimensional array of String returns '[][]'.
*/ */
public String dimension() { public String dimension() {
StringBuffer dimension = new StringBuffer(); StringBuilder dimension = new StringBuilder();
for (Type t = arrayType; t.tag == ARRAY; t = env.types.elemtype(t)) { for (Type t = arrayType; t.tag == ARRAY; t = env.types.elemtype(t)) {
dimension = dimension.append("[]"); dimension.append("[]");
} }
return dimension.toString(); return dimension.toString();
} }
...@@ -304,6 +303,7 @@ public class TypeMaker { ...@@ -304,6 +303,7 @@ public class TypeMaker {
* *
* @return name of type including any dimension information. * @return name of type including any dimension information.
*/ */
@Override
public String toString() { public String toString() {
return qualifiedTypeName() + dimension(); return qualifiedTypeName() + dimension();
} }
......
/* /*
* Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -78,14 +78,17 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable { ...@@ -78,14 +78,17 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
/** /**
* Return the ClassDoc of the erasure of this type variable. * Return the ClassDoc of the erasure of this type variable.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym); return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
} }
@Override
public TypeVariable asTypeVariable() { public TypeVariable asTypeVariable() {
return this; return this;
} }
@Override
public String toString() { public String toString() {
return typeVarToString(env, (TypeVar)type, true); return typeVarToString(env, (TypeVar)type, true);
} }
...@@ -96,7 +99,7 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable { ...@@ -96,7 +99,7 @@ public class TypeVariableImpl extends AbstractTypeImpl implements TypeVariable {
* "extends" clause. Class names are qualified if "full" is true. * "extends" clause. Class names are qualified if "full" is true.
*/ */
static String typeVarToString(DocEnv env, TypeVar v, boolean full) { static String typeVarToString(DocEnv env, TypeVar v, boolean full) {
StringBuffer s = new StringBuffer(v.toString()); StringBuilder s = new StringBuilder(v.toString());
List<Type> bounds = getBounds(v, env); List<Type> bounds = getBounds(v, env);
if (bounds.nonEmpty()) { if (bounds.nonEmpty()) {
boolean first = true; boolean first = true;
......
/* /*
* Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,8 +28,6 @@ package com.sun.tools.javadoc; ...@@ -28,8 +28,6 @@ package com.sun.tools.javadoc;
import com.sun.javadoc.*; import com.sun.javadoc.*;
import static com.sun.javadoc.LanguageVersion.*;
import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.ClassSymbol;
import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Type;
import com.sun.tools.javac.util.List; import com.sun.tools.javac.util.List;
...@@ -69,18 +67,24 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType { ...@@ -69,18 +67,24 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
/** /**
* Return the ClassDoc of the erasure of this wildcard type. * Return the ClassDoc of the erasure of this wildcard type.
*/ */
@Override
public ClassDoc asClassDoc() { public ClassDoc asClassDoc() {
return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym); return env.getClassDoc((ClassSymbol)env.types.erasure(type).tsym);
} }
@Override
public WildcardType asWildcardType() { public WildcardType asWildcardType() {
return this; return this;
} }
@Override
public String typeName() { return "?"; } public String typeName() { return "?"; }
@Override
public String qualifiedTypeName() { return "?"; } public String qualifiedTypeName() { return "?"; }
@Override
public String simpleTypeName() { return "?"; } public String simpleTypeName() { return "?"; }
@Override
public String toString() { public String toString() {
return wildcardTypeToString(env, (Type.WildcardType)type, true); return wildcardTypeToString(env, (Type.WildcardType)type, true);
} }
...@@ -96,7 +100,7 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType { ...@@ -96,7 +100,7 @@ public class WildcardTypeImpl extends AbstractTypeImpl implements WildcardType {
if (env.legacyDoclet) { if (env.legacyDoclet) {
return TypeMaker.getTypeName(env.types.erasure(wildThing), full); return TypeMaker.getTypeName(env.types.erasure(wildThing), full);
} }
StringBuffer s = new StringBuffer("?"); StringBuilder s = new StringBuilder("?");
List<Type> bounds = getExtendsBounds(wildThing); List<Type> bounds = getExtendsBounds(wildThing);
if (bounds.nonEmpty()) { if (bounds.nonEmpty()) {
s.append(" extends "); s.append(" extends ");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册