1 /* |
1 /* |
2 * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
42 * Tests that doccomments are available from the Tree API. |
42 * Tests that doccomments are available from the Tree API. |
43 */ |
43 */ |
44 public class T6358786 { |
44 public class T6358786 { |
45 public static void main(String... args) throws IOException { |
45 public static void main(String... args) throws IOException { |
46 JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
46 JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); |
47 StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null); |
47 try (StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null)) { |
48 String srcdir = System.getProperty("test.src"); |
48 String srcdir = System.getProperty("test.src"); |
49 File file = new File(srcdir, args[0]); |
49 File file = new File(srcdir, args[0]); |
50 JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file))); |
50 JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file))); |
51 Elements elements = task.getElements(); |
51 Elements elements = task.getElements(); |
52 for (TypeElement clazz : task.enter(task.parse())) { |
52 for (TypeElement clazz : task.enter(task.parse())) { |
53 String doc = elements.getDocComment(clazz); |
53 String doc = elements.getDocComment(clazz); |
54 if (doc == null) |
54 if (doc == null) |
55 throw new AssertionError(clazz.getSimpleName() + ": no doc comment"); |
55 throw new AssertionError(clazz.getSimpleName() + ": no doc comment"); |
56 System.out.format("%s: %s%n", clazz.getSimpleName(), doc); |
56 System.out.format("%s: %s%n", clazz.getSimpleName(), doc); |
|
57 } |
57 } |
58 } |
58 } |
59 } |
59 } |
60 } |