test/tools/javac/T6458823/T6458823.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

     1 /*
     2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     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
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6458823
    27  * @summary Messager messages on TypeParamterElements to not include position information.
    28  *
    29  * @compile MyProcessor.java T6458823.java
    30  * @run main T6458823
    31  */
    33 import java.io.File;
    34 import java.io.IOException;
    35 import java.io.Writer;
    36 import java.net.URISyntaxException;
    37 import java.util.ArrayList;
    38 import java.util.HashMap;
    39 import java.util.List;
    40 import java.util.Map;
    41 import java.util.Set;
    42 import javax.tools.Diagnostic;
    43 import javax.tools.DiagnosticCollector;
    44 import javax.tools.JavaCompiler;
    45 import javax.tools.JavaCompiler.CompilationTask;
    46 import javax.tools.JavaFileObject;
    47 import javax.tools.StandardJavaFileManager;
    48 import javax.tools.ToolProvider;
    50 public class T6458823 {
    51     public static void main(String[] args) throws Exception {
    52         JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    53         if (compiler == null) {
    54             throw new RuntimeException("can't get javax.tools.JavaCompiler!");
    55         }
    56         DiagnosticCollector<JavaFileObject> diagColl =
    57             new DiagnosticCollector<JavaFileObject>();
    58         StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
    59         List<String> options = new ArrayList<String>();
    60         options.add("-processor");
    61         options.add("MyProcessor");
    62         options.add("-proc:only");
    63         List<File> files = new ArrayList<File>();
    64         files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
    65         final CompilationTask task = compiler.getTask(null, fm, diagColl,
    66             options, null, fm.getJavaFileObjectsFromFiles(files));
    67         task.call();
    68         int diagCount = 0;
    69         for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
    70             if (diag.getKind() != Diagnostic.Kind.WARNING) {
    71                 throw new AssertionError("Only warnings expected");
    72             }
    73             System.out.println(diag);
    74             if (diag.getPosition() == Diagnostic.NOPOS) {
    75                 throw new AssertionError("No position info in message");
    76             }
    77             if (diag.getSource() == null) {
    78                 throw new AssertionError("No source info in message");
    79             }
    80             diagCount++;
    81         }
    82         if (diagCount != 2) {
    83             throw new AssertionError("unexpected number of warnings: " +
    84                 diagCount + ", expected: 2");
    85         }
    86     }
    87 }

mercurial