T6358786.java revision 49:b9bcea8bbe24
1141296Sdas/*
2141296Sdas * Copyright 2005-2006 Sun Microsystems, Inc.  All Rights Reserved.
32116Sjkh * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
42116Sjkh *
52116Sjkh * This code is free software; you can redistribute it and/or modify it
62116Sjkh * under the terms of the GNU General Public License version 2 only, as
7141296Sdas * published by the Free Software Foundation.
82116Sjkh *
9141296Sdas * This code is distributed in the hope that it will be useful, but WITHOUT
102116Sjkh * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
112116Sjkh * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
122116Sjkh * version 2 for more details (a copy is included in the LICENSE file that
132116Sjkh * accompanied this code).
14176207Sbde *
15176207Sbde * You should have received a copy of the GNU General Public License version
162116Sjkh * 2 along with this work; if not, write to the Free Software Foundation,
172116Sjkh * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18141296Sdas *
19141296Sdas * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20141296Sdas * CA 95054 USA or visit www.sun.com if you need additional information or
212116Sjkh * have any questions.
22141296Sdas */
232116Sjkh
242116Sjkh/*
252116Sjkh * @test
26177765Sdas * @bug     6358786
27177765Sdas * @summary Doccomments are not returned from Tree API
282116Sjkh * @author  Peter von der Ah\u00e9
292116Sjkh * @run main T6358786 T6358786.java
302116Sjkh */
312116Sjkh
322116Sjkhimport com.sun.tools.javac.api.JavacTaskImpl;
332116Sjkhimport com.sun.tools.javac.file.JavacFileManager;
3497413Salfredimport java.util.Arrays;
35117912Speter
362116Sjkhimport javax.lang.model.util.Elements;
372116Sjkhimport java.io.*;
382116Sjkhimport javax.lang.model.element.TypeElement;
392116Sjkhimport javax.tools.*;
402116Sjkh
412116Sjkh/**
422116Sjkh * Tests that doccomments are available from the Tree API.
432116Sjkh */
442116Sjkhpublic class T6358786 {
452116Sjkh    public static void main(String... args) throws IOException {
462116Sjkh        JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
472116Sjkh        StandardJavaFileManager fm = tool.getStandardFileManager(null, null, null);
482116Sjkh        String srcdir = System.getProperty("test.src");
492116Sjkh        File file = new File(srcdir, args[0]);
502116Sjkh        JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, fm, null, null, null, fm.getJavaFileObjectsFromFiles(Arrays.asList(file)));
512116Sjkh        Elements elements = task.getElements();
52176207Sbde        for (TypeElement clazz : task.enter(task.parse())) {
532116Sjkh            String doc = elements.getDocComment(clazz);
542116Sjkh            if (doc == null)
552116Sjkh                throw new AssertionError(clazz.getSimpleName() + ": no doc comment");
562116Sjkh            System.out.format("%s: %s%n", clazz.getSimpleName(), doc);
572116Sjkh        }
582116Sjkh    }
592116Sjkh}
602116Sjkh