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