langtools/test/tools/javac/T6458823/T6458823.java
author sogoel
Thu, 05 Jun 2014 10:57:10 -0700
changeset 24797 850ebd4d80a7
parent 6586 0d40dc0c06cb
child 27319 030080f03e4f
permissions -rw-r--r--
8044072: Group 2: create .out files for OverrideChecks tests in tools/javac dir Reviewed-by: jjg
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
/*
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
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>();
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    58
        StandardJavaFileManager fm = compiler.getStandardFileManager(null, null, null);
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    59
        List<String> options = new ArrayList<String>();
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    60
        options.add("-processor");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    61
        options.add("MyProcessor");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    62
        options.add("-proc:only");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    63
        List<File> files = new ArrayList<File>();
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    64
        files.add(new File(T6458823.class.getResource("TestClass.java").toURI()));
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    65
        final CompilationTask task = compiler.getTask(null, fm, diagColl,
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    66
            options, null, fm.getJavaFileObjectsFromFiles(files));
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    67
        task.call();
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    68
        int diagCount = 0;
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    69
        for (Diagnostic<? extends JavaFileObject> diag : diagColl.getDiagnostics()) {
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    70
            if (diag.getKind() != Diagnostic.Kind.WARNING) {
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    71
                throw new AssertionError("Only warnings expected");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    72
            }
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    73
            System.out.println(diag);
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    74
            if (diag.getPosition() == Diagnostic.NOPOS) {
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    75
                throw new AssertionError("No position info in message");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    76
            }
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    77
            if (diag.getSource() == null) {
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    78
                throw new AssertionError("No source info in message");
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    79
            }
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    80
            diagCount++;
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    81
        }
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    82
        if (diagCount != 2) {
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    83
            throw new AssertionError("unexpected number of warnings: " +
0d40dc0c06cb 6458823: Messager messages on TypeParamterElements to not include position information.
sundar
parents:
diff changeset
    84
                diagCount + ", expected: 2");
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
}