langtools/test/tools/javac/processing/TestMultipleErrors.java
changeset 28455 41245007c074
child 30730 d3ce7619db2c
equal deleted inserted replaced
28454:63c31d7de8f6 28455:41245007c074
       
     1 /*
       
     2  * Copyright (c) 2014, 2015, 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  */
       
    23 
       
    24 
       
    25 /*
       
    26  * @test
       
    27  * @bug 8066843
       
    28  * @summary Annotation processors should be able to print multiple errors at the same location.
       
    29  * @library /tools/javac/lib
       
    30  * @build JavacTestingAbstractProcessor TestMultipleErrors
       
    31  * @compile/fail/ref=TestMultipleErrors.out -XDrawDiagnostics -processor TestMultipleErrors TestMultipleErrors.java
       
    32  */
       
    33 
       
    34 import java.util.*;
       
    35 import javax.annotation.processing.*;
       
    36 import javax.lang.model.element.*;
       
    37 import javax.tools.Diagnostic.Kind;
       
    38 import com.sun.source.util.TreePath;
       
    39 import com.sun.source.util.Trees;
       
    40 
       
    41 public class TestMultipleErrors extends JavacTestingAbstractProcessor {
       
    42     @Override
       
    43     public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
       
    44         for (Element root : roundEnv.getRootElements()) {
       
    45             processingEnv.getMessager().printMessage(Kind.ERROR, "error1", root);
       
    46             processingEnv.getMessager().printMessage(Kind.ERROR, "error2", root);
       
    47 
       
    48             Trees trees = Trees.instance(processingEnv);
       
    49             TreePath path = trees.getPath(root);
       
    50 
       
    51             trees.printMessage(Kind.ERROR, "error3", path.getLeaf(), path.getCompilationUnit());
       
    52             trees.printMessage(Kind.ERROR, "error4", path.getLeaf(), path.getCompilationUnit());
       
    53         }
       
    54         return true;
       
    55     }
       
    56 }