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

Merge

......@@ -70,7 +70,7 @@ ifdef QUIET
endif
ifdef VERBOSE
ANT_OPTIONS += -verbose -diagnostics
ANT_OPTIONS += -verbose -debug
endif
ifdef JDK_VERSION
......
......@@ -101,7 +101,11 @@ class SourceOrderDeclScanner extends DeclarationScanner {
}
@SuppressWarnings("cast")
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 dpo2 = new DeclPartialOrder();
......
......@@ -496,57 +496,12 @@ public class Apt extends ListBuffer<Env<AttrContext>> {
* won't match anything.
*/
Pattern importStringToPattern(String s) {
if (s.equals("*")) {
return allMatches;
if (com.sun.tools.javac.processing.JavacProcessingEnvironment.isValidImportString(s)) {
return com.sun.tools.javac.processing.JavacProcessingEnvironment.validImportStringToPattern(s);
} else {
String t = s;
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 &= 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);
Bark bark = Bark.instance(context);
bark.aptWarning("MalformedSupportedString", s);
return com.sun.tools.javac.processing.JavacProcessingEnvironment.noMatches;
}
}
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;
import com.sun.tools.apt.util.Bark;
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
* tool.
*
......@@ -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;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
......@@ -34,6 +36,7 @@ import java.util.Set;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.StringTokenizer;
import java.util.zip.ZipFile;
import javax.tools.JavaFileManager.Location;
......@@ -449,4 +452,60 @@ public class Paths {
return fsInfo.isFile(file)
&& (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 @@
package com.sun.tools.javac.processing;
import java.lang.reflect.*;
import java.util.*;
import java.util.regex.*;
......@@ -874,20 +873,9 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
JavaFileManager fileManager = currentContext.get(JavaFileManager.class);
List<JavaFileObject> fileObjects = List.nil();
for (JavaFileObject jfo : filer.getGeneratedSourceFileObjects() ) {
fileObjects = fileObjects.prepend(jfo);
}
compiler = JavaCompiler.instance(currentContext);
List<JCCompilationUnit> parsedFiles = compiler.parseFiles(fileObjects);
roots = cleanTrees(roots).reverse();
for (JCCompilationUnit unit : parsedFiles)
roots = roots.prepend(unit);
roots = roots.reverse();
List<JCCompilationUnit> parsedFiles = sourcesToParsedFiles(compiler);
roots = cleanTrees(roots).appendList(parsedFiles);
// Check for errors after parsing
if (compiler.parseErrors()) {
......@@ -921,11 +909,16 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
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);
currentContext = contextForNextRound(currentContext, true);
compiler = JavaCompiler.instance(currentContext);
filer.newRound(currentContext, true);
filer.warnIfUnclosedFiles();
warnIfUnmatchedOptions();
......@@ -979,10 +972,22 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
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
private void runLastRound(PrintWriter xout,
int roundNumber,
boolean errorStatus,
private List<JCCompilationUnit> runLastRound(PrintWriter xout,
int roundNumber,
boolean errorStatus,
JavaCompiler compiler,
List<JCCompilationUnit> roots,
TaskListener taskListener) throws IOException {
roundNumber++;
List<ClassSymbol> noTopLevelClasses = List.nil();
......@@ -1003,6 +1008,15 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
if (taskListener != null)
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) {
......@@ -1340,115 +1354,62 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
return specifiedPackages;
}
// Borrowed from DocletInvoker and apt
// TODO: remove from apt's Main
private static final Pattern allMatches = Pattern.compile(".*");
public static final Pattern noMatches = Pattern.compile("(\\P{all})+");
/**
* 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
* Convert import-style string for supported annotations into a
* regex matching that string. If the string is a valid
* import-style string, return a regex that won't match anything.
*/
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;
private static Pattern importStringToPattern(String s, Processor p, Log log) {
if (isValidImportString(s)) {
return validImportStringToPattern(s);
} else {
log.warning("proc.malformed.supported.string", s, p.getClass().getName());
return noMatches; // won't match any valid identifier
}
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
* Return true if the argument string is a valid import-style
* string specifying claimed annotations; return false otherwise.
*/
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 + "/";
public static boolean isValidImportString(String s) {
if (s.equals("*"))
return true;
boolean valid = true;
String t = s;
int index = t.indexOf('*');
if (index != -1) {
// '*' must be last character...
if (index == t.length() -1) {
// ... any and preceding 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
return false;
}
try {
return new URL("file", "", name);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("file");
// 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);
}
return valid;
}
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) {
public static Pattern validImportStringToPattern(String s) {
if (s.equals("*")) {
return allMatches;
} else {
String t = s;
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("\\.", "\\\\.");
String s_prime = s.replace(".", "\\.");
if (s_prime.endsWith("*")) {
s_prime = s_prime.substring(0, s_prime.length() - 1) + ".+";
......
......@@ -81,7 +81,7 @@ public class DocletInvoker {
cpString = appendPath(System.getProperty("env.class.path"), cpString);
cpString = appendPath(System.getProperty("java.class.path"), cpString);
cpString = appendPath(docletPath, cpString);
URL[] urls = pathToURLs(cpString);
URL[] urls = com.sun.tools.javac.file.Paths.pathToURLs(cpString);
if (docletParentClassLoader == null)
appClassLoader = new URLClassLoader(urls, getDelegationClassLoader(docletClassName));
else
......@@ -313,58 +313,4 @@ public class DocletInvoker {
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.*;
import javax.lang.model.element.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class Anno extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations,
RoundEnvironment roundEnv) {
......@@ -35,4 +34,9 @@ public class Anno extends AbstractProcessor {
// System.err.println("annotation processing");
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -27,6 +27,8 @@
* @summary Verify that assertions are enabled before the class is initialized
* and not thereafter
* @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;
@Wrap
@SupportedAnnotationTypes("Wrap")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6403466 extends AbstractProcessor {
static final String testSrcDir = System.getProperty("test.src");
......@@ -73,24 +72,31 @@ public class T6403466 extends AbstractProcessor {
}
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
Filer filer = processingEnv.getFiler();
for (TypeElement anno: annos) {
Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
System.err.println("anno: " + anno);
System.err.println("elts: " + elts);
for (TypeElement te: ElementFilter.typesIn(elts)) {
try {
Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter();
out.write("class " + te.getSimpleName() + "Wrapper { }");
out.close();
} catch (IOException ex) {
ex.printStackTrace();
if (!rEnv.processingOver()) {
Filer filer = processingEnv.getFiler();
for (TypeElement anno: annos) {
Set<? extends Element> elts = rEnv.getElementsAnnotatedWith(anno);
System.err.println("anno: " + anno);
System.err.println("elts: " + elts);
for (TypeElement te: ElementFilter.typesIn(elts)) {
try {
Writer out = filer.createSourceFile(te.getSimpleName() + "Wrapper").openWriter();
out.write("class " + te.getSimpleName() + "Wrapper { }");
out.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
}
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
@Retention(RetentionPolicy.SOURCE)
......
......@@ -17,7 +17,7 @@ import com.sun.source.tree.*;
import com.sun.source.util.*;
import com.sun.tools.javac.tree.JCTree;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class T6406771 extends AbstractProcessor {
String[] tests = {
......@@ -95,4 +95,8 @@ public class T6406771 extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -37,7 +37,6 @@ import com.sun.source.tree.*;
import com.sun.source.util.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6411379 extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annoElems,
......@@ -58,6 +57,11 @@ public class T6411379 extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
public void checkNull(Object o) {
if (o != null)
throw new AssertionError("expected null");
......
......@@ -37,7 +37,6 @@ import com.sun.source.tree.*;
import com.sun.source.util.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6423583 extends AbstractProcessor {
boolean b1 = true;
boolean b2 = false;
......@@ -59,6 +58,10 @@ public class T6423583 extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static class Test extends TreeScanner<Void,Void> {
......
......@@ -38,7 +38,6 @@ import javax.lang.model.element.*;
import com.sun.source.tree.*;
import com.sun.source.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class T6855236 extends AbstractProcessor {
......@@ -63,6 +62,11 @@ public class T6855236 extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
class CodeVisitor extends TreePathScanner<Object, Trees> {
@Override
......
......@@ -76,7 +76,6 @@ public class T6421111 extends ToolTester {
throw new AssertionError("Annotation processor failed");
}
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
static class MyProcessor extends AbstractProcessor {
void test(TypeElement element, boolean fbound) {
TypeParameterElement tpe = element.getTypeParameters().iterator().next();
......@@ -96,6 +95,10 @@ public class T6421111 extends ToolTester {
test(processingEnv.getElementUtils().getTypeElement("Test2"), true);
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
public static void main(String... args) {
new T6421111().test(args);
......
......@@ -105,7 +105,6 @@ class DummyFO extends SimpleJavaFileObject {
}
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
class P extends AbstractProcessor {
boolean ran = false;
......@@ -145,4 +144,9 @@ class P extends AbstractProcessor {
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -38,7 +38,6 @@ import com.sun.source.util.*;
import com.sun.tools.javac.api.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class T6412669 extends AbstractProcessor {
public static void main(String... args) throws IOException {
String testSrc = System.getProperty("test.src", ".");
......@@ -72,4 +71,9 @@ public class T6412669 extends AbstractProcessor {
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -34,13 +34,12 @@ import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import javax.lang.model.SourceVersion;
import static javax.tools.Diagnostic.Kind.*;
import static javax.lang.model.SourceVersion.RELEASE_6;
@interface TestMe {}
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(RELEASE_6)
public class T6424358 extends AbstractProcessor {
@TestMe enum Test { FOO; }
......@@ -66,4 +65,9 @@ public class T6424358 extends AbstractProcessor {
scan.scan(e);
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -28,7 +28,6 @@ import javax.lang.model.*;
import javax.lang.model.element.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class A extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
Filer filer = processingEnv.getFiler();
......@@ -40,4 +39,8 @@ public class A extends AbstractProcessor {
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -30,7 +30,6 @@ import javax.lang.model.element.*;
import javax.tools.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class A extends AbstractProcessor {
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
......@@ -42,4 +41,9 @@ public class A extends AbstractProcessor {
}
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
}
......@@ -63,7 +63,6 @@ public class T6430209 {
new File(testSrc, "test0.java"), new File(testSrc, "test1.java")));
Iterable<String> opts = Arrays.asList("-proc:only",
"-processor", "b6341534",
"-source", "1.6",
"-processorpath", testClasses);
StringWriter out = new StringWriter();
JavacTask task = tool.getTask(out, fm, dl, opts, null, files);
......
......@@ -22,6 +22,7 @@
*/
import javax.annotation.processing.*;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
......@@ -30,7 +31,6 @@ import java.util.*;
import java.util.Set;
@SupportedAnnotationTypes({"*"})
@SupportedSourceVersion(javax.lang.model.SourceVersion.RELEASE_7)
public class b6341534 extends AbstractProcessor {
static int r = 0;
static Elements E = null;
......@@ -62,4 +62,9 @@ public class b6341534 extends AbstractProcessor {
if( renv.errorRaised() ) { msgr.printMessage(ERROR, "FAILED");}
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.*;
@SupportedAnnotationTypes("*")
@SupportedSourceVersion(SourceVersion.RELEASE_7 )
public class T6439826 extends AbstractProcessor {
public static void main(String... args) {
String testSrc = System.getProperty("test.src", ".");
......@@ -76,6 +75,11 @@ public class T6439826 extends AbstractProcessor {
return false;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void writeBadFile() {
Filer filer = processingEnv.getFiler();
Messager messager = processingEnv.getMessager();
......
......@@ -40,7 +40,6 @@ import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class TypeParamBounds extends AbstractProcessor {
......@@ -60,6 +59,11 @@ public class TypeParamBounds extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
TypeElement gen = elements.getTypeElement("TypeParamBounds.Gen");
......
......@@ -38,7 +38,6 @@ import javax.lang.model.type.*;
import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("IAm")
@IAm(OverEager.class)
public class OverEager extends AbstractProcessor {
......@@ -59,6 +58,11 @@ public class OverEager extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
for (TypeElement t : typesIn(round.getRootElements())) {
......
......@@ -39,8 +39,6 @@ import javax.lang.model.util.*;
import static javax.lang.model.type.TypeKind.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class NoTypes extends AbstractProcessor {
......@@ -60,6 +58,11 @@ public class NoTypes extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
......
......@@ -37,7 +37,6 @@ import javax.lang.model.element.*;
import javax.lang.model.type.*;
import javax.lang.model.util.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class GetTypeElemBadArg extends AbstractProcessor {
......@@ -64,6 +63,12 @@ public class GetTypeElemBadArg extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private static void tellAbout(TypeElement t) {
System.out.println(t);
System.out.println(t.getClass());
......
......@@ -40,7 +40,6 @@ import javax.lang.model.util.*;
import static javax.lang.model.util.ElementFilter.*;
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedAnnotationTypes("*")
public class OverridesSpecEx extends AbstractProcessor {
......@@ -60,6 +59,11 @@ public class OverridesSpecEx extends AbstractProcessor {
return true;
}
@Override
public SourceVersion getSupportedSourceVersion() {
return SourceVersion.latest();
}
private void doit(Set<? extends TypeElement> annoTypes,
RoundEnvironment round) {
TypeElement string = elements.getTypeElement("java.lang.String");
......
......@@ -98,7 +98,7 @@ import static com.sun.tools.javac.util.Position.NOPOS;
* @test
* @bug 6919889
* @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 {
/**
......@@ -150,6 +150,8 @@ public class TreePosTest {
tags.add(args[++i]);
else if (arg.equals("-ef") && i + 1 < args.length)
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")) {
if (excludeFiles.size() > 0)
throw new Error("-r must be used before -ef");
......@@ -199,6 +201,7 @@ public class TreePosTest {
out.println("-t tag Limit checks to tree nodes with this tag");
out.println(" Can be repeated if desired");
out.println("-ef file Exclude file or directory");
out.println("-et tag Exclude tree nodes with given tag name");
out.println("");
out.println("files may be directories or files");
out.println("directories will be scanned recursively");
......@@ -304,6 +307,8 @@ public class TreePosTest {
Set<String> tags = new HashSet<String>();
/** Set of files and directories to be excluded from analysis. */
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. */
TagNames tagNames = new TagNames();
......@@ -324,7 +329,7 @@ public class TreePosTest {
return;
Info self = new Info(tree, endPosTable);
if (check(self)) {
if (check(encl, self)) {
// Modifiers nodes are present throughout the tree even where
// there is no corresponding source text.
// Redundant semicolons in a class definition can cause empty
......@@ -392,8 +397,13 @@ public class TreePosTest {
super.visitVarDef(tree);
}
boolean check(Info x) {
return tags.size() == 0 || tags.contains(tagNames.get(x.tag));
boolean check(Info encl, Info self) {
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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册