Java源码示例:com.sun.tools.javac.tree.DocPretty
示例1
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例2
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例3
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例4
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例5
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例6
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例7
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例8
@Override
void check(TreePath path, Name name) throws Exception {
String raw = trees.getDocComment(path);
String normRaw = normalize(raw);
StringWriter out = new StringWriter();
DocPretty dp = new DocPretty(out);
dp.print(trees.getDocCommentTree(path));
String pretty = out.toString();
if (!pretty.equals(normRaw)) {
error("mismatch");
System.err.println("*** expected:");
System.err.println(normRaw.replace(" ", "_"));
System.err.println("*** found:");
System.err.println(pretty.replace(" ", "_"));
// throw new Error();
}
}
示例9
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例10
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例11
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例12
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例13
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例14
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例15
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例16
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例17
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例18
/**
* Tests getting a DocCommentTree from an element, as well
* as test if break iterator setter/getter works correctly.
*
* @param javaFileName a test file to be processed
* @param expected the expected output
* @throws java.io.IOException
*/
public void runElementAndBreakIteratorTests(String javaFileName, String expected) throws IOException {
List<File> javaFiles = new ArrayList<>();
javaFiles.add(new File(testSrc, javaFileName));
List<File> dirs = new ArrayList<>();
dirs.add(new File(testSrc));
try (StandardJavaFileManager fm = javac.getStandardFileManager(null, null, null)) {
fm.setLocation(javax.tools.StandardLocation.SOURCE_PATH, dirs);
Iterable<? extends JavaFileObject> fos = fm.getJavaFileObjectsFromFiles(javaFiles);
final JavacTask t = javac.getTask(null, fm, null, null, null, fos);
final DocTrees trees = DocTrees.instance(t);
Iterable<? extends Element> elements = t.analyze();
Element klass = elements.iterator().next();
DocCommentTree dcTree = trees.getDocCommentTree(klass);
List<? extends DocTree> firstSentence = dcTree.getFirstSentence();
StringWriter sw = new StringWriter();
DocPretty pretty = new DocPretty(sw);
pretty.print(firstSentence);
check("getDocCommentTree(Element)", expected, sw.toString());
BreakIterator bi = BreakIterator.getSentenceInstance(Locale.FRENCH);
trees.setBreakIterator(bi);
BreakIterator nbi = trees.getBreakIterator();
if (bi.equals(nbi)) {
pass++;
check("getDocCommentTree(Element) with BreakIterator", expected, sw.toString());
} else {
fail++;
System.err.println("BreakIterators don't match");
}
}
}
示例19
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例20
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例21
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例22
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例23
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}
示例24
private String getAttrValue(AttributeTree tree) {
if (tree.getValue() == null)
return null;
StringWriter sw = new StringWriter();
try {
new DocPretty(sw).print(tree.getValue());
} catch (IOException e) {
// cannot happen
}
// ignore potential use of entities for now
return sw.toString();
}
示例25
String getExpectText(DocTree t) {
StringWriter sw = new StringWriter();
DocPretty p = new DocPretty(sw);
try { p.print(t); } catch (IOException never) { }
String s = sw.toString();
if (s.length() <= 1)
return s;
int ws = s.replaceAll("\\s+", " ").indexOf(" ");
if (ws != -1) s = s.substring(0, ws);
return (s.length() < 5) ? s : s.substring(0, 5);
}