提交 ba90eb5c 编写于 作者: L lana

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.
*
* 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 {
private boolean hiddenIn(ClassSymbol clazz, Types 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) {
Scope.Entry e = c.members().lookup(name);
/** This method looks in the supertypes graph that has the current class as the
* 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) {
if (e.sym.kind == kind &&
(kind != MTH ||
......@@ -481,18 +494,19 @@ public abstract class Symbol extends AnnoConstruct implements Element {
}
e = e.next();
}
List<Symbol> hiddenSyms = List.nil();
for (Type st : types.interfaces(c.type).prepend(types.supertype(c.type))) {
Symbol hiddenSym = null;
for (Type st : types.interfaces(currentClass.type)
.prepend(types.supertype(currentClass.type))) {
if (st != null && (st.hasTag(CLASS))) {
Symbol sym = hiddenInInternal((ClassSymbol)st.tsym, types);
if (sym != null) {
hiddenSyms = hiddenSyms.prepend(hiddenInInternal((ClassSymbol)st.tsym, types));
if (sym == this) {
return this;
} else if (sym != null) {
hiddenSym = sym;
}
}
}
return hiddenSyms.contains(this) ?
this :
(hiddenSyms.isEmpty() ? null : hiddenSyms.head);
return hiddenSym;
}
/** 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.
*
* 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 {
}
public String toString() {
if (inst != null) return inst.toString();
else return qtype + "?";
return (inst == null) ? qtype + "?" : inst.toString();
}
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
......@@ -1492,8 +1505,7 @@ public abstract class Type extends AnnoConstruct implements TypeMirror {
@Override
public Type baseType() {
if (inst != null) return inst.baseType();
else return this;
return (inst == null) ? this : inst.baseType();
}
/** 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -2119,6 +2119,12 @@ public class Infer {
//back-door to infer
return Infer.this;
}
@Override
public String toString() {
return "Inference vars: " + inferencevars + '\n' +
"Undet vars: " + undetvars;
}
}
final InferenceContext emptyContext = new InferenceContext(List.<Type>nil());
......
......@@ -1038,7 +1038,7 @@ public class ClassWriter extends ClassFile {
}
databuf.appendChar(pool.get(inner));
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(
!inner.name.isEmpty() ? pool.get(inner.name) : 0);
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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -2189,9 +2189,9 @@ public class Code {
// Keep local variables if
// 1) we need them for debug information
// 2) it is an exception type and it contains type annotations
if (!varDebugInfo &&
(!var.sym.isExceptionParameter() ||
var.sym.hasTypeAnnotations())) return;
boolean keepLocalVariables = varDebugInfo ||
(var.sym.isExceptionParameter() && var.sym.hasTypeAnnotations());
if (!keepLocalVariables) return;
if ((var.sym.flags() & Flags.SYNTHETIC) != 0) return;
if (varBuffer == null)
varBuffer = new LocalVar[20];
......
/*
* 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.
*
* This code is free software; you can redistribute it and/or modify it
......@@ -30,6 +30,7 @@ import java.io.PrintWriter;
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
......@@ -51,6 +52,11 @@ public class Driver {
new Driver().runDriver(clazz.newInstance());
}
String[][] extraParamsCombinations = new String[][] {
new String[] { },
new String[] { "-g" },
};
protected void runDriver(Object object) throws Exception {
int passed = 0, failed = 0;
Class<?> clazz = object.getClass();
......@@ -65,18 +71,20 @@ public class Driver {
throw new IllegalArgumentException("Test method needs to return a string: " + method);
String testClass = testClassOf(method);
try {
String compact = (String)method.invoke(object);
String fullFile = wrap(compact);
ClassFile cf = compileAndReturn(fullFile, testClass);
List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
ReferenceInfoUtil.compare(expected, actual, cf);
out.println("PASSED: " + method.getName());
++passed;
} catch (Throwable e) {
out.println("FAILED: " + method.getName());
out.println(" " + e.toString());
++failed;
for (String[] extraParams : extraParamsCombinations) {
try {
String compact = (String)method.invoke(object);
String fullFile = wrap(compact);
ClassFile cf = compileAndReturn(fullFile, testClass, extraParams);
List<TypeAnnotation> actual = ReferenceInfoUtil.extendedAnnotationsOf(cf);
ReferenceInfoUtil.compare(expected, actual, cf);
out.println("PASSED: " + method.getName());
++passed;
} catch (Throwable e) {
out.println("FAILED: " + method.getName());
out.println(" " + e.toString());
++failed;
}
}
}
......@@ -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 clazzFile = compileTestFile(source, testClass);
return ClassFile.read(clazzFile);
......@@ -170,8 +178,12 @@ public class Driver {
return f;
}
protected File compileTestFile(File f, String testClass) {
int rc = com.sun.tools.javac.Main.compile(new String[] { "-source", "1.8", "-g", f.getPath() });
protected File compileTestFile(File f, String testClass, String... extraParams) {
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)
throw new Error("compilation failed. rc=" + rc);
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.
*
* 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.*;
/*
* @test
* @bug 8028576
* @summary Test population of reference info for exception parameters
* @author Werner Dietl
* @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;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册