提交 b23cd9e0 编写于 作者: A amurillo

Merge

/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -467,11 +467,24 @@ public abstract class Symbol extends AnnoConstruct implements Element { ...@@ -467,11 +467,24 @@ public abstract class Symbol extends AnnoConstruct implements Element {
private boolean hiddenIn(ClassSymbol clazz, Types types) { private boolean hiddenIn(ClassSymbol clazz, Types types) {
Symbol sym = hiddenInInternal(clazz, types); Symbol sym = hiddenInInternal(clazz, types);
return sym != null && sym != this; Assert.check(sym != null, "the result of hiddenInInternal() can't be null");
/* If we find the current symbol then there is no symbol hiding it
*/
return sym != this;
} }
private Symbol hiddenInInternal(ClassSymbol c, Types types) { /** This method looks in the supertypes graph that has the current class as the
Scope.Entry e = c.members().lookup(name); * initial node, till it finds the current symbol or another symbol that hides it.
* If the current class has more than one supertype (extends one class and
* implements one or more interfaces) then null can be returned, meaning that
* a wrong path in the supertypes graph was selected. Null can only be returned
* as a temporary value, as a result of the recursive call.
*/
private Symbol hiddenInInternal(ClassSymbol currentClass, Types types) {
if (currentClass == owner) {
return this;
}
Scope.Entry e = currentClass.members().lookup(name);
while (e.scope != null) { while (e.scope != null) {
if (e.sym.kind == kind && if (e.sym.kind == kind &&
(kind != MTH || (kind != MTH ||
...@@ -481,18 +494,19 @@ public abstract class Symbol extends AnnoConstruct implements Element { ...@@ -481,18 +494,19 @@ public abstract class Symbol extends AnnoConstruct implements Element {
} }
e = e.next(); e = e.next();
} }
List<Symbol> hiddenSyms = List.nil(); Symbol hiddenSym = null;
for (Type st : types.interfaces(c.type).prepend(types.supertype(c.type))) { for (Type st : types.interfaces(currentClass.type)
.prepend(types.supertype(currentClass.type))) {
if (st != null && (st.hasTag(CLASS))) { if (st != null && (st.hasTag(CLASS))) {
Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types); Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types);
if (sym != null) { if (sym == this) {
hiddenSyms = hiddenSyms.prepend(hiddenInInternal((ClassSymbol)st.tsym, types)); return this;
} else if (sym != null) {
hiddenSym = sym;
} }
} }
} }
return hiddenSyms.contains(this) ? return hiddenSym;
this :
(hiddenSyms.isEmpty() ? null : hiddenSyms.head);
} }
/** Is this symbol inherited into a given class? /** Is this symbol inherited into a given class?
......
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -1481,8 +1481,21 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { ...@@ -1481,8 +1481,21 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
} }
public String toString() { public String toString() {
if (inst != null) return inst.toString(); return (inst == null) ? qtype + "?" : inst.toString();
else return qtype + "?"; }
public String debugString() {
String result = "inference var = " + qtype + "\n";
if (inst != null) {
result += "inst = " + inst + '\n';
}
for (InferenceBound bound: InferenceBound.values()) {
List<Type> aboundList = bounds.get(bound);
if (aboundList.size() > 0) {
result += bound + " = " + aboundList + '\n';
}
}
return result;
} }
@Override @Override
...@@ -1492,8 +1505,7 @@ public abstract class Type extends AnnoConstruct implements TypeMirror { ...@@ -1492,8 +1505,7 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
@Override @Override
public Type baseType() { public Type baseType() {
if (inst != null) return inst.baseType(); return (inst == null) ? this : inst.baseType();
else return this;
} }
/** get all bounds of a given kind */ /** get all bounds of a given kind */
......
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -2119,6 +2119,12 @@ public class Infer { ...@@ -2119,6 +2119,12 @@ public class Infer {
//back-door to infer //back-door to infer
return Infer.this; return Infer.this;
} }
@Override
public String toString() {
return "Inference vars: " + inferencevars + '\n' +
"Undet vars: " + undetvars;
}
} }
final InferenceContext emptyContext = new InferenceContext(List.<Type>nil()); final InferenceContext emptyContext = new InferenceContext(List.<Type>nil());
......
...@@ -1038,7 +1038,7 @@ public class ClassWriter extends ClassFile { ...@@ -1038,7 +1038,7 @@ public class ClassWriter extends ClassFile {
} }
databuf.appendChar(pool.get(inner)); databuf.appendChar(pool.get(inner));
databuf.appendChar( databuf.appendChar(
inner.owner.kind == TYP ? pool.get(inner.owner) : 0); inner.owner.kind == TYP && !inner.name.isEmpty() ? pool.get(inner.owner) : 0);
databuf.appendChar( databuf.appendChar(
!inner.name.isEmpty() ? pool.get(inner.name) : 0); !inner.name.isEmpty() ? pool.get(inner.name) : 0);
databuf.appendChar(flags); databuf.appendChar(flags);
......
/* /*
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -2189,9 +2189,9 @@ public class Code { ...@@ -2189,9 +2189,9 @@ public class Code {
// Keep local variables if // Keep local variables if
// 1) we need them for debug information // 1) we need them for debug information
// 2) it is an exception type and it contains type annotations // 2) it is an exception type and it contains type annotations
if (!varDebugInfo && boolean keepLocalVariables = varDebugInfo ||
(!var.sym.isExceptionParameter() || (var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations());
var.sym.hasTypeAnnotations())) return; if (!keepLocalVariables) return;
if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return; if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
if (varBuffer == null) if (varBuffer == null)
varBuffer = new LocalVar[20]; varBuffer = new LocalVar[20];
......
...@@ -762,14 +762,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea ...@@ -762,14 +762,14 @@ public class JavacProcessingEnvironment implements ProcessingEnvironment, Closea
public Set<TypeElement> visitType(TypeElement e, Set<TypeElement> p) { public Set<TypeElement> visitType(TypeElement e, Set<TypeElement> p) {
// Type parameters are not considered to be enclosed by a type // Type parameters are not considered to be enclosed by a type
scan(e.getTypeParameters(), p); scan(e.getTypeParameters(), p);
return scan(e.getEnclosedElements(), p); return super.visitType(e, p);
} }
@Override @Override
public Set<TypeElement> visitExecutable(ExecutableElement e, Set<TypeElement> p) { public Set<TypeElement> visitExecutable(ExecutableElement e, Set<TypeElement> p) {
// Type parameters are not considered to be enclosed by an executable // Type parameters are not considered to be enclosed by an executable
scan(e.getTypeParameters(), p); scan(e.getTypeParameters(), p);
return scan(e.getEnclosedElements(), p); return super.visitExecutable(e, p);
} }
void addAnnotations(Element e, Set<TypeElement> p) { void addAnnotations(Element e, Set<TypeElement> p) {
......
...@@ -137,14 +137,14 @@ public class JavacRoundEnvironment implements RoundEnvironment { ...@@ -137,14 +137,14 @@ public class JavacRoundEnvironment implements RoundEnvironment {
public Set<Element> visitType(TypeElement e, TypeElement p) { public Set<Element> visitType(TypeElement e, TypeElement p) {
// Type parameters are not considered to be enclosed by a type // Type parameters are not considered to be enclosed by a type
scan(e.getTypeParameters(), p); scan(e.getTypeParameters(), p);
return scan(e.getEnclosedElements(), p); return super.visitType(e, p);
} }
@Override @Override
public Set<Element> visitExecutable(ExecutableElement e, TypeElement p) { public Set<Element> visitExecutable(ExecutableElement e, TypeElement p) {
// Type parameters are not considered to be enclosed by an executable // Type parameters are not considered to be enclosed by an executable
scan(e.getTypeParameters(), p); scan(e.getTypeParameters(), p);
return scan(e.getEnclosedElements(), p); return super.visitExecutable(e, p);
} }
@Override @Override
......
...@@ -202,7 +202,6 @@ public class ClassWriter extends BasicWriter { ...@@ -202,7 +202,6 @@ public class ClassWriter extends BasicWriter {
if (options.verbose) { if (options.verbose) {
println(); println();
indent(+1); indent(+1);
attrWriter.write(cf, cf.attributes, constant_pool);
println("minor version: " + cf.minor_version); println("minor version: " + cf.minor_version);
println("major version: " + cf.major_version); println("major version: " + cf.major_version);
writeList("flags: ", flags.getClassFlags(), "\n"); writeList("flags: ", flags.getClassFlags(), "\n");
...@@ -218,6 +217,10 @@ public class ClassWriter extends BasicWriter { ...@@ -218,6 +217,10 @@ public class ClassWriter extends BasicWriter {
writeMethods(); writeMethods();
indent(-1); indent(-1);
println("}"); println("}");
if (options.verbose) {
attrWriter.write(cf, cf.attributes, constant_pool);
}
} }
// where // where
class JavaTypePrinter implements Type.Visitor<StringBuilder,StringBuilder> { class JavaTypePrinter implements Type.Visitor<StringBuilder,StringBuilder> {
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8034924
* @summary Incorrect inheritance of inaccessible static method
* @library /tools/javac/lib
* @build ToolBox
* @run main IncorrectInheritanceTest
*/
public class IncorrectInheritanceTest {
private static final String ASrc =
"package pkg;\n" +
"\n" +
"public class A {\n" +
" static void foo(Object o) {}\n" +
" private static void bar(Object o) {}\n" +
"}";
private static final String BSrc =
"import pkg.A;\n" +
"class B extends A {\n" +
" public void foo(Object o) {}\n" +
" public void bar(Object o) {}\n" +
"}";
private static final String CSrc =
"class C extends B {\n" +
" public void m(Object o) {\n" +
" foo(o);\n" +
" bar(o);\n" +
" }\n" +
"}";
public static void main(String[] args) throws Exception {
new IncorrectInheritanceTest().test();
}
public void test() throws Exception {
ToolBox.JavaToolArgs javacParams =
new ToolBox.JavaToolArgs()
.setSources(ASrc, BSrc, CSrc);
ToolBox.javac(javacParams);
}
}
/* /*
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,6 +30,7 @@ import java.io.PrintWriter; ...@@ -30,6 +30,7 @@ import java.io.PrintWriter;
import java.lang.annotation.*; import java.lang.annotation.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -51,6 +52,11 @@ public class Driver { ...@@ -51,6 +52,11 @@ public class Driver {
new Driver().runDriver(clazz.newInstance()); new Driver().runDriver(clazz.newInstance());
} }
String[][] extraParamsCombinations = new String[][] {
new String[] { },
new String[] { "-g" },
};
protected void runDriver(Object object) throws Exception { protected void runDriver(Object object) throws Exception {
int passed = 0, failed = 0; int passed = 0, failed = 0;
Class<?> clazz = object.getClass(); Class<?> clazz = object.getClass();
...@@ -65,18 +71,20 @@ public class Driver { ...@@ -65,18 +71,20 @@ public class Driver {
throw new IllegalArgumentException("Test method needs to return a string: " + method); throw new IllegalArgumentException("Test method needs to return a string: " + method);
String testClass = testClassOf(method); String testClass = testClassOf(method);
try { for (String[] extraParams : extraParamsCombinations) {
String compact = (String)method.invoke(object); try {
String fullFile = wrap(compact); String compact = (String)method.invoke(object);
ClassFile cf = compileAndReturn(fullFile, testClass); String fullFile = wrap(compact);
List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf); ClassFile cf = compileAndReturn(fullFile, testClass, extraParams);
ReferenceInfoUtil.compare(expected, actual, cf); List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
out.println("PASSED: " + method.getName()); ReferenceInfoUtil.compare(expected, actual, cf);
++passed; out.println("PASSED: " + method.getName());
} catch (Throwable e) { ++passed;
out.println("FAILED: " + method.getName()); } catch (Throwable e) {
out.println(" " + e.toString()); out.println("FAILED: " + method.getName());
++failed; out.println(" " + e.toString());
++failed;
}
} }
} }
...@@ -156,7 +164,7 @@ public class Driver { ...@@ -156,7 +164,7 @@ public class Driver {
} }
} }
private ClassFile compileAndReturn(String fullFile, String testClass) throws Exception { private ClassFile compileAndReturn(String fullFile, String testClass, String... extraParams) throws Exception {
File source = writeTestFile(fullFile); File source = writeTestFile(fullFile);
File clazzFile = compileTestFile(source, testClass); File clazzFile = compileTestFile(source, testClass);
return ClassFile.read(clazzFile); return ClassFile.read(clazzFile);
...@@ -170,8 +178,12 @@ public class Driver { ...@@ -170,8 +178,12 @@ public class Driver {
return f; return f;
} }
protected File compileTestFile(File f, String testClass) { protected File compileTestFile(File f, String testClass, String... extraParams) {
int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() }); List<String> options = new ArrayList<>();
options.addAll(Arrays.asList("-source", "1.8"));
options.addAll(Arrays.asList(extraParams));
options.add(f.getPath());
int rc = com.sun.tools.javac.Main.compile(options.toArray(new String[options.size()]));
if (rc != 0) if (rc != 0)
throw new Error("compilation failed. rc=" + rc); throw new Error("compilation failed. rc=" + rc);
String path; String path;
......
/* /*
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*; ...@@ -25,6 +25,7 @@ import static com.sun.tools.classfile.TypeAnnotation.TargetType.*;
/* /*
* @test * @test
* @bug 8028576
* @summary Test population of reference info for exception parameters * @summary Test population of reference info for exception parameters
* @author Werner Dietl * @author Werner Dietl
* @compile -g Driver.java ReferenceInfoUtil.java ExceptionParameters.java * @compile -g Driver.java ReferenceInfoUtil.java ExceptionParameters.java
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/** @test
* @bug 8034854
* @summary Verify that the InnerClasses attribute has outer_class_info_index zero if it has
* inner_name_index zero (for synthetic classes)
* @compile SyntheticClasses.java
* @run main SyntheticClasses
*/
import java.io.*;
import java.util.*;
import com.sun.tools.classfile.*;
public class SyntheticClasses {
public static void main(String[] args) throws IOException, ConstantPoolException {
new SyntheticClasses().run();
}
private void run() throws IOException, ConstantPoolException {
File testClasses = new File(System.getProperty("test.classes"));
for (File classFile : testClasses.listFiles()) {
ClassFile cf = ClassFile.read(classFile);
if (cf.getName().matches(".*\\$[0-9]+")) {
EnclosingMethod_attribute encl =
(EnclosingMethod_attribute) cf.getAttribute(Attribute.EnclosingMethod);
if (encl != null) {
if (encl.method_index != 0)
throw new IllegalStateException("Invalid EnclosingMethod.method_index: " +
encl.method_index + ".");
}
}
InnerClasses_attribute attr =
(InnerClasses_attribute) cf.getAttribute(Attribute.InnerClasses);
if (attr != null) {
for (InnerClasses_attribute.Info info : attr.classes) {
if (cf.major_version < 51)
throw new IllegalStateException();
if (info.inner_name_index == 0 && info.outer_class_info_index != 0)
throw new IllegalStateException("Invalid outer_class_info_index=" +
info.outer_class_info_index +
"; inner_name_index=" +
info.inner_name_index + ".");
}
}
}
}
}
class SyntheticConstructorAccessTag {
private static class A {
private A(){}
}
public void test() {
new A();
}
}
class SyntheticEnumMapping {
private int convert(E e) {
switch (e) {
case A: return 0;
default: return -1;
}
}
enum E { A }
}
interface SyntheticAssertionsDisabled {
public default void test() {
assert false;
}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8038080
* @summary make sure that all declaration annotations are discovered
* by the processing environment
* @library /tools/javac/lib
* @build JavacTestingAbstractProcessor ProcessingEnvAnnoDiscovery
* @compile/process -processor ProcessingEnvAnnoDiscovery ProcessingEnvAnnoDiscovery.java
*/
import java.lang.annotation.*;
import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.*;
import com.sun.tools.javac.util.*;
@ProcessingEnvAnnoDiscovery.Anno1
public class ProcessingEnvAnnoDiscovery<@ProcessingEnvAnnoDiscovery.Anno4 T>
extends JavacTestingAbstractProcessor {
private int round = 0;
public boolean process(Set<? extends TypeElement> annos, RoundEnvironment rEnv) {
if (round++ == 0) {
System.out.println(annos);
Assert.check(annos.contains(eltUtils.getTypeElement("java.lang.annotation.Target")));
Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno1")));
Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno2")));
Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno3")));
Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno4")));
Assert.check(annos.contains(eltUtils.getTypeElement("ProcessingEnvAnnoDiscovery.Anno5")));
Assert.check(annos.size() == 6, "Found extra annotations"); //Anno1-5 + @Target
}
return true;
}
@Anno2
public <@Anno5 K> K m(@Anno3 long foo) {
return null;
}
@interface Anno1 {}
@interface Anno2 {}
@interface Anno3 {}
@Target(ElementType.TYPE_PARAMETER)
@interface Anno4 {}
@Target(ElementType.TYPE_PARAMETER)
@interface Anno5 {}
}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.*;
@Retention(RUNTIME)
public @interface Anno {}
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Class to hold annotations for ElementsAnnotatedWithTest.
*/
@AnnotatedElementInfo(annotationName="Anno",
expectedSize=1,
names={"annotatedParameter"})
public class ParameterAnnotations {
private void foo(@Anno Object annotatedParameter) {}
}
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
/* /*
* @test * @test
* @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 8030049 * @bug 6397298 6400986 6425592 6449798 6453386 6508401 6498938 6911854 8030049 8038080
* @summary Tests that getElementsAnnotatedWith works properly. * @summary Tests that getElementsAnnotatedWith works properly.
* @author Joseph D. Darcy * @author Joseph D. Darcy
* @library /tools/javac/lib * @library /tools/javac/lib
...@@ -31,12 +31,14 @@ ...@@ -31,12 +31,14 @@
* @compile TestElementsAnnotatedWith.java * @compile TestElementsAnnotatedWith.java
* @compile InheritedAnnotation.java * @compile InheritedAnnotation.java
* @compile TpAnno.java * @compile TpAnno.java
* @compile Anno.java
* @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only SurfaceAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only BuriedAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java * @compile -processor TestElementsAnnotatedWith -proc:only Part1.java Part2.java
* @compile -processor TestElementsAnnotatedWith -proc:only C2.java * @compile -processor TestElementsAnnotatedWith -proc:only C2.java
* @compile -processor TestElementsAnnotatedWith -proc:only Foo.java * @compile -processor TestElementsAnnotatedWith -proc:only Foo.java
* @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java * @compile -processor TestElementsAnnotatedWith -proc:only TypeParameterAnnotations.java
* @compile -processor TestElementsAnnotatedWith -proc:only ParameterAnnotations.java
* @compile/fail/ref=ErroneousAnnotations.out -processor TestElementsAnnotatedWith -proc:only -XDrawDiagnostics ErroneousAnnotations.java * @compile/fail/ref=ErroneousAnnotations.out -processor TestElementsAnnotatedWith -proc:only -XDrawDiagnostics ErroneousAnnotations.java
* @compile Foo.java * @compile Foo.java
* @compile/process -processor TestElementsAnnotatedWith -proc:only Foo * @compile/process -processor TestElementsAnnotatedWith -proc:only Foo
......
...@@ -40,10 +40,10 @@ public class T4975569 ...@@ -40,10 +40,10 @@ public class T4975569
verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION"); verify("T4975569$Anno", "flags: ACC_INTERFACE, ACC_ABSTRACT, ACC_ANNOTATION");
verify("T4975569$E", "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM"); verify("T4975569$E", "flags: ACC_FINAL, ACC_SUPER, ACC_ENUM");
verify("T4975569$S", "flags: ACC_BRIDGE, ACC_SYNTHETIC", verify("T4975569$S", "flags: ACC_BRIDGE, ACC_SYNTHETIC",
"InnerClasses:\n static"); "InnerClasses:\n static");
verify("T4975569$V", "void m(java.lang.String...)", verify("T4975569$V", "void m(java.lang.String...)",
"flags: ACC_VARARGS"); "flags: ACC_VARARGS");
verify("T4975569$Prot", "InnerClasses:\n protected"); verify("T4975569$Prot", "InnerClasses:\n protected");
//verify("T4975569$Priv", "InnerClasses"); //verify("T4975569$Priv", "InnerClasses");
if (errors > 0) if (errors > 0)
throw new Error(errors + " found."); throw new Error(errors + " found.");
......
/*
* Copyright (c) 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 8035104
* @summary reorder class file attributes in javap listing
*/
import java.io.*;
public class T8035104 {
public static void main(String[] args) throws Exception {
new T8035104().run();
}
public void run() throws Exception {
String[] lines = javap("-v", T8035104.class.getName()).split("[\r\n]+");
int minor = -1;
int SourceFile = -1;
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
if (line.matches(" *minor version: [0-9.]+"))
minor = i;
if (line.matches(" *SourceFile: .+"))
SourceFile = i;
}
if (minor == -1)
throw new Exception("minor version not found");
if (SourceFile == -1)
throw new Exception("SourceFile not found");
if (SourceFile < minor)
throw new Exception("unexpected order of output");
System.out.println("output OK");
}
String javap(String... args) {
StringWriter sw = new StringWriter();
PrintWriter out = new PrintWriter(sw);
int rc = com.sun.tools.javap.Main.run(args, out);
out.close();
System.out.println(sw.toString());
System.out.println("javap exited, rc=" + rc);
return sw.toString();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册