langtools/test/tools/javac/processing/6430209/b6341534.java
changeset 6720 f16f91662ad8
parent 6582 c7a4fb5a2f86
child 8846 39157538c506
equal deleted inserted replaced
6719:1ce993f87850 6720:f16f91662ad8
     1 /*
     1 /*
     2  * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    28 import static javax.lang.model.util.ElementFilter.*;
    28 import static javax.lang.model.util.ElementFilter.*;
    29 import static javax.tools.Diagnostic.Kind.*;
    29 import static javax.tools.Diagnostic.Kind.*;
    30 import java.util.*;
    30 import java.util.*;
    31 import java.util.Set;
    31 import java.util.Set;
    32 
    32 
    33 @SupportedAnnotationTypes({"*"})
    33 public class b6341534 extends JavacTestingAbstractProcessor {
    34 public class b6341534 extends AbstractProcessor {
       
    35     static int r = 0;
    34     static int r = 0;
    36     static Elements E = null;
    35 
    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
    36     //Create directory 'dir1' and a test class in dir1
    44     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
    37     public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv)
    45     {
    38     {
    46         if(!renv.errorRaised() &&  !renv.processingOver()){
    39         if(!renv.errorRaised() &&  !renv.processingOver()){
    47             r++;
    40             r++;
    48             for( TypeElement t : typesIn(renv.getRootElements()) )
    41             for( TypeElement t : typesIn(renv.getRootElements()) )
    49                 System.out.println("Round"+r+ ": " + t.toString());
    42                 System.out.println("Round"+r+ ": " + t.toString());
    50 
    43 
    51             try {
    44             try {
    52                 PackageElement PE = E.getPackageElement("dir1");
    45                 PackageElement PE = eltUtils.getPackageElement("dir1");
    53                 List<? extends Element> LEE = PE.getEnclosedElements();    /* <=This line elicits the error message.  */
    46                 List<? extends Element> LEE = PE.getEnclosedElements();    /* <=This line elicits the error message.  */
    54                 for(Element e : LEE)
    47                 for(Element e : LEE)
    55                     System.out.println("found " + e.toString() + " in dir1.");
    48                     System.out.println("found " + e.toString() + " in dir1.");
    56             }
    49             }
    57             catch(NullPointerException npe) {
    50             catch(NullPointerException npe) {
    58                 msgr.printMessage(ERROR,npe.toString());
    51                 messager.printMessage(ERROR,npe.toString());
    59                 //npe.printStackTrace();
    52                 //npe.printStackTrace();
    60                 return false;
    53                 return false;
    61             }
    54             }
    62         }
    55         }
    63         // on round 1, expect errorRaised == false && processingOver == false
    56         // on round 1, expect errorRaised == false && processingOver == false
    64         // on round 2, expect errorRaised == true && processingOver == true
    57         // on round 2, expect errorRaised == true && processingOver == true
    65         if( renv.errorRaised() != renv.processingOver()) {
    58         if( renv.errorRaised() != renv.processingOver()) {
    66             msgr.printMessage(ERROR, "FAILED");
    59             messager.printMessage(ERROR, "FAILED");
    67         }
    60         }
    68         return true;
    61         return true;
    69     }
    62     }
    70 
       
    71     @Override
       
    72     public SourceVersion getSupportedSourceVersion() {
       
    73         return SourceVersion.latest();
       
    74     }
       
    75 }
    63 }