提交 2cc0addc 编写于 作者: L lana

Merge

...@@ -70,7 +70,7 @@ ifdef QUIET ...@@ -70,7 +70,7 @@ ifdef QUIET
endif endif
ifdef VERBOSE ifdef VERBOSE
ANT_OPTIONS += -verbose -diagnostics ANT_OPTIONS += -verbose -debug
endif endif
ifdef JDK_VERSION ifdef JDK_VERSION
......
...@@ -101,7 +101,11 @@ class SourceOrderDeclScanner extends DeclarationScanner { ...@@ -101,7 +101,11 @@ class SourceOrderDeclScanner extends DeclarationScanner {
} }
@SuppressWarnings("cast") @SuppressWarnings("cast")
private int compareEqualPosition(Declaration d1, Declaration d2) { private int compareEqualPosition(Declaration d1, Declaration d2) {
assert d1.getPosition() == d2.getPosition(); assert
(d1.getPosition() == d2.getPosition()) || // Handles two null positions.
(d1.getPosition().file().compareTo(d2.getPosition().file()) == 0 &&
d1.getPosition().line() == d2.getPosition().line() &&
d1.getPosition().column() == d2.getPosition().column());
DeclPartialOrder dpo1 = new DeclPartialOrder(); DeclPartialOrder dpo1 = new DeclPartialOrder();
DeclPartialOrder dpo2 = new DeclPartialOrder(); DeclPartialOrder dpo2 = new DeclPartialOrder();
......
...@@ -496,57 +496,12 @@ public class Apt extends ListBuffer<Env<AttrContext>> { ...@@ -496,57 +496,12 @@ public class Apt extends ListBuffer<Env<AttrContext>> {
* won't match anything. * won't match anything.
*/ */
Pattern importStringToPattern(String s) { Pattern importStringToPattern(String s) {
if (s.equals("*")) { if (com.sun.tools.javac.processing.JavacProcessingEnvironment.isValidImportString(s)) {
return allMatches; return com.sun.tools.javac.processing.JavacProcessingEnvironment.validImportStringToPattern(s);
} else { } else {
String t = s; Bark bark = Bark.instance(context);
boolean star = false; bark.aptWarning("MalformedSupportedString", s);
return com.sun.tools.javac.processing.JavacProcessingEnvironment.noMatches;
/*
* Validate string from factory is legal. If the string
* has more than one asterisks or the asterisks does not
* appear as the last character (preceded by a period),
* the string is not legal.
*/
boolean valid = true;
int index = t.indexOf('*');
if (index != -1) {
// '*' must be last character...
if (index == t.length() -1) {
// ... and preceeding character must be '.'
if ( index-1 >= 0 ) {
valid = t.charAt(index-1) == '.';
// Strip off ".*$" for identifier checks
t = t.substring(0, t.length()-2);
}
} else
valid = false;
}
// Verify string is off the form (javaId \.)+ or javaId
if (valid) {
String[] javaIds = t.split("\\.", t.length()+2);
for(String javaId: javaIds)
valid &= isJavaIdentifier(javaId);
}
if (!valid) {
Bark bark = Bark.instance(context);
bark.aptWarning("MalformedSupportedString", s);
return noMatches; // won't match any valid identifier
}
String s_prime = s.replaceAll("\\.", "\\\\.");
if (s_prime.endsWith("*")) {
s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+";
}
return Pattern.compile(s_prime);
} }
} }
private static final Pattern allMatches = Pattern.compile(".*");
private static final Pattern noMatches = Pattern.compile("(\\P{all})+");
} }
...@@ -56,6 +56,8 @@ import com.sun.tools.apt.comp.UsageMessageNeededException; ...@@ -56,6 +56,8 @@ import com.sun.tools.apt.comp.UsageMessageNeededException;
import com.sun.tools.apt.util.Bark; import com.sun.tools.apt.util.Bark;
import com.sun.mirror.apt.AnnotationProcessorFactory; import com.sun.mirror.apt.AnnotationProcessorFactory;
import static com.sun.tools.javac.file.Paths.pathToURLs;
/** This class provides a commandline interface to the apt build-time /** This class provides a commandline interface to the apt build-time
* tool. * tool.
* *
...@@ -1276,59 +1278,4 @@ public class Main { ...@@ -1276,59 +1278,4 @@ public class Main {
} }
} }
} }
// Borrowed from DocletInvoker
/**
* Utility method for converting a search path string to an array
* of directory and JAR file URLs.
*
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/
static URL[] pathToURLs(String path) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
URL[] urls = new URL[st.countTokens()];
int count = 0;
while (st.hasMoreTokens()) {
URL url = fileToURL(new File(st.nextToken()));
if (url != null) {
urls[count++] = url;
}
}
if (urls.length != count) {
URL[] tmp = new URL[count];
System.arraycopy(urls, 0, tmp, 0, count);
urls = tmp;
}
return urls;
}
/**
* Returns the directory or JAR file URL corresponding to the specified
* local file name.
*
* @param file the File object
* @return the resulting directory or JAR file URL, or null if unknown
*/
static URL fileToURL(File file) {
String name;
try {
name = file.getCanonicalPath();
} catch (IOException e) {
name = file.getAbsolutePath();
}
name = name.replace(File.separatorChar, '/');
if (!name.startsWith("/")) {
name = "/" + name;
}
// If the file does not exist, then assume that it's a directory
if (!file.isFile()) {
name = name + "/";
}
try {
return new URL("file", "", name);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("file");
}
}
} }
...@@ -27,6 +27,8 @@ package com.sun.tools.javac.file; ...@@ -27,6 +27,8 @@ package com.sun.tools.javac.file;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
...@@ -34,6 +36,7 @@ import java.util.Set; ...@@ -34,6 +36,7 @@ import java.util.Set;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.StringTokenizer;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
import javax.tools.JavaFileManager.Location; import javax.tools.JavaFileManager.Location;
...@@ -449,4 +452,60 @@ public class Paths { ...@@ -449,4 +452,60 @@ public class Paths {
return fsInfo.isFile(file) return fsInfo.isFile(file)
&& (n.endsWith(".jar") || n.endsWith(".zip")); && (n.endsWith(".jar") || n.endsWith(".zip"));
} }
/**
* Utility method for converting a search path string to an array
* of directory and JAR file URLs.
*
* Note that this method is called by apt and the DocletInvoker.
*
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/
public static URL[] pathToURLs(String path) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
URL[] urls = new URL[st.countTokens()];
int count = 0;
while (st.hasMoreTokens()) {
URL url = fileToURL(new File(st.nextToken()));
if (url != null) {
urls[count++] = url;
}
}
if (urls.length != count) {
URL[] tmp = new URL[count];
System.arraycopy(urls, 0, tmp, 0, count);
urls = tmp;
}
return urls;
}
/**
* Returns the directory or JAR file URL corresponding to the specified
* local file name.
*
* @param file the File object
* @return the resulting directory or JAR file URL, or null if unknown
*/
private static URL fileToURL(File file) {
String name;
try {
name = file.getCanonicalPath();
} catch (IOException e) {
name = file.getAbsolutePath();
}
name = name.replace(File.separatorChar, '/');
if (!name.startsWith("/")) {
name = "/" + name;
}
// If the file does not exist, then assume that it's a directory
if (!file.isFile()) {
name = name + "/";
}
try {
return new URL("file", "", name);
} catch (MalformedURLException e) {
throw new IllegalArgumentException(file.toString());
}
}
} }
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package com.sun.tools.javac.processing; package com.sun.tools.javac.processing;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.*; import java.util.*;
import java.util.regex.*; import java.util.regex.*;
...@@ -874,20 +873,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -874,20 +873,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
JavaFileManager fileManager = currentContext.get(JavaFileManager.class); JavaFileManager fileManager = currentContext.get(JavaFileManager.class);
List<JavaFileObject> fileObjects = List.nil();
for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
fileObjects = fileObjects.prepend(jfo);
}
compiler = JavaCompiler.instance(currentContext); compiler = JavaCompiler.instance(currentContext);
List<JCCompilationUnit> parsedFiles = compiler.parseFiles(fileObjects); List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
roots = cleanTrees(roots).reverse(); roots = cleanTrees(roots).appendList(parsedFiles);
for (JCCompilationUnit unit : parsedFiles)
roots = roots.prepend(unit);
roots = roots.reverse();
// Check for errors after parsing // Check for errors after parsing
if (compiler.parseErrors()) { if (compiler.parseErrors()) {
...@@ -921,11 +909,16 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -921,11 +909,16 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
break runAround; // No new files break runAround; // No new files
} }
} }
runLastRound(xout, roundNumber, errorStatus, taskListener); roots = runLastRound(xout, roundNumber, errorStatus, compiler, roots, taskListener);
// Set error status for any files compiled and generated in
// the last round
if (compiler.parseErrors())
errorStatus = true;
compiler.close(false); compiler.close(false);
currentContext = contextForNextRound(currentContext, true); currentContext = contextForNextRound(currentContext, true);
compiler = JavaCompiler.instance(currentContext); compiler = JavaCompiler.instance(currentContext);
filer.newRound(currentContext, true); filer.newRound(currentContext, true);
filer.warnIfUnclosedFiles(); filer.warnIfUnclosedFiles();
warnIfUnmatchedOptions(); warnIfUnmatchedOptions();
...@@ -979,10 +972,22 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -979,10 +972,22 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return compiler; return compiler;
} }
private List<JCCompilationUnit> sourcesToParsedFiles(JavaCompiler compiler)
throws IOException {
List<JavaFileObject> fileObjects = List.nil();
for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
fileObjects = fileObjects.prepend(jfo);
}
return compiler.parseFiles(fileObjects);
}
// Call the last round of annotation processing // Call the last round of annotation processing
private void runLastRound(PrintWriter xout, private List<JCCompilationUnit> runLastRound(PrintWriter xout,
int roundNumber, int roundNumber,
boolean errorStatus, boolean errorStatus,
JavaCompiler compiler,
List<JCCompilationUnit> roots,
TaskListener taskListener) throws IOException { TaskListener taskListener) throws IOException {
roundNumber++; roundNumber++;
List<ClassSymbol> noTopLevelClasses = List.nil(); List<ClassSymbol> noTopLevelClasses = List.nil();
...@@ -1003,6 +1008,15 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1003,6 +1008,15 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (taskListener != null) if (taskListener != null)
taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND)); taskListener.finished(new TaskEvent(TaskEvent.Kind.ANNOTATION_PROCESSING_ROUND));
} }
// Add any sources generated during the last round to the set
// of files to be compiled.
if (moreToDo()) {
List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
roots = cleanTrees(roots).appendList(parsedFiles);
}
return roots;
} }
private void updateProcessingState(Context currentContext, boolean lastRound) { private void updateProcessingState(Context currentContext, boolean lastRound) {
...@@ -1340,115 +1354,62 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -1340,115 +1354,62 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return specifiedPackages; return specifiedPackages;
} }
// Borrowed from DocletInvoker and apt private static final Pattern allMatches = Pattern.compile(".*");
// TODO: remove from apt's Main public static final Pattern noMatches = Pattern.compile("(\\P{all})+");
/** /**
* Utility method for converting a search path string to an array * Convert import-style string for supported annotations into a
* of directory and JAR file URLs. * regex matching that string. If the string is a valid
* * import-style string, return a regex that won't match anything.
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/ */
public static URL[] pathToURLs(String path) { private static Pattern importStringToPattern(String s, Processor p, Log log) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator); if (isValidImportString(s)) {
URL[] urls = new URL[st.countTokens()]; return validImportStringToPattern(s);
int count = 0; } else {
while (st.hasMoreTokens()) { log.warning("proc.malformed.supported.string", s, p.getClass().getName());
URL url = fileToURL(new File(st.nextToken())); return noMatches; // won't match any valid identifier
if (url != null) {
urls[count++] = url;
}
}
if (urls.length != count) {
URL[] tmp = new URL[count];
System.arraycopy(urls, 0, tmp, 0, count);
urls = tmp;
} }
return urls;
} }
/** /**
* Returns the directory or JAR file URL corresponding to the specified * Return true if the argument string is a valid import-style
* local file name. * string specifying claimed annotations; return false otherwise.
*
* @param file the File object
* @return the resulting directory or JAR file URL, or null if unknown
*/ */
private static URL fileToURL(File file) { public static boolean isValidImportString(String s) {
String name; if (s.equals("*"))
try { return true;
name = file.getCanonicalPath();
} catch (IOException e) { boolean valid = true;
name = file.getAbsolutePath(); String t = s;
} int index = t.indexOf('*');
name = name.replace(File.separatorChar, '/');
if (!name.startsWith("/")) { if (index != -1) {
name = "/" + name; // '*' must be last character...
} if (index == t.length() -1) {
// If the file does not exist, then assume that it's a directory // ... any and preceding character must be '.'
if (!file.isFile()) { if ( index-1 >= 0 ) {
name = name + "/"; valid = t.charAt(index-1) == '.';
// Strip off ".*$" for identifier checks
t = t.substring(0, t.length()-2);
}
} else
return false;
} }
try {
return new URL("file", "", name); // Verify string is off the form (javaId \.)+ or javaId
} catch (MalformedURLException e) { if (valid) {
throw new IllegalArgumentException("file"); String[] javaIds = t.split("\\.", t.length()+2);
for(String javaId: javaIds)
valid &= SourceVersion.isIdentifier(javaId);
} }
return valid;
} }
public static Pattern validImportStringToPattern(String s) {
private static final Pattern allMatches = Pattern.compile(".*");
private static final Pattern noMatches = Pattern.compile("(\\P{all})+");
/**
* Convert import-style string to regex matching that string. If
* the string is a valid import-style string, return a regex that
* won't match anything.
*/
// TODO: remove version in Apt.java
public static Pattern importStringToPattern(String s, Processor p, Log log) {
if (s.equals("*")) { if (s.equals("*")) {
return allMatches; return allMatches;
} else { } else {
String t = s; String s_prime = s.replace(".", "\\.");
boolean star = false;
/*
* Validate string from factory is legal. If the string
* has more than one asterisks or the asterisks does not
* appear as the last character (preceded by a period),
* the string is not legal.
*/
boolean valid = true;
int index = t.indexOf('*');
if (index != -1) {
// '*' must be last character...
if (index == t.length() -1) {
// ... and preceeding character must be '.'
if ( index-1 >= 0 ) {
valid = t.charAt(index-1) == '.';
// Strip off ".*$" for identifier checks
t = t.substring(0, t.length()-2);
}
} else
valid = false;
}
// Verify string is off the form (javaId \.)+ or javaId
if (valid) {
String[] javaIds = t.split("\\.", t.length()+2);
for(String javaId: javaIds)
valid &= SourceVersion.isIdentifier(javaId);
}
if (!valid) {
log.warning("proc.malformed.supported.string", s, p.getClass().getName());
return noMatches; // won't match any valid identifier
}
String s_prime = s.replaceAll("\\.", "\\\\.");
if (s_prime.endsWith("*")) { if (s_prime.endsWith("*")) {
s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+"; s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+";
......
...@@ -81,7 +81,7 @@ public class DocletInvoker { ...@@ -81,7 +81,7 @@ public class DocletInvoker {
cpString = appendPath(System.getProperty("env.class.path"), cpString); cpString = appendPath(System.getProperty("env.class.path"), cpString);
cpString = appendPath(System.getProperty("java.class.path"), cpString); cpString = appendPath(System.getProperty("java.class.path"), cpString);
cpString = appendPath(docletPath, cpString); cpString = appendPath(docletPath, cpString);
URL[] urls = pathToURLs(cpString); URL[] urls = com.sun.tools.javac.file.Paths.pathToURLs(cpString);
if (docletParentClassLoader == null) if (docletParentClassLoader == null)
appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName)); appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
else else
...@@ -313,58 +313,4 @@ public class DocletInvoker { ...@@ -313,58 +313,4 @@ public class DocletInvoker {
Thread.currentThread().setContextClassLoader(savedCCL); Thread.currentThread().setContextClassLoader(savedCCL);
} }
} }
/**
* Utility method for converting a search path string to an array
* of directory and JAR file URLs.
*
* @param path the search path string
* @return the resulting array of directory and JAR file URLs
*/
static URL[] pathToURLs(String path) {
StringTokenizer st = new StringTokenizer(path, File.pathSeparator);
URL[] urls = new URL[st.countTokens()];
int count = 0;
while (st.hasMoreTokens()) {
URL url = fileToURL(new File(st.nextToken()));
if (url != null) {
urls[count++] = url;
}
}
if (urls.length != count) {
URL[] tmp = new URL[count];
System.arraycopy(urls, 0, tmp, 0, count);
urls = tmp;
}
return urls;
}
/**
* Returns the directory or JAR file URL corresponding to the specified
* local file name.
*
* @param file the File object
* @return the resulting directory or JAR file URL, or null if unknown
*/
static URL fileToURL(File file) {
String name;
try {
name = file.getCanonicalPath();
} catch (IOException e) {
name = file.getAbsolutePath();
}
name = name.replace(File.separatorChar, '/');
if (!name.startsWith("/")) {
name = "/" + name;
}
// If the file does not exist, then assume that it's a directory
if (!file.isFile()) {
name = name + "/";
}
try {
return new URL("file", "", name);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("file");
}
}
} }
...@@ -27,7 +27,6 @@ import javax.lang.model.*; ...@@ -27,7 +27,6 @@ import javax.lang.model.*;
import javax.lang.model.element.*; import javax.lang.model.element.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class Anno extends AbstractProcessor { public class Anno extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) { RoundEnvironment roundEnv) {
...@@ -35,4 +34,9 @@ public class Anno extends AbstractProcessor { ...@@ -35,4 +34,9 @@ public class Anno extends AbstractProcessor {
// System.err.println("annotation processing"); // System.err.println("annotation processing");
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
* @summary Verify that assertions are enabled before the class is initialized * @summary Verify that assertions are enabled before the class is initialized
* and not thereafter * and not thereafter
* @author gafter * @author gafter
* @build EarlyAssert EarlyAssertWrapper
* @run main EarlyAssertWrapper
*/ */
/* /*
......
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.io.*;
import java.util.*;
/*
* Wrapper for the EarlyAssert test to run the test in a JVM without assertions
* enabled.
*/
public class EarlyAssertWrapper {
public static void main(String... args) throws Exception {
EarlyAssertWrapper w = new EarlyAssertWrapper();
w.run();
}
void run() throws Exception {
List<String> cmd = new ArrayList<String>();
File java_home = new File(System.getProperty("java.home"));
if (java_home.getName().equals("jre"))
java_home = java_home.getParentFile();
cmd.add(new File(new File(java_home, "bin"), "java").getPath());
// ensure we run with the same bootclasspath as this test,
// in case this test is being run with -Xbootclasspath
cmd.add("-Xbootclasspath:" + System.getProperty("sun.boot.class.path"));
// propogate classpath
cmd.add("-classpath");
cmd.add(System.getProperty("java.class.path"));
// ensure all assertions disabled in target VM
cmd.add("-da");
cmd.add("-dsa");
cmd.add("EarlyAssert");
System.err.println("Running command: " + cmd);
ProcessBuilder pb = new ProcessBuilder(cmd);
pb.redirectErrorStream(true);
Process p = pb.start();
p.getOutputStream().close();
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
String line;
DataInputStream in = new DataInputStream(p.getInputStream());
try {
while ((line = in.readLine()) != null)
pw.println(line);
} finally {
in.close();
}
pw.close();
String out = sw.toString();
int rc = p.waitFor();
if (rc != 0 || out.length() > 0)
throw new Error("failed: rc=" + rc + (out.length() > 0 ? ": " + out : ""));
}
}
...@@ -41,7 +41,6 @@ import com.sun.tools.javac.api.JavacTool; ...@@ -41,7 +41,6 @@ import com.sun.tools.javac.api.JavacTool;
@Wrap @Wrap
@SupportedAnnotationTypes("Wrap") @SupportedAnnotationTypes("Wrap")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6403466 extends AbstractProcessor { public class T6403466 extends AbstractProcessor {
static final String testSrcDir = System.getProperty("test.src"); static final String testSrcDir = System.getProperty("test.src");
...@@ -73,24 +72,31 @@ public class T6403466 extends AbstractProcessor { ...@@ -73,24 +72,31 @@ public class T6403466 extends AbstractProcessor {
} }
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) { public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
Filer filer = processingEnv.getFiler(); if (!rEnv.processingOver()) {
for (TypeElement anno: annos) { Filer filer = processingEnv.getFiler();
Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno); for (TypeElement anno: annos) {
System.err.println("anno: " + anno); Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
System.err.println("elts: " + elts); System.err.println("anno: " + anno);
for (TypeElement te: ElementFilter.typesIn(elts)) { System.err.println("elts: " + elts);
try { for (TypeElement te: ElementFilter.typesIn(elts)) {
Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter(); try {
out.write("class " + te.getSimpleName() + "Wrapper { }"); Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter();
out.close(); out.write("class " + te.getSimpleName() + "Wrapper { }");
} catch (IOException ex) { out.close();
ex.printStackTrace(); } catch (IOException ex) {
ex.printStackTrace();
}
} }
}
}
} }
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
@Retention(RetentionPolicy.SOURCE) @Retention(RetentionPolicy.SOURCE)
......
...@@ -17,7 +17,7 @@ import com.sun.source.tree.*; ...@@ -17,7 +17,7 @@ import com.sun.source.tree.*;
import com.sun.source.util.*; import com.sun.source.util.*;
import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class T6406771 extends AbstractProcessor { public class T6406771 extends AbstractProcessor {
String[] tests = { String[] tests = {
...@@ -95,4 +95,8 @@ public class T6406771 extends AbstractProcessor { ...@@ -95,4 +95,8 @@ public class T6406771 extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -37,7 +37,6 @@ import com.sun.source.tree.*; ...@@ -37,7 +37,6 @@ import com.sun.source.tree.*;
import com.sun.source.util.*; import com.sun.source.util.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6411379 extends AbstractProcessor { public class T6411379 extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annoElems, public boolean process(Set<? extends TypeElement> annoElems,
...@@ -58,6 +57,11 @@ public class T6411379 extends AbstractProcessor { ...@@ -58,6 +57,11 @@ public class T6411379 extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
public void checkNull(Object o) { public void checkNull(Object o) {
if (o != null) if (o != null)
throw new AssertionError("expected null"); throw new AssertionError("expected null");
......
...@@ -37,7 +37,6 @@ import com.sun.source.tree.*; ...@@ -37,7 +37,6 @@ import com.sun.source.tree.*;
import com.sun.source.util.*; import com.sun.source.util.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6423583 extends AbstractProcessor { public class T6423583 extends AbstractProcessor {
boolean b1 = true; boolean b1 = true;
boolean b2 = false; boolean b2 = false;
...@@ -59,6 +58,10 @@ public class T6423583 extends AbstractProcessor { ...@@ -59,6 +58,10 @@ public class T6423583 extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static class Test extends TreeScanner<Void,Void> { private static class Test extends TreeScanner<Void,Void> {
......
...@@ -38,7 +38,6 @@ import javax.lang.model.element.*; ...@@ -38,7 +38,6 @@ import javax.lang.model.element.*;
import com.sun.source.tree.*; import com.sun.source.tree.*;
import com.sun.source.util.*; import com.sun.source.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class T6855236 extends AbstractProcessor { public class T6855236 extends AbstractProcessor {
...@@ -63,6 +62,11 @@ public class T6855236 extends AbstractProcessor { ...@@ -63,6 +62,11 @@ public class T6855236 extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
class CodeVisitor extends TreePathScanner<Object, Trees> { class CodeVisitor extends TreePathScanner<Object, Trees> {
@Override @Override
......
...@@ -76,7 +76,6 @@ public class T6421111 extends ToolTester { ...@@ -76,7 +76,6 @@ public class T6421111 extends ToolTester {
throw new AssertionError("Annotation processor failed"); throw new AssertionError("Annotation processor failed");
} }
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
static class MyProcessor extends AbstractProcessor { static class MyProcessor extends AbstractProcessor {
void test(TypeElement element, boolean fbound) { void test(TypeElement element, boolean fbound) {
TypeParameterElement tpe = element.getTypeParameters().iterator().next(); TypeParameterElement tpe = element.getTypeParameters().iterator().next();
...@@ -96,6 +95,10 @@ public class T6421111 extends ToolTester { ...@@ -96,6 +95,10 @@ public class T6421111 extends ToolTester {
test(processingEnv.getElementUtils().getTypeElement("Test2"), true); test(processingEnv.getElementUtils().getTypeElement("Test2"), true);
return false; return false;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
public static void main(String... args) { public static void main(String... args) {
new T6421111().test(args); new T6421111().test(args);
......
...@@ -105,7 +105,6 @@ class DummyFO extends SimpleJavaFileObject { ...@@ -105,7 +105,6 @@ class DummyFO extends SimpleJavaFileObject {
} }
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
class P extends AbstractProcessor { class P extends AbstractProcessor {
boolean ran = false; boolean ran = false;
...@@ -145,4 +144,9 @@ class P extends AbstractProcessor { ...@@ -145,4 +144,9 @@ class P extends AbstractProcessor {
} }
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -38,7 +38,6 @@ import com.sun.source.util.*; ...@@ -38,7 +38,6 @@ import com.sun.source.util.*;
import com.sun.tools.javac.api.*; import com.sun.tools.javac.api.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6412669 extends AbstractProcessor { public class T6412669 extends AbstractProcessor {
public static void main(String... args) throws IOException { public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", "."); String testSrc = System.getProperty("test.src", ".");
...@@ -72,4 +71,9 @@ public class T6412669 extends AbstractProcessor { ...@@ -72,4 +71,9 @@ public class T6412669 extends AbstractProcessor {
} }
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -34,13 +34,12 @@ import java.util.Set; ...@@ -34,13 +34,12 @@ import java.util.Set;
import javax.annotation.processing.*; import javax.annotation.processing.*;
import javax.lang.model.element.*; import javax.lang.model.element.*;
import javax.lang.model.util.*; import javax.lang.model.util.*;
import javax.lang.model.SourceVersion;
import static javax.tools.Diagnostic.Kind.*; import static javax.tools.Diagnostic.Kind.*;
import static javax.lang.model.SourceVersion.RELEASE_6;
@interface TestMe {} @interface TestMe {}
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(RELEASE_6)
public class T6424358 extends AbstractProcessor { public class T6424358 extends AbstractProcessor {
@TestMe enum Test { FOO; } @TestMe enum Test { FOO; }
...@@ -66,4 +65,9 @@ public class T6424358 extends AbstractProcessor { ...@@ -66,4 +65,9 @@ public class T6424358 extends AbstractProcessor {
scan.scan(e); scan.scan(e);
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -28,7 +28,6 @@ import javax.lang.model.*; ...@@ -28,7 +28,6 @@ import javax.lang.model.*;
import javax.lang.model.element.*; import javax.lang.model.element.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class A extends AbstractProcessor { public class A extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) { public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
Filer filer = processingEnv.getFiler(); Filer filer = processingEnv.getFiler();
...@@ -40,4 +39,8 @@ public class A extends AbstractProcessor { ...@@ -40,4 +39,8 @@ public class A extends AbstractProcessor {
} }
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -30,7 +30,6 @@ import javax.lang.model.element.*; ...@@ -30,7 +30,6 @@ import javax.lang.model.element.*;
import javax.tools.*; import javax.tools.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class A extends AbstractProcessor { public class A extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
...@@ -42,4 +41,9 @@ public class A extends AbstractProcessor { ...@@ -42,4 +41,9 @@ public class A extends AbstractProcessor {
} }
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
...@@ -63,7 +63,6 @@ public class T6430209 { ...@@ -63,7 +63,6 @@ public class T6430209 {
new File(testSrc, "test0.java"), new File(testSrc, "test1.java"))); new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
Iterable<String> opts = Arrays.asList("-proc:only", Iterable<String> opts = Arrays.asList("-proc:only",
"-processor", "b6341534", "-processor", "b6341534",
"-source", "1.6",
"-processorpath", testClasses); "-processorpath", testClasses);
StringWriter out = new StringWriter(); StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files); JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
*/ */
import javax.annotation.processing.*; import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*; import javax.lang.model.element.*;
import javax.lang.model.util.*; import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*; import static javax.lang.model.util.ElementFilter.*;
...@@ -30,7 +31,6 @@ import java.util.*; ...@@ -30,7 +31,6 @@ import java.util.*;
import java.util.Set; import java.util.Set;
@SupportedAnnotationTypes({"*"}) @SupportedAnnotationTypes({"*"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_7)
public class b6341534 extends AbstractProcessor { public class b6341534 extends AbstractProcessor {
static int r = 0; static int r = 0;
static Elements E = null; static Elements E = null;
...@@ -62,4 +62,9 @@ public class b6341534 extends AbstractProcessor { ...@@ -62,4 +62,9 @@ public class b6341534 extends AbstractProcessor {
if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");} if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");}
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
} }
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* A dummy class to be compiled.
*/
public class Dummy {}
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/**
* Class to exercise dependencies on the two source files generated by
* T6634138.java, foo.WrittenAfterProcessing.java and
* foo.package-info.java.
*/
public class ExerciseDependency {
public static void main(String... args) {
foo.WrittenAfterProcessing wap = new foo.WrittenAfterProcessing();
java.lang.Package pkg = wap.getClass().getPackage();
Deprecated d = pkg.getAnnotation(Deprecated.class);
if (d == null)
throw new RuntimeException();
}
}
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6634138
* @author Joseph D. Darcy
* @summary Verify source files output after processing is over are compiled
* @compile T6634138.java
* @compile -processor T6634138 Dummy.java
* @run main ExerciseDependency
*/
import java.lang.annotation.Annotation;
import java.io.*;
import java.util.Collections;
import java.util.Set;
import java.util.HashSet;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
@SupportedAnnotationTypes("*")
public class T6634138 extends AbstractProcessor {
private Filer filer;
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnvironment) {
// Write out files *after* processing is over.
if (roundEnvironment.processingOver()) {
System.out.println("Writing out source files.");
try {
PrintWriter pw = new PrintWriter(filer.createSourceFile("foo.WrittenAfterProcessing").openWriter());
try {
pw.println("package foo;");
pw.println("public class WrittenAfterProcessing {");
pw.println(" public WrittenAfterProcessing() {super();}");
pw.println("}");
} finally {
pw.close();
}
pw = new PrintWriter(filer.createSourceFile("foo.package-info").openWriter());
try {
pw.println("@Deprecated");
pw.println("package foo;");
} finally {
pw.close();
}
} catch(IOException io) {
throw new RuntimeException(io);
}
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
public void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
filer = processingEnv.getFiler();
}
}
...@@ -39,7 +39,6 @@ import static javax.lang.model.util.ElementFilter.*; ...@@ -39,7 +39,6 @@ import static javax.lang.model.util.ElementFilter.*;
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7 )
public class T6439826 extends AbstractProcessor { public class T6439826 extends AbstractProcessor {
public static void main(String... args) { public static void main(String... args) {
String testSrc = System.getProperty("test.src", "."); String testSrc = System.getProperty("test.src", ".");
...@@ -76,6 +75,11 @@ public class T6439826 extends AbstractProcessor { ...@@ -76,6 +75,11 @@ public class T6439826 extends AbstractProcessor {
return false; return false;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void writeBadFile() { private void writeBadFile() {
Filer filer = processingEnv.getFiler(); Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager(); Messager messager = processingEnv.getMessager();
......
...@@ -40,7 +40,6 @@ import javax.lang.model.element.*; ...@@ -40,7 +40,6 @@ import javax.lang.model.element.*;
import javax.lang.model.type.*; import javax.lang.model.type.*;
import javax.lang.model.util.*; import javax.lang.model.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class TypeParamBounds extends AbstractProcessor { public class TypeParamBounds extends AbstractProcessor {
...@@ -60,6 +59,11 @@ public class TypeParamBounds extends AbstractProcessor { ...@@ -60,6 +59,11 @@ public class TypeParamBounds extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes, private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) { RoundEnvironment round) {
TypeElement gen = elements.getTypeElement("TypeParamBounds.Gen"); TypeElement gen = elements.getTypeElement("TypeParamBounds.Gen");
......
...@@ -38,7 +38,6 @@ import javax.lang.model.type.*; ...@@ -38,7 +38,6 @@ import javax.lang.model.type.*;
import javax.lang.model.util.*; import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*; import static javax.lang.model.util.ElementFilter.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("IAm") @SupportedAnnotationTypes("IAm")
@IAm(OverEager.class) @IAm(OverEager.class)
public class OverEager extends AbstractProcessor { public class OverEager extends AbstractProcessor {
...@@ -59,6 +58,11 @@ public class OverEager extends AbstractProcessor { ...@@ -59,6 +58,11 @@ public class OverEager extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes, private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) { RoundEnvironment round) {
for (TypeElement t : typesIn(round.getRootElements())) { for (TypeElement t : typesIn(round.getRootElements())) {
......
...@@ -39,8 +39,6 @@ import javax.lang.model.util.*; ...@@ -39,8 +39,6 @@ import javax.lang.model.util.*;
import static javax.lang.model.type.TypeKind.*; import static javax.lang.model.type.TypeKind.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class NoTypes extends AbstractProcessor { public class NoTypes extends AbstractProcessor {
...@@ -60,6 +58,11 @@ public class NoTypes extends AbstractProcessor { ...@@ -60,6 +58,11 @@ public class NoTypes extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes, private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) { RoundEnvironment round) {
......
...@@ -37,7 +37,6 @@ import javax.lang.model.element.*; ...@@ -37,7 +37,6 @@ import javax.lang.model.element.*;
import javax.lang.model.type.*; import javax.lang.model.type.*;
import javax.lang.model.util.*; import javax.lang.model.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class GetTypeElemBadArg extends AbstractProcessor { public class GetTypeElemBadArg extends AbstractProcessor {
...@@ -64,6 +63,12 @@ public class GetTypeElemBadArg extends AbstractProcessor { ...@@ -64,6 +63,12 @@ public class GetTypeElemBadArg extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static void tellAbout(TypeElement t) { private static void tellAbout(TypeElement t) {
System.out.println(t); System.out.println(t);
System.out.println(t.getClass()); System.out.println(t.getClass());
......
...@@ -40,7 +40,6 @@ import javax.lang.model.util.*; ...@@ -40,7 +40,6 @@ import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*; import static javax.lang.model.util.ElementFilter.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*") @SupportedAnnotationTypes("*")
public class OverridesSpecEx extends AbstractProcessor { public class OverridesSpecEx extends AbstractProcessor {
...@@ -60,6 +59,11 @@ public class OverridesSpecEx extends AbstractProcessor { ...@@ -60,6 +59,11 @@ public class OverridesSpecEx extends AbstractProcessor {
return true; return true;
} }
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes, private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) { RoundEnvironment round) {
TypeElement string = elements.getTypeElement("java.lang.String"); TypeElement string = elements.getTypeElement("java.lang.String");
......
...@@ -98,7 +98,7 @@ import static com.sun.tools.javac.util.Position.NOPOS; ...@@ -98,7 +98,7 @@ import static com.sun.tools.javac.util.Position.NOPOS;
* @test * @test
* @bug 6919889 * @bug 6919889
* @summary assorted position errors in compiler syntax trees * @summary assorted position errors in compiler syntax trees
* @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations -ef ./tools/javap/typeAnnotations . * @run main TreePosTest -q -r -ef ./tools/javac/typeAnnotations -ef ./tools/javap/typeAnnotations -et ANNOTATED_TYPE .
*/ */
public class TreePosTest { public class TreePosTest {
/** /**
...@@ -150,6 +150,8 @@ public class TreePosTest { ...@@ -150,6 +150,8 @@ public class TreePosTest {
tags.add(args[++i]); tags.add(args[++i]);
else if (arg.equals("-ef") && i + 1 < args.length) else if (arg.equals("-ef") && i + 1 < args.length)
excludeFiles.add(new File(baseDir, args[++i])); excludeFiles.add(new File(baseDir, args[++i]));
else if (arg.equals("-et") && i + 1 < args.length)
excludeTags.add(args[++i]);
else if (arg.equals("-r")) { else if (arg.equals("-r")) {
if (excludeFiles.size() > 0) if (excludeFiles.size() > 0)
throw new Error("-r must be used before -ef"); throw new Error("-r must be used before -ef");
...@@ -199,6 +201,7 @@ public class TreePosTest { ...@@ -199,6 +201,7 @@ public class TreePosTest {
out.println("-t tag Limit checks to tree nodes with this tag"); out.println("-t tag Limit checks to tree nodes with this tag");
out.println(" Can be repeated if desired"); out.println(" Can be repeated if desired");
out.println("-ef file Exclude file or directory"); out.println("-ef file Exclude file or directory");
out.println("-et tag Exclude tree nodes with given tag name");
out.println(""); out.println("");
out.println("files may be directories or files"); out.println("files may be directories or files");
out.println("directories will be scanned recursively"); out.println("directories will be scanned recursively");
...@@ -304,6 +307,8 @@ public class TreePosTest { ...@@ -304,6 +307,8 @@ public class TreePosTest {
Set<String> tags = new HashSet<String>(); Set<String> tags = new HashSet<String>();
/** Set of files and directories to be excluded from analysis. */ /** Set of files and directories to be excluded from analysis. */
Set<File> excludeFiles = new HashSet<File>(); Set<File> excludeFiles = new HashSet<File>();
/** Set of tag names to be excluded from analysis. */
Set<String> excludeTags = new HashSet<String>();
/** Table of printable names for tree tag values. */ /** Table of printable names for tree tag values. */
TagNames tagNames = new TagNames(); TagNames tagNames = new TagNames();
...@@ -324,7 +329,7 @@ public class TreePosTest { ...@@ -324,7 +329,7 @@ public class TreePosTest {
return; return;
Info self = new Info(tree, endPosTable); Info self = new Info(tree, endPosTable);
if (check(self)) { if (check(encl, self)) {
// Modifiers nodes are present throughout the tree even where // Modifiers nodes are present throughout the tree even where
// there is no corresponding source text. // there is no corresponding source text.
// Redundant semicolons in a class definition can cause empty // Redundant semicolons in a class definition can cause empty
...@@ -392,8 +397,13 @@ public class TreePosTest { ...@@ -392,8 +397,13 @@ public class TreePosTest {
super.visitVarDef(tree); super.visitVarDef(tree);
} }
boolean check(Info x) { boolean check(Info encl, Info self) {
return tags.size() == 0 || tags.contains(tagNames.get(x.tag)); if (excludeTags.size() > 0) {
if (encl != null && excludeTags.contains(tagNames.get(encl.tag))
|| excludeTags.contains(tagNames.get(self.tag)))
return false;
}
return tags.size() == 0 || tags.contains(tagNames.get(self.tag));
} }
void check(String label, Info encl, Info self, boolean ok) { void check(String label, Info encl, Info self, boolean ok) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册