6634138: Source generated in last round not compiled

Mon, 15 Feb 2010 18:20:57 -0800

author
darcy
date
Mon, 15 Feb 2010 18:20:57 -0800
changeset 494
af18e3956985
parent 493
7d9e3a15d2b3
child 495
fe17a9dbef03

6634138: Source generated in last round not compiled
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java file | annotate | diff | comparison | revisions
test/tools/javac/T6403466.java file | annotate | diff | comparison | revisions
test/tools/javac/processing/6634138/Dummy.java file | annotate | diff | comparison | revisions
test/tools/javac/processing/6634138/ExerciseDependency.java file | annotate | diff | comparison | revisions
test/tools/javac/processing/6634138/T6634138.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon Feb 15 16:09:50 2010 -0800
     1.2 +++ b/src/share/classes/com/sun/tools/javac/processing/JavacProcessingEnvironment.java	Mon Feb 15 18:20:57 2010 -0800
     1.3 @@ -874,20 +874,9 @@
     1.4  
     1.5                      JavaFileManager fileManager = currentContext.get(JavaFileManager.class);
     1.6  
     1.7 -                    List<JavaFileObject> fileObjects = List.nil();
     1.8 -                    for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
     1.9 -                        fileObjects = fileObjects.prepend(jfo);
    1.10 -                    }
    1.11 -
    1.12 -
    1.13                      compiler = JavaCompiler.instance(currentContext);
    1.14 -                    List<JCCompilationUnit> parsedFiles = compiler.parseFiles(fileObjects);
    1.15 -                    roots = cleanTrees(roots).reverse();
    1.16 -
    1.17 -
    1.18 -                    for (JCCompilationUnit unit : parsedFiles)
    1.19 -                        roots = roots.prepend(unit);
    1.20 -                    roots = roots.reverse();
    1.21 +                    List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
    1.22 +                    roots = cleanTrees(roots).appendList(parsedFiles);
    1.23  
    1.24                      // Check for errors after parsing
    1.25                      if (compiler.parseErrors()) {
    1.26 @@ -921,11 +910,16 @@
    1.27                      break runAround; // No new files
    1.28              }
    1.29          }
    1.30 -        runLastRound(xout, roundNumber, errorStatus, taskListener);
    1.31 +        roots = runLastRound(xout, roundNumber, errorStatus, compiler, roots, taskListener);
    1.32 +        // Set error status for any files compiled and generated in
    1.33 +        // the last round
    1.34 +        if (compiler.parseErrors())
    1.35 +            errorStatus = true;
    1.36  
    1.37          compiler.close(false);
    1.38          currentContext = contextForNextRound(currentContext, true);
    1.39          compiler = JavaCompiler.instance(currentContext);
    1.40 +
    1.41          filer.newRound(currentContext, true);
    1.42          filer.warnIfUnclosedFiles();
    1.43          warnIfUnmatchedOptions();
    1.44 @@ -979,10 +973,22 @@
    1.45          return compiler;
    1.46      }
    1.47  
    1.48 +    private List<JCCompilationUnit> sourcesToParsedFiles(JavaCompiler compiler)
    1.49 +        throws IOException {
    1.50 +        List<JavaFileObject> fileObjects = List.nil();
    1.51 +        for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
    1.52 +            fileObjects = fileObjects.prepend(jfo);
    1.53 +        }
    1.54 +
    1.55 +       return compiler.parseFiles(fileObjects);
    1.56 +    }
    1.57 +
    1.58      // Call the last round of annotation processing
    1.59 -    private void runLastRound(PrintWriter xout,
    1.60 -                              int roundNumber,
    1.61 -                              boolean errorStatus,
    1.62 +    private List<JCCompilationUnit> runLastRound(PrintWriter xout,
    1.63 +                                                 int roundNumber,
    1.64 +                                                 boolean errorStatus,
    1.65 +                                                 JavaCompiler compiler,
    1.66 +                                                 List<JCCompilationUnit> roots,
    1.67                                TaskListener taskListener) throws IOException {
    1.68          roundNumber++;
    1.69          List<ClassSymbol> noTopLevelClasses = List.nil();
    1.70 @@ -1003,6 +1009,15 @@
    1.71              if (taskListener != null)
    1.72                  taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
    1.73          }
    1.74 +
    1.75 +        // Add any sources generated during the last round to the set
    1.76 +        // of files to be compiled.
    1.77 +        if (moreToDo()) {
    1.78 +            List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
    1.79 +            roots = cleanTrees(roots).appendList(parsedFiles);
    1.80 +        }
    1.81 +
    1.82 +        return roots;
    1.83      }
    1.84  
    1.85      private void updateProcessingState(Context currentContext, boolean lastRound) {
     2.1 --- a/test/tools/javac/T6403466.java	Mon Feb 15 16:09:50 2010 -0800
     2.2 +++ b/test/tools/javac/T6403466.java	Mon Feb 15 18:20:57 2010 -0800
     2.3 @@ -41,7 +41,6 @@
     2.4  
     2.5  @Wrap
     2.6  @SupportedAnnotationTypes("Wrap")
     2.7 -@SupportedSourceVersion(SourceVersion.RELEASE_6)
     2.8  public class T6403466 extends AbstractProcessor {
     2.9  
    2.10      static final String testSrcDir = System.getProperty("test.src");
    2.11 @@ -73,24 +72,31 @@
    2.12      }
    2.13  
    2.14      public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
    2.15 -        Filer filer = processingEnv.getFiler();
    2.16 -        for (TypeElement anno: annos) {
    2.17 -            Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
    2.18 -            System.err.println("anno: " + anno);
    2.19 -            System.err.println("elts: " + elts);
    2.20 -            for (TypeElement te: ElementFilter.typesIn(elts)) {
    2.21 -                try {
    2.22 -                    Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter();
    2.23 -                    out.write("class " + te.getSimpleName() + "Wrapper { }");
    2.24 -                    out.close();
    2.25 -                } catch (IOException ex) {
    2.26 -                    ex.printStackTrace();
    2.27 +        if (!rEnv.processingOver()) {
    2.28 +            Filer filer = processingEnv.getFiler();
    2.29 +            for (TypeElement anno: annos) {
    2.30 +                Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
    2.31 +                System.err.println("anno: " + anno);
    2.32 +                System.err.println("elts: " + elts);
    2.33 +                for (TypeElement te: ElementFilter.typesIn(elts)) {
    2.34 +                    try {
    2.35 +                        Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter();
    2.36 +                        out.write("class " + te.getSimpleName() + "Wrapper { }");
    2.37 +                        out.close();
    2.38 +                    } catch (IOException ex) {
    2.39 +                        ex.printStackTrace();
    2.40 +                    }
    2.41                  }
    2.42 +
    2.43              }
    2.44 -
    2.45          }
    2.46          return true;
    2.47      }
    2.48 +
    2.49 +    @Override
    2.50 +    public SourceVersion getSupportedSourceVersion() {
    2.51 +        return SourceVersion.latest();
    2.52 +    }
    2.53  }
    2.54  
    2.55  @Retention(RetentionPolicy.SOURCE)
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/processing/6634138/Dummy.java	Mon Feb 15 18:20:57 2010 -0800
     3.3 @@ -0,0 +1,27 @@
     3.4 +/*
     3.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.24 + * have any questions.
    3.25 + */
    3.26 +
    3.27 +/**
    3.28 + * A dummy class to be compiled.
    3.29 + */
    3.30 +public class Dummy {}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/test/tools/javac/processing/6634138/ExerciseDependency.java	Mon Feb 15 18:20:57 2010 -0800
     4.3 @@ -0,0 +1,37 @@
     4.4 +/*
     4.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
     4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.7 + *
     4.8 + * This code is free software; you can redistribute it and/or modify it
     4.9 + * under the terms of the GNU General Public License version 2 only, as
    4.10 + * published by the Free Software Foundation.
    4.11 + *
    4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    4.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    4.15 + * version 2 for more details (a copy is included in the LICENSE file that
    4.16 + * accompanied this code).
    4.17 + *
    4.18 + * You should have received a copy of the GNU General Public License version
    4.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    4.21 + *
    4.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    4.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    4.24 + * have any questions.
    4.25 + */
    4.26 +
    4.27 +/**
    4.28 + * Class to exercise dependencies on the two source files generated by
    4.29 + * T6634138.java, foo.WrittenAfterProcessing.java and
    4.30 + * foo.package-info.java.
    4.31 + */
    4.32 +public class ExerciseDependency {
    4.33 +    public static void main(String... args) {
    4.34 +        foo.WrittenAfterProcessing wap = new foo.WrittenAfterProcessing();
    4.35 +        java.lang.Package pkg = wap.getClass().getPackage();
    4.36 +        Deprecated d = pkg.getAnnotation(Deprecated.class);
    4.37 +        if (d == null)
    4.38 +            throw new RuntimeException();
    4.39 +    }
    4.40 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/test/tools/javac/processing/6634138/T6634138.java	Mon Feb 15 18:20:57 2010 -0800
     5.3 @@ -0,0 +1,93 @@
     5.4 +/*
     5.5 + * Copyright 2010 Sun Microsystems, Inc.  All Rights Reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.
    5.11 + *
    5.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.15 + * version 2 for more details (a copy is included in the LICENSE file that
    5.16 + * accompanied this code).
    5.17 + *
    5.18 + * You should have received a copy of the GNU General Public License version
    5.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.21 + *
    5.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    5.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    5.24 + * have any questions.
    5.25 + */
    5.26 +
    5.27 +/*
    5.28 + * @test
    5.29 + * @bug 6634138
    5.30 + * @author  Joseph D. Darcy
    5.31 + * @summary Verify source files output after processing is over are compiled
    5.32 + * @compile T6634138.java
    5.33 + * @compile -processor T6634138 Dummy.java
    5.34 + * @run main ExerciseDependency
    5.35 + */
    5.36 +
    5.37 +import java.lang.annotation.Annotation;
    5.38 +import java.io.*;
    5.39 +import java.util.Collections;
    5.40 +import java.util.Set;
    5.41 +import java.util.HashSet;
    5.42 +import java.util.List;
    5.43 +import java.util.ArrayList;
    5.44 +import java.util.Arrays;
    5.45 +import javax.annotation.processing.*;
    5.46 +import javax.lang.model.SourceVersion;
    5.47 +import javax.lang.model.element.*;
    5.48 +import javax.lang.model.util.*;
    5.49 +
    5.50 +@SupportedAnnotationTypes("*")
    5.51 +public class T6634138 extends AbstractProcessor {
    5.52 +    private Filer filer;
    5.53 +
    5.54 +    public boolean process(Set<? extends TypeElement> annotations,
    5.55 +                           RoundEnvironment roundEnvironment) {
    5.56 +        // Write out files *after* processing is over.
    5.57 +        if (roundEnvironment.processingOver()) {
    5.58 +            System.out.println("Writing out source files.");
    5.59 +            try {
    5.60 +                PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter());
    5.61 +                try {
    5.62 +                     pw.println("package foo;");
    5.63 +                     pw.println("public class WrittenAfterProcessing {");
    5.64 +                     pw.println("  public WrittenAfterProcessing() {super();}");
    5.65 +                     pw.println("}");
    5.66 +                 } finally {
    5.67 +                     pw.close();
    5.68 +                 }
    5.69 +
    5.70 +                pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
    5.71 +                try {
    5.72 +                     pw.println("@Deprecated");
    5.73 +                     pw.println("package foo;");
    5.74 +                 } finally {
    5.75 +                     pw.close();
    5.76 +                 }
    5.77 +            } catch(IOException io) {
    5.78 +                throw new RuntimeException(io);
    5.79 +            }
    5.80 +        }
    5.81 +        return true;
    5.82 +    }
    5.83 +
    5.84 +    @Override
    5.85 +    public SourceVersion getSupportedSourceVersion() {
    5.86 +        return SourceVersion.latest();
    5.87 +    }
    5.88 +
    5.89 +    public void init(ProcessingEnvironment processingEnv) {
    5.90 +        super.init(processingEnv);
    5.91 +        filer    = processingEnv.getFiler();
    5.92 +    }
    5.93 +}
    5.94 +
    5.95 +
    5.96 +

mercurial