test/tools/javac/processing/6430209/b6341534.java

Mon, 30 Aug 2010 18:03:35 -0700

author
jjg
date
Mon, 30 Aug 2010 18:03:35 -0700
changeset 664
4124840b35fe
parent 554
9d9f26857129
child 699
d2aaaec153e8
permissions
-rw-r--r--

6403465: javac should defer diagnostics until it can be determined they are persistent
Reviewed-by: mcimadamore, darcy

     1 /*
     2  * Copyright (c) 2006, 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 import javax.annotation.processing.*;
    25 import javax.lang.model.SourceVersion;
    26 import javax.lang.model.element.*;
    27 import javax.lang.model.util.*;
    28 import static javax.lang.model.util.ElementFilter.*;
    29 import static javax.tools.Diagnostic.Kind.*;
    30 import java.util.*;
    31 import java.util.Set;
    33 @SupportedAnnotationTypes({"*"})
    34 public class b6341534 extends AbstractProcessor {
    35     static int r = 0;
    36     static Elements E = null;
    37     static Messager msgr = null;
    38     public void init(ProcessingEnvironment penv)  {
    39         processingEnv = penv;
    40         msgr = penv.getMessager();
    41         E = penv.getElementUtils();
    42     }
    43     //Create directory 'dir1' and a test class in dir1
    44     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
    45     {
    46         if(!renv.errorRaised() &&  !renv.processingOver()){
    47             r++;
    48             for( TypeElement t : typesIn(renv.getRootElements()) )
    49                 System.out.println("Round"+r+ ": " + t.toString());
    51             try {
    52                 PackageElement PE = E.getPackageElement("dir1");
    53                 List<? extends Element> LEE = PE.getEnclosedElements();    /* <=This line elicits the error message.  */
    54                 for(Element e : LEE)
    55                     System.out.println("found " + e.toString() + " in dir1.");
    56             }
    57             catch(NullPointerException npe) {
    58                 msgr.printMessage(ERROR,npe.toString());
    59                 //npe.printStackTrace();
    60                 return false;
    61             }
    62         }
    63         // on round 1, expect errorRaised == false && processingOver == false
    64         // on round 2, expect errorRaised == true && processingOver == true
    65         if( renv.errorRaised() != renv.processingOver()) {
    66             msgr.printMessage(ERROR, "FAILED");
    67         }
    68         return true;
    69     }
    71     @Override
    72     public SourceVersion getSupportedSourceVersion() {
    73         return SourceVersion.latest();
    74     }
    75 }

mercurial