本文整理汇总了Java中com.sun.tools.javac.tree.DocPretty类的典型用法代码示例。如果您正苦于以下问题:Java DocPretty类的具体用法?Java DocPretty怎么用?Java DocPretty使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocPretty类属于com.sun.tools.javac.tree包,在下文中一共展示了DocPretty类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import com.sun.tools.javac.tree.DocPretty; //导入依赖的package包/类
@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: getAttrValue
import com.sun.tools.javac.tree.DocPretty; //导入依赖的package包/类
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();
}
示例3: runElementAndBreakIteratorTests
import com.sun.tools.javac.tree.DocPretty; //导入依赖的package包/类
/**
* 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");
}
}
}
示例4: getExpectText
import com.sun.tools.javac.tree.DocPretty; //导入依赖的package包/类
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);
}