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 */ 23 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; 32 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()); 50 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 } 70 71 @Override 72 public SourceVersion getSupportedSourceVersion() { 73 return SourceVersion.latest(); 74 } 75 } | 1 /* 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. 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 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; 32 33 public class b6341534 extends JavacTestingAbstractProcessor { 34 static int r = 0; 35 36 //Create directory 'dir1' and a test class in dir1 37 public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) 38 { 39 if(!renv.errorRaised() && !renv.processingOver()){ 40 r++; 41 for( TypeElement t : typesIn(renv.getRootElements()) ) 42 System.out.println("Round"+r+ ": " + t.toString()); 43 44 try { 45 PackageElement PE = eltUtils.getPackageElement("dir1"); 46 List<? extends Element> LEE = PE.getEnclosedElements(); /* <=This line elicits the error message. */ 47 for(Element e : LEE) 48 System.out.println("found " + e.toString() + " in dir1."); 49 } 50 catch(NullPointerException npe) { 51 messager.printMessage(ERROR,npe.toString()); 52 //npe.printStackTrace(); 53 return false; 54 } 55 } 56 // on round 1, expect errorRaised == false && processingOver == false 57 // on round 2, expect errorRaised == true && processingOver == true 58 if( renv.errorRaised() != renv.processingOver()) { 59 messager.printMessage(ERROR, "FAILED"); 60 } 61 return true; 62 } 63 } |