提交 a075139b 编写于 作者: L lana

Merge

......@@ -352,6 +352,45 @@
</java>
</target>
<!-- a patching facility to speed up incorporating the langtools' classfiles
into a jdk of your choice. Either target.java.home or patch.jdk can be
set on the command line; setting target.java.home has the advantage of
patching the jdk used for jtreg and other tests.
-->
<target name="patch" depends="build-all-classes">
<condition property="patch.jdk" value="${target.java.home}">
<available file="${target.java.home}" type="dir"/>
</condition>
<fail message="patch.jdk or target.java.home is not set, please set target.java.home, or patch.jdk for an alternate jdk image to patch">
<condition>
<not>
<isset property="patch.jdk"/>
</not>
</condition>
</fail>
<property name="patch.tools.jar" location="${patch.jdk}/lib/tools.jar"/>
<property name="patch.rt.jar" location="${patch.jdk}/jre/lib/rt.jar"/>
<fail message="patch.jdk or target.java.home must point to a valid jdk image: missing tools.jar">
<condition>
<not>
<available file="${patch.tools.jar}" type="file"/>
</not>
</condition>
</fail>
<fail message="patch.jdk or target.java.home must point to a valid jdk image: missing rt.jar">
<condition>
<not>
<available file="${patch.rt.jar}" type="file"/>
</not>
</condition>
</fail>
<zip zipfile="${patch.tools.jar}" update="true">
<zipfileset dir="${build.classes.dir}" includes="com/**"/>
</zip>
<zip zipfile="${patch.rt.jar}" update="true">
<zipfileset dir="${build.classes.dir}" includes="javax/**"/>
</zip>
</target>
<!--
**** Debugging/diagnostic targets.
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -53,7 +53,6 @@ public interface MethodTree extends Tree {
Tree getReturnType();
List<? extends TypeParameterTree> getTypeParameters();
List<? extends VariableTree> getParameters();
//308 List<? extends AnnotationTree> getReceiverAnnotations();
List<? extends ExpressionTree> getThrows();
BlockTree getBody();
Tree getDefaultValue(); // for annotation types
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -46,8 +46,6 @@ public interface Tree {
*/
public enum Kind {
//308 ANNOTATED_TYPE(AnnotatedTypeTree.class),
/**
* Used for instances of {@link AnnotationTree}.
*/
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -57,7 +57,6 @@ package com.sun.source.tree;
* @since 1.6
*/
public interface TreeVisitor<R,P> {
//308 R visitAnnotatedType(AnnotatedTypeTree node, P p);
R visitAnnotation(AnnotationTree node, P p);
R visitMethodInvocation(MethodInvocationTree node, P p);
R visitAssert(AssertTree node, P p);
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -47,5 +47,4 @@ import javax.lang.model.element.Name;
public interface TypeParameterTree extends Tree {
Name getName();
List<? extends Tree> getBounds();
//308 List<? extends AnnotationTree> getAnnotations();
}
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -248,10 +248,6 @@ public class SimpleTreeVisitor <R,P> implements TreeVisitor<R,P> {
return defaultAction(node, p);
}
//308 public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
//308 return defaultAction(node, p);
//308 }
public R visitErroneous(ErroneousTree node, P p) {
return defaultAction(node, p);
}
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -138,7 +138,6 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
r = scanAndReduce(node.getReturnType(), p, r);
r = scanAndReduce(node.getTypeParameters(), p, r);
r = scanAndReduce(node.getParameters(), p, r);
//308 r = scanAndReduce(node.getReceiverAnnotations(), p, r);
r = scanAndReduce(node.getThrows(), p, r);
r = scanAndReduce(node.getBody(), p, r);
r = scanAndReduce(node.getDefaultValue(), p, r);
......@@ -362,7 +361,6 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
public R visitTypeParameter(TypeParameterTree node, P p) {
R r = scan(node.getBounds(), p);
//308 R r = scanAndReduce(node.getAnnotations(), p, r);
return r;
}
......@@ -380,12 +378,6 @@ public class TreeScanner<R,P> implements TreeVisitor<R,P> {
return r;
}
//308 public R visitAnnotatedType(AnnotatedTypeTree node, P p) {
//308 R r = scan(node.getAnnotations(), p);
//308 r = scanAndReduce(node.getUnderlyingType(), p, r);
//308 return r;
//308 }
public R visitOther(Tree node, P p) {
return null;
}
......
/*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2011, 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
......@@ -39,6 +39,7 @@ import java.util.Map;
public abstract class Attribute {
public static final String AnnotationDefault = "AnnotationDefault";
public static final String BootstrapMethods = "BootstrapMethods";
public static final String CharacterRangeTable = "CharacterRangeTable";
public static final String Code = "Code";
public static final String ConstantValue = "ConstantValue";
......@@ -54,8 +55,6 @@ public abstract class Attribute {
public static final String RuntimeInvisibleAnnotations = "RuntimeInvisibleAnnotations";
public static final String RuntimeVisibleParameterAnnotations = "RuntimeVisibleParameterAnnotations";
public static final String RuntimeInvisibleParameterAnnotations = "RuntimeInvisibleParameterAnnotations";
public static final String RuntimeVisibleTypeAnnotations = "RuntimeVisibleTypeAnnotations";
public static final String RuntimeInvisibleTypeAnnotations = "RuntimeInvisibleTypeAnnotations";
public static final String Signature = "Signature";
public static final String SourceDebugExtension = "SourceDebugExtension";
public static final String SourceFile = "SourceFile";
......@@ -101,6 +100,7 @@ public abstract class Attribute {
protected void init() {
standardAttributes = new HashMap<String,Class<? extends Attribute>>();
standardAttributes.put(AnnotationDefault, AnnotationDefault_attribute.class);
standardAttributes.put(BootstrapMethods, BootstrapMethods_attribute.class);
standardAttributes.put(CharacterRangeTable, CharacterRangeTable_attribute.class);
standardAttributes.put(Code, Code_attribute.class);
standardAttributes.put(ConstantValue, ConstantValue_attribute.class);
......@@ -118,8 +118,6 @@ public abstract class Attribute {
standardAttributes.put(RuntimeInvisibleParameterAnnotations, RuntimeInvisibleParameterAnnotations_attribute.class);
standardAttributes.put(RuntimeVisibleAnnotations, RuntimeVisibleAnnotations_attribute.class);
standardAttributes.put(RuntimeVisibleParameterAnnotations, RuntimeVisibleParameterAnnotations_attribute.class);
standardAttributes.put(RuntimeVisibleTypeAnnotations, RuntimeVisibleTypeAnnotations_attribute.class);
standardAttributes.put(RuntimeInvisibleTypeAnnotations, RuntimeInvisibleTypeAnnotations_attribute.class);
standardAttributes.put(Signature, Signature_attribute.class);
standardAttributes.put(SourceID, SourceID_attribute.class);
}
......@@ -159,6 +157,7 @@ public abstract class Attribute {
public interface Visitor<R,P> {
R visitBootstrapMethods(BootstrapMethods_attribute attr, P p);
R visitDefault(DefaultAttribute attr, P p);
R visitAnnotationDefault(AnnotationDefault_attribute attr, P p);
R visitCharacterRangeTable(CharacterRangeTable_attribute attr, P p);
......@@ -176,8 +175,6 @@ public abstract class Attribute {
R visitRuntimeInvisibleAnnotations(RuntimeInvisibleAnnotations_attribute attr, P p);
R visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, P p);
R visitRuntimeInvisibleParameterAnnotations(RuntimeInvisibleParameterAnnotations_attribute attr, P p);
R visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, P p);
R visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, P p);
R visitSignature(Signature_attribute attr, P p);
R visitSourceDebugExtension(SourceDebugExtension_attribute attr, P p);
R visitSourceFile(SourceFile_attribute attr, P p);
......
/*
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 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
......@@ -28,34 +28,63 @@ package com.sun.tools.classfile;
import java.io.IOException;
/**
* See JSR 308 specification, section 4
* See JVMS3 <TBD>
* http://cr.openjdk.java.net/~jrose/pres/indy-javadoc-mlvm/
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*/
public abstract class RuntimeTypeAnnotations_attribute extends Attribute {
protected RuntimeTypeAnnotations_attribute(ClassReader cr, int name_index, int length)
throws IOException, Annotation.InvalidAnnotation {
public class BootstrapMethods_attribute extends Attribute {
public final BootstrapMethodSpecifier[] bootstrap_method_specifiers;
BootstrapMethods_attribute(ClassReader cr, int name_index, int length)
throws IOException, AttributeException {
super(name_index, length);
int num_annotations = cr.readUnsignedShort();
annotations = new ExtendedAnnotation[num_annotations];
for (int i = 0; i < annotations.length; i++)
annotations[i] = new ExtendedAnnotation(cr);
int bootstrap_method_count = cr.readUnsignedShort();
bootstrap_method_specifiers = new BootstrapMethodSpecifier[bootstrap_method_count];
for (int i = 0; i < bootstrap_method_specifiers.length; i++)
bootstrap_method_specifiers[i] = new BootstrapMethodSpecifier(cr);
}
protected RuntimeTypeAnnotations_attribute(int name_index, ExtendedAnnotation[] annotations) {
super(name_index, length(annotations));
this.annotations = annotations;
public BootstrapMethods_attribute(int name_index, BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
super(name_index, length(bootstrap_method_specifiers));
this.bootstrap_method_specifiers = bootstrap_method_specifiers;
}
private static int length(ExtendedAnnotation[] annos) {
public static int length(BootstrapMethodSpecifier[] bootstrap_method_specifiers) {
int n = 2;
for (ExtendedAnnotation anno: annos)
n += anno.length();
for (BootstrapMethodSpecifier b : bootstrap_method_specifiers)
n += b.length();
return n;
}
public final ExtendedAnnotation[] annotations;
@Override
public <R, P> R accept(Visitor<R, P> visitor, P p) {
return visitor.visitBootstrapMethods(this, p);
}
public static class BootstrapMethodSpecifier {
public int bootstrap_method_ref;
public int[] bootstrap_arguments;
public BootstrapMethodSpecifier(int bootstrap_method_ref, int[] bootstrap_arguments) {
this.bootstrap_method_ref = bootstrap_method_ref;
this.bootstrap_arguments = bootstrap_arguments;
}
BootstrapMethodSpecifier(ClassReader cr) throws IOException {
bootstrap_method_ref = cr.readUnsignedShort();
int method_count = cr.readUnsignedShort();
bootstrap_arguments = new int[method_count];
for (int i = 0; i < bootstrap_arguments.length; i++) {
bootstrap_arguments[i] = cr.readUnsignedShort();
}
}
int length() {
// u2 (method_ref) + u2 (argc) + u2 * argc
return 2 + 2 + (bootstrap_arguments.length * 2);
}
}
}
/*
* Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2011 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
......@@ -31,7 +31,10 @@ import com.sun.tools.classfile.ConstantPool.CONSTANT_Fieldref_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Float_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Integer_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_InterfaceMethodref_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_InvokeDynamic_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Long_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodHandle_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_MethodType_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_Methodref_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_NameAndType_info;
import com.sun.tools.classfile.ConstantPool.CONSTANT_String_info;
......@@ -304,6 +307,20 @@ public class ClassTranslator
return info;
}
public CPInfo visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Map<Object, Object> translations) {
CONSTANT_InvokeDynamic_info info2 = (CONSTANT_InvokeDynamic_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp) {
info2 = info;
} else {
info2 = new CONSTANT_InvokeDynamic_info(cp2, info.bootstrap_method_attr_index, info.name_and_type_index);
}
translations.put(info, info2);
}
return info;
}
public CPInfo visitLong(CONSTANT_Long_info info, Map<Object, Object> translations) {
CONSTANT_Long_info info2 = (CONSTANT_Long_info) translations.get(info);
if (info2 == null) {
......@@ -339,6 +356,34 @@ public class ClassTranslator
return info;
}
public CPInfo visitMethodHandle(CONSTANT_MethodHandle_info info, Map<Object, Object> translations) {
CONSTANT_MethodHandle_info info2 = (CONSTANT_MethodHandle_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp) {
info2 = info;
} else {
info2 = new CONSTANT_MethodHandle_info(cp2, info.reference_kind, info.reference_index);
}
translations.put(info, info2);
}
return info;
}
public CPInfo visitMethodType(CONSTANT_MethodType_info info, Map<Object, Object> translations) {
CONSTANT_MethodType_info info2 = (CONSTANT_MethodType_info) translations.get(info);
if (info2 == null) {
ConstantPool cp2 = translate(info.cp, translations);
if (cp2 == info.cp) {
info2 = info;
} else {
info2 = new CONSTANT_MethodType_info(cp2, info.descriptor_index);
}
translations.put(info, info2);
}
return info;
}
public CPInfo visitString(CONSTANT_String_info info, Map<Object, Object> translations) {
CONSTANT_String_info info2 = (CONSTANT_String_info) translations.get(info);
if (info2 == null) {
......
/*
* Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2008, 2011, 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
......@@ -267,6 +267,12 @@ public class ClassWriter {
return 1;
}
public Integer visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, ClassOutputStream out) {
out.writeShort(info.bootstrap_method_attr_index);
out.writeShort(info.name_and_type_index);
return 1;
}
public Integer visitLong(CONSTANT_Long_info info, ClassOutputStream out) {
out.writeLong(info.value);
return 2;
......@@ -278,6 +284,17 @@ public class ClassWriter {
return 1;
}
public Integer visitMethodHandle(CONSTANT_MethodHandle_info info, ClassOutputStream out) {
out.writeByte(info.reference_kind.tag);
out.writeShort(info.reference_index);
return 1;
}
public Integer visitMethodType(CONSTANT_MethodType_info info, ClassOutputStream out) {
out.writeShort(info.descriptor_index);
return 1;
}
public Integer visitMethodref(CONSTANT_Methodref_info info, ClassOutputStream out) {
return writeRef(info, out);
}
......@@ -332,6 +349,19 @@ public class ClassWriter {
return null;
}
public Void visitBootstrapMethods(BootstrapMethods_attribute attr, ClassOutputStream out) {
out.writeShort(attr.bootstrap_method_specifiers.length);
for (BootstrapMethods_attribute.BootstrapMethodSpecifier bsm : attr.bootstrap_method_specifiers) {
out.writeShort(bsm.bootstrap_method_ref);
int bsm_args_count = bsm.bootstrap_arguments.length;
out.writeShort(bsm_args_count);
for (int i : bsm.bootstrap_arguments) {
out.writeShort(i);
}
}
return null;
}
public Void visitCharacterRangeTable(CharacterRangeTable_attribute attr, ClassOutputStream out) {
out.writeShort(attr.character_range_table.length);
for (CharacterRangeTable_attribute.Entry e: attr.character_range_table)
......@@ -459,16 +489,6 @@ public class ClassWriter {
return null;
}
public Void visitRuntimeVisibleTypeAnnotations(RuntimeVisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
return null;
}
public Void visitRuntimeInvisibleTypeAnnotations(RuntimeInvisibleTypeAnnotations_attribute attr, ClassOutputStream out) {
annotationWriter.write(attr.annotations, out);
return null;
}
public Void visitRuntimeVisibleParameterAnnotations(RuntimeVisibleParameterAnnotations_attribute attr, ClassOutputStream out) {
out.writeByte(attr.parameter_annotations.length);
for (Annotation[] annos: attr.parameter_annotations)
......@@ -628,12 +648,6 @@ public class ClassWriter {
write(anno, out);
}
public void write(ExtendedAnnotation[] annos, ClassOutputStream out) {
out.writeShort(annos.length);
for (ExtendedAnnotation anno: annos)
write(anno, out);
}
public void write(Annotation anno, ClassOutputStream out) {
out.writeShort(anno.type_index);
out.writeShort(anno.element_value_pairs.length);
......@@ -641,11 +655,6 @@ public class ClassWriter {
write(p, out);
}
public void write(ExtendedAnnotation anno, ClassOutputStream out) {
write(anno.annotation, out);
write(anno.position, out);
}
public void write(element_value_pair pair, ClassOutputStream out) {
out.writeShort(pair.element_name_index);
write(pair.value, out);
......@@ -684,95 +693,5 @@ public class ClassWriter {
return null;
}
private void write(ExtendedAnnotation.Position p, ClassOutputStream out) {
out.writeByte(p.type.targetTypeValue());
switch (p.type) {
// type case
case TYPECAST:
case TYPECAST_GENERIC_OR_ARRAY:
// object creation
case INSTANCEOF:
case INSTANCEOF_GENERIC_OR_ARRAY:
// new expression
case NEW:
case NEW_GENERIC_OR_ARRAY:
case NEW_TYPE_ARGUMENT:
case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
out.writeShort(p.offset);
break;
// local variable
case LOCAL_VARIABLE:
case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
int table_length = p.lvarOffset.length;
out.writeShort(table_length);
for (int i = 0; i < table_length; ++i) {
out.writeShort(1); // for table length
out.writeShort(p.lvarOffset[i]);
out.writeShort(p.lvarLength[i]);
out.writeShort(p.lvarIndex[i]);
}
break;
// method receiver
case METHOD_RECEIVER:
// Do nothing
break;
// type parameters
case CLASS_TYPE_PARAMETER:
case METHOD_TYPE_PARAMETER:
out.writeByte(p.parameter_index);
break;
// type parameters bounds
case CLASS_TYPE_PARAMETER_BOUND:
case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
case METHOD_TYPE_PARAMETER_BOUND:
case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
out.writeByte(p.parameter_index);
out.writeByte(p.bound_index);
break;
// wildcards
case WILDCARD_BOUND:
case WILDCARD_BOUND_GENERIC_OR_ARRAY:
write(p.wildcard_position, out);
break;
// Class extends and implements clauses
case CLASS_EXTENDS:
case CLASS_EXTENDS_GENERIC_OR_ARRAY:
out.writeByte(p.type_index);
break;
// throws
case THROWS:
out.writeByte(p.type_index);
break;
case CLASS_LITERAL:
case CLASS_LITERAL_GENERIC_OR_ARRAY:
out.writeShort(p.offset);
break;
// method parameter: not specified
case METHOD_PARAMETER_GENERIC_OR_ARRAY:
out.writeByte(p.parameter_index);
break;
// method type argument: wasn't specified
case METHOD_TYPE_ARGUMENT:
case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
out.writeShort(p.offset);
out.writeByte(p.type_index);
break;
// We don't need to worry abut these
case METHOD_RETURN_GENERIC_OR_ARRAY:
case FIELD_GENERIC_OR_ARRAY:
break;
case UNKNOWN:
break;
default:
throw new AssertionError("unknown type: " + p);
}
// Append location data for generics/arrays.
if (p.type.hasLocation()) {
out.writeShort(p.location.size());
for (int i : p.location)
out.writeByte((byte)i);
}
}
}
}
/*
* Copyright (c) 2007, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2011, 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
......@@ -114,6 +114,54 @@ public class ConstantPool {
public static final int CONSTANT_Methodref = 10;
public static final int CONSTANT_InterfaceMethodref = 11;
public static final int CONSTANT_NameAndType = 12;
public static final int CONSTANT_MethodHandle = 15;
public static final int CONSTANT_MethodType = 16;
public static final int CONSTANT_InvokeDynamic = 18;
public static enum RefKind {
REF_getField(1, "getfield"),
REF_getStatic(2, "getstatic"),
REF_putField(3, "putfield"),
REF_putStatic(4, "putstatic"),
REF_invokeVirtual(5, "invokevirtual"),
REF_invokeStatic(6, "invokestatic"),
REF_invokeSpecial(7, "invokespecial"),
REF_newInvokeSpecial(8, "newinvokespecial"),
REF_invokeInterface(9, "invokeinterface");
public final int tag;
public final String name;
RefKind(int tag, String name) {
this.tag = tag;
this.name = name;
}
static RefKind getRefkind(int tag) {
switch(tag) {
case 1:
return REF_getField;
case 2:
return REF_getStatic;
case 3:
return REF_putField;
case 4:
return REF_putStatic;
case 5:
return REF_invokeVirtual;
case 6:
return REF_invokeStatic;
case 7:
return REF_invokeSpecial;
case 8:
return REF_newInvokeSpecial;
case 9:
return REF_invokeInterface;
default:
return null;
}
}
}
ConstantPool(ClassReader cr) throws IOException, InvalidEntry {
int count = cr.readUnsignedShort();
......@@ -146,11 +194,23 @@ public class ConstantPool {
pool[i] = new CONSTANT_InterfaceMethodref_info(this, cr);
break;
case CONSTANT_InvokeDynamic:
pool[i] = new CONSTANT_InvokeDynamic_info(this, cr);
break;
case CONSTANT_Long:
pool[i] = new CONSTANT_Long_info(cr);
i++;
break;
case CONSTANT_MethodHandle:
pool[i] = new CONSTANT_MethodHandle_info(this, cr);
break;
case CONSTANT_MethodType:
pool[i] = new CONSTANT_MethodType_info(this, cr);
break;
case CONSTANT_Methodref:
pool[i] = new CONSTANT_Methodref_info(this, cr);
break;
......@@ -279,9 +339,12 @@ public class ConstantPool {
R visitFloat(CONSTANT_Float_info info, P p);
R visitInteger(CONSTANT_Integer_info info, P p);
R visitInterfaceMethodref(CONSTANT_InterfaceMethodref_info info, P p);
R visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, P p);
R visitLong(CONSTANT_Long_info info, P p);
R visitNameAndType(CONSTANT_NameAndType_info info, P p);
R visitMethodref(CONSTANT_Methodref_info info, P p);
R visitMethodHandle(CONSTANT_MethodHandle_info info, P p);
R visitMethodType(CONSTANT_MethodType_info info, P p);
R visitString(CONSTANT_String_info info, P p);
R visitUtf8(CONSTANT_Utf8_info info, P p);
}
......@@ -548,6 +611,44 @@ public class ConstantPool {
}
}
public static class CONSTANT_InvokeDynamic_info extends CPInfo {
CONSTANT_InvokeDynamic_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
bootstrap_method_attr_index = cr.readUnsignedShort();
name_and_type_index = cr.readUnsignedShort();
}
public CONSTANT_InvokeDynamic_info(ConstantPool cp, int bootstrap_method_index, int name_and_type_index) {
super(cp);
this.bootstrap_method_attr_index = bootstrap_method_index;
this.name_and_type_index = name_and_type_index;
}
public int getTag() {
return CONSTANT_InvokeDynamic;
}
public int byteLength() {
return 5;
}
@Override
public String toString() {
return "CONSTANT_InvokeDynamic_info[bootstrap_method_index: " + bootstrap_method_attr_index + ", name_and_type_index: " + name_and_type_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitInvokeDynamic(this, data);
}
public CONSTANT_NameAndType_info getNameAndTypeInfo() throws ConstantPoolException {
return cp.getNameAndTypeInfo(name_and_type_index);
}
public final int bootstrap_method_attr_index;
public final int name_and_type_index;
}
public static class CONSTANT_Long_info extends CPInfo {
CONSTANT_Long_info(ClassReader cr) throws IOException {
value = cr.readLong();
......@@ -582,6 +683,87 @@ public class ConstantPool {
public final long value;
}
public static class CONSTANT_MethodHandle_info extends CPInfo {
CONSTANT_MethodHandle_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
reference_kind = RefKind.getRefkind(cr.readUnsignedByte());
reference_index = cr.readUnsignedShort();
}
public CONSTANT_MethodHandle_info(ConstantPool cp, RefKind ref_kind, int member_index) {
super(cp);
this.reference_kind = ref_kind;
this.reference_index = member_index;
}
public int getTag() {
return CONSTANT_MethodHandle;
}
public int byteLength() {
return 4;
}
@Override
public String toString() {
return "CONSTANT_MethodHandle_info[ref_kind: " + reference_kind + ", member_index: " + reference_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitMethodHandle(this, data);
}
public CPRefInfo getCPRefInfo() throws ConstantPoolException {
int expected = CONSTANT_Methodref;
int actual = cp.get(reference_index).getTag();
// allow these tag types also:
switch (actual) {
case CONSTANT_Fieldref:
case CONSTANT_InterfaceMethodref:
expected = actual;
}
return (CPRefInfo) cp.get(reference_index, expected);
}
public final RefKind reference_kind;
public final int reference_index;
}
public static class CONSTANT_MethodType_info extends CPInfo {
CONSTANT_MethodType_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp);
descriptor_index = cr.readUnsignedShort();
}
public CONSTANT_MethodType_info(ConstantPool cp, int signature_index) {
super(cp);
this.descriptor_index = signature_index;
}
public int getTag() {
return CONSTANT_MethodType;
}
public int byteLength() {
return 3;
}
@Override
public String toString() {
return "CONSTANT_MethodType_info[signature_index: " + descriptor_index + "]";
}
public <R, D> R accept(Visitor<R, D> visitor, D data) {
return visitor.visitMethodType(this, data);
}
public String getType() throws ConstantPoolException {
return cp.getUTF8Value(descriptor_index);
}
public final int descriptor_index;
}
public static class CONSTANT_Methodref_info extends CPRefInfo {
CONSTANT_Methodref_info(ConstantPool cp, ClassReader cr) throws IOException {
super(cp, cr, CONSTANT_Methodref);
......@@ -729,5 +911,4 @@ public class ConstantPool {
public final String value;
}
}
/*
* Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2009, 2011 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
......@@ -626,10 +626,26 @@ public class Dependencies {
return visitRef(info, p);
}
public Void visitInvokeDynamic(CONSTANT_InvokeDynamic_info info, Void p) {
return null;
}
public Void visitLong(CONSTANT_Long_info info, Void p) {
return null;
}
public Void visitMethodHandle(CONSTANT_MethodHandle_info info, Void p) {
return null;
}
public Void visitMethodType(CONSTANT_MethodType_info info, Void p) {
return null;
}
public Void visitMethodref(CONSTANT_Methodref_info info, Void p) {
return visitRef(info, p);
}
public Void visitNameAndType(CONSTANT_NameAndType_info info, Void p) {
try {
new Signature(info.type_index).getType(constant_pool).accept(this, null);
......@@ -639,10 +655,6 @@ public class Dependencies {
}
}
public Void visitMethodref(CONSTANT_Methodref_info info, Void p) {
return visitRef(info, p);
}
public Void visitString(CONSTANT_String_info info, Void p) {
return null;
}
......
......@@ -755,22 +755,30 @@ public class HtmlTree extends Content {
if (!isInline() && !endsWithNewLine(contentBuilder))
contentBuilder.append(DocletConstants.NL);
String tagString = htmlTag.toString();
contentBuilder.append("<" + tagString);
contentBuilder.append("<");
contentBuilder.append(tagString);
Iterator<HtmlAttr> iterator = attrs.keySet().iterator();
HtmlAttr key;
String value = "";
while (iterator.hasNext()) {
key = iterator.next();
value = attrs.get(key);
contentBuilder.append(" " + key.toString());
if (!value.isEmpty())
contentBuilder.append("=\"" + value + "\"");
contentBuilder.append(" ");
contentBuilder.append(key.toString());
if (!value.isEmpty()) {
contentBuilder.append("=\"");
contentBuilder.append(value);
contentBuilder.append("\"");
}
}
contentBuilder.append(">");
for (Content c : content)
c.write(contentBuilder);
if (htmlTag.endTagRequired())
contentBuilder.append("</" + tagString + ">");
if (htmlTag.endTagRequired()) {
contentBuilder.append("</");
contentBuilder.append(tagString);
contentBuilder.append(">");
}
if (!isInline())
contentBuilder.append(DocletConstants.NL);
}
......
......@@ -99,8 +99,24 @@ public abstract class Content {
* @param contentBuilder content to test for newline character at the end
* @return true if the content ends with newline.
*/
public boolean endsWithNewLine(StringBuilder contentBuilder) {
return ((contentBuilder.length() == 0) ||
(contentBuilder.toString().endsWith(DocletConstants.NL)));
protected boolean endsWithNewLine(StringBuilder contentBuilder) {
int contentLength = contentBuilder.length();
if (contentLength == 0) {
return true;
}
int nlLength = DocletConstants.NL.length();
if (contentLength < nlLength) {
return false;
}
int contentIndex = contentLength - 1;
int nlIndex = nlLength - 1;
while (nlIndex >= 0) {
if (contentBuilder.charAt(contentIndex) != DocletConstants.NL.charAt(nlIndex)) {
return false;
}
contentIndex--;
nlIndex--;
}
return true;
}
}
/*
* Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -43,12 +43,6 @@ import java.lang.reflect.*;
*/
public class Main {
static {
ClassLoader loader = Main.class.getClassLoader();
if (loader != null)
loader.setPackageAssertionStatus("com.sun.tools.javac", true);
}
/** Unsupported command line interface.
* @param args The command line parameters.
*/
......
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2011, 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
......@@ -204,21 +204,6 @@ public abstract class Attribute implements AnnotationValue {
}
}
public static class TypeCompound extends Compound {
public TypeAnnotationPosition position;
public TypeCompound(Compound compound,
TypeAnnotationPosition position) {
this(compound.type, compound.values, position);
}
public TypeCompound(Type type,
List<Pair<MethodSymbol, Attribute>> values,
TypeAnnotationPosition position) {
super(type, values);
this.position = position;
}
}
/** The value for an annotation element of an array type.
*/
public static class Array extends Attribute {
......@@ -255,8 +240,7 @@ public abstract class Attribute implements AnnotationValue {
public VarSymbol value;
public Enum(Type type, VarSymbol value) {
super(type);
assert value != null;
this.value = value;
this.value = Assert.checkNonNull(value);
}
public void accept(Visitor v) { v.visitEnum(this); }
public String toString() {
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -133,7 +133,7 @@ public class Scope {
*/
private Scope(Scope next, Symbol owner, Entry[] table, ScopeCounter scopeCounter) {
this.next = next;
assert emptyScope == null || owner != null;
Assert.check(emptyScope == null || owner != null);
this.owner = owner;
this.table = table;
this.hashMask = table.length - 1;
......@@ -191,16 +191,16 @@ public class Scope {
* with next.
*/
public Scope leave() {
assert shared == 0;
Assert.check(shared == 0);
if (table != next.table) return next;
while (elems != null) {
int hash = getIndex(elems.sym.name);
Entry e = table[hash];
assert e == elems : elems.sym;
Assert.check(e == elems, elems.sym);
table[hash] = elems.shadowed;
elems = elems.sibling;
}
assert next.shared > 0;
Assert.check(next.shared > 0);
next.shared--;
next.nelems = nelems;
// System.out.println("====> leaving scope " + this.hashCode() + " owned by " + this.owner + " to " + next.hashCode());
......@@ -211,12 +211,12 @@ public class Scope {
/** Double size of hash table.
*/
private void dble() {
assert shared == 0;
Assert.check(shared == 0);
Entry[] oldtable = table;
Entry[] newtable = new Entry[oldtable.length * 2];
for (Scope s = this; s != null; s = s.next) {
if (s.table == oldtable) {
assert s == this || s.shared != 0;
Assert.check(s == this || s.shared != 0);
s.table = newtable;
s.hashMask = newtable.length - 1;
}
......@@ -237,7 +237,7 @@ public class Scope {
/** Enter symbol sym in this scope.
*/
public void enter(Symbol sym) {
assert shared == 0;
Assert.check(shared == 0);
enter(sym, this);
}
......@@ -251,7 +251,7 @@ public class Scope {
* arguments are only used in import scopes.
*/
public void enter(Symbol sym, Scope s, Scope origin) {
assert shared == 0;
Assert.check(shared == 0);
if (nelems * 3 >= hashMask * 2)
dble();
int hash = getIndex(sym.name);
......@@ -274,7 +274,7 @@ public class Scope {
* attribute tells us that the class isn't a package member.
*/
public void remove(Symbol sym) {
assert shared == 0;
Assert.check(shared == 0);
Entry e = lookup(sym.name);
if (e.scope == null) return;
......@@ -314,7 +314,7 @@ public class Scope {
/** Enter symbol sym in this scope if not already there.
*/
public void enterIfAbsent(Symbol sym) {
assert shared == 0;
Assert.check(shared == 0);
Entry e = lookup(sym.name);
while (e.scope == this && e.sym.kind != sym.kind) e = e.next();
if (e.scope != this) enter(sym);
......
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -81,8 +81,7 @@ public abstract class Symbol implements Element {
* method to make sure that the class symbol is loaded.
*/
public List<Attribute.Compound> getAnnotationMirrors() {
assert attributes_field != null;
return attributes_field;
return Assert.checkNonNull(attributes_field);
}
/** Fetch a particular annotation from a symbol. */
......@@ -100,17 +99,6 @@ public abstract class Symbol implements Element {
*/
public Type type;
/** The type annotations targeted to a tree directly owned by this symbol
*/
// type annotations are stored here for two purposes:
// - convenient location to store annotations for generation after erasure
// - a private interface for accessing type annotations parsed from
// classfiles
// the field is populated for the following declaration only
// class, field, variable and type parameters
//
public List<Attribute.TypeCompound> typeAnnotations;
/** The owner of this symbol.
*/
public Symbol owner;
......@@ -133,7 +121,6 @@ public abstract class Symbol implements Element {
this.completer = null;
this.erasure_field = null;
this.attributes_field = List.nil();
this.typeAnnotations = List.nil();
this.name = name;
}
......@@ -608,7 +595,7 @@ public abstract class Symbol implements Element {
}
public <R, P> R accept(ElementVisitor<R, P> v, P p) {
assert type.tag == TYPEVAR; // else override will be invoked
Assert.check(type.tag == TYPEVAR); // else override will be invoked
return v.visitTypeParameter(this, p);
}
......@@ -682,8 +669,7 @@ public abstract class Symbol implements Element {
if (attributes_field.isEmpty())
attributes_field = package_info.attributes_field;
}
assert attributes_field != null;
return attributes_field;
return Assert.checkNonNull(attributes_field);
}
/** A package "exists" if a type or package that exists has
......@@ -780,8 +766,7 @@ public abstract class Symbol implements Element {
public List<Attribute.Compound> getAnnotationMirrors() {
if (completer != null) complete();
assert attributes_field != null;
return attributes_field;
return Assert.checkNonNull(attributes_field);
}
public Type erasure(Types types) {
......@@ -1032,7 +1017,7 @@ public abstract class Symbol implements Element {
}
public void setData(Object data) {
assert !(data instanceof Env<?>) : this;
Assert.check(!(data instanceof Env<?>), this);
this.data = data;
}
......@@ -1064,7 +1049,7 @@ public abstract class Symbol implements Element {
*/
public MethodSymbol(long flags, Name name, Type type, Symbol owner) {
super(MTH, flags, name, type, owner);
assert owner.type.tag != TYPEVAR : owner + "." + name;
if (owner.type.tag == TYPEVAR) Assert.error(owner + "." + name);
}
/** Clone this symbol with new owner.
......
......@@ -126,7 +126,6 @@ public class Symtab {
public final Type serializableType;
public final Type methodHandleType;
public final Type polymorphicSignatureType;
public final Type invokeDynamicType;
public final Type throwableType;
public final Type errorType;
public final Type illegalArgumentExceptionType;
......@@ -422,7 +421,6 @@ public class Symtab {
serializableType = enterClass("java.io.Serializable");
methodHandleType = enterClass("java.dyn.MethodHandle");
polymorphicSignatureType = enterClass("java.dyn.MethodHandle$PolymorphicSignature");
invokeDynamicType = enterClass("java.dyn.InvokeDynamic");
errorType = enterClass("java.lang.Error");
illegalArgumentExceptionType = enterClass("java.lang.IllegalArgumentException");
exceptionType = enterClass("java.lang.Exception");
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -138,7 +138,7 @@ public class Type implements PrimitiveType {
*/
public Type constType(Object constValue) {
final Object value = constValue;
assert tag <= BOOLEAN;
Assert.check(tag <= BOOLEAN);
return new Type(tag, tsym) {
@Override
public Object constValue() {
......@@ -202,13 +202,13 @@ public class Type implements PrimitiveType {
* The constant value of this type, converted to String
*/
public String stringValue() {
assert constValue() != null;
Object cv = Assert.checkNonNull(constValue());
if (tag == BOOLEAN)
return ((Integer) constValue()).intValue() == 0 ? "false" : "true";
return ((Integer) cv).intValue() == 0 ? "false" : "true";
else if (tag == CHAR)
return String.valueOf((char) ((Integer) constValue()).intValue());
return String.valueOf((char) ((Integer) cv).intValue());
else
return constValue().toString();
return cv.toString();
}
/**
......@@ -365,6 +365,16 @@ public class Type implements PrimitiveType {
return false;
}
public static List<Type> filter(List<Type> ts, Filter<Type> tf) {
ListBuffer<Type> buf = ListBuffer.lb();
for (Type t : ts) {
if (tf.accepts(t)) {
buf.append(t);
}
}
return buf.toList();
}
public boolean isSuperBound() { return false; }
public boolean isExtendsBound() { return false; }
public boolean isUnbound() { return false; }
......@@ -428,9 +438,8 @@ public class Type implements PrimitiveType {
public WildcardType(Type type, BoundKind kind, TypeSymbol tsym) {
super(WILDCARD, tsym);
assert(type != null);
this.type = Assert.checkNonNull(type);
this.kind = kind;
this.type = type;
}
public WildcardType(WildcardType t, TypeVar bound) {
this(t.type, t.kind, t.tsym, bound);
......@@ -1021,9 +1030,8 @@ public class Type implements PrimitiveType {
Type lower,
WildcardType wildcard) {
super(name, owner, lower);
assert lower != null;
this.lower = Assert.checkNonNull(lower);
this.bound = upper;
this.lower = lower;
this.wildcard = wildcard;
}
......
/*
* Copyright (c) 2009, 2010, 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. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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.
*/
package com.sun.tools.javac.code;
import javax.lang.model.element.ElementKind;
import com.sun.tools.javac.code.Symbol.VarSymbol;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.tree.TreeScanner;
import com.sun.tools.javac.tree.JCTree.*;
import com.sun.tools.javac.util.Context;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.util.ListBuffer;
/**
* Contains operations specific to processing type annotations
*/
public class TypeAnnotations {
private static final Context.Key<TypeAnnotations> key
= new Context.Key<TypeAnnotations>();
public static TypeAnnotations instance(Context context) {
TypeAnnotations instance = context.get(key);
if (instance == null)
instance = new TypeAnnotations(context);
return instance;
}
protected TypeAnnotations(Context context) {
context.put(key, this);
}
public void taFillAndLift(JCClassDecl tree, boolean visitBodies) {
//308 new TypeAnnotationPositions().scan(tree);
//308 new TypeAnnotationLift().scan(tree);
}
private static class TypeAnnotationPositions extends TreeScanner {
private ListBuffer<JCTree> frames = ListBuffer.lb();
private void push(JCTree t) { frames = frames.prepend(t); }
private JCTree pop() { return frames.next(); }
private JCTree peek2() { return frames.toList().tail.head; }
@Override
public void scan(JCTree tree) {
push(tree);
super.scan(tree);
pop();
}
private boolean inClass = false;
@Override
public void visitClassDef(JCClassDecl tree) {
if (!inClass) {
// Do not recurse into nested and inner classes since
// TransTypes.visitClassDef makes an invocation for each class
// separately.
inClass = true;
try {
super.visitClassDef(tree);
} finally {
inClass = false;
}
}
}
private TypeAnnotationPosition resolveFrame(JCTree tree, JCTree frame,
List<JCTree> path, TypeAnnotationPosition p) {
switch (frame.getKind()) {
case TYPE_CAST:
p.type = TargetType.TYPECAST;
p.pos = frame.pos;
return p;
case INSTANCE_OF:
p.type = TargetType.INSTANCEOF;
p.pos = frame.pos;
return p;
case NEW_CLASS:
p.type = TargetType.NEW;
p.pos = frame.pos;
return p;
case NEW_ARRAY:
p.type = TargetType.NEW;
p.pos = frame.pos;
return p;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
p.pos = frame.pos;
if (((JCClassDecl)frame).extending == tree) {
p.type = TargetType.CLASS_EXTENDS;
p.type_index = -1;
} else if (((JCClassDecl)frame).implementing.contains(tree)) {
p.type = TargetType.CLASS_EXTENDS;
p.type_index = ((JCClassDecl)frame).implementing.indexOf(tree);
} else if (((JCClassDecl)frame).typarams.contains(tree)) {
p.type = TargetType.CLASS_TYPE_PARAMETER;
p.parameter_index = ((JCClassDecl)frame).typarams.indexOf(tree);
} else
throw new AssertionError();
return p;
case METHOD: {
JCMethodDecl frameMethod = (JCMethodDecl)frame;
p.pos = frame.pos;
if (frameMethod.receiverAnnotations.contains(tree))
p.type = TargetType.METHOD_RECEIVER;
else if (frameMethod.thrown.contains(tree)) {
p.type = TargetType.THROWS;
p.type_index = frameMethod.thrown.indexOf(tree);
} else if (((JCMethodDecl)frame).restype == tree) {
p.type = TargetType.METHOD_RETURN_GENERIC_OR_ARRAY;
} else if (frameMethod.typarams.contains(tree)) {
p.type = TargetType.METHOD_TYPE_PARAMETER;
p.parameter_index = frameMethod.typarams.indexOf(tree);
} else
throw new AssertionError();
return p;
}
case MEMBER_SELECT: {
JCFieldAccess fieldFrame = (JCFieldAccess)frame;
if ("class".contentEquals(fieldFrame.name)) {
p.type = TargetType.CLASS_LITERAL;
p.pos = TreeInfo.innermostType(fieldFrame.selected).pos;
} else
throw new AssertionError();
return p;
}
case PARAMETERIZED_TYPE: {
TypeAnnotationPosition nextP;
if (((JCTypeApply)frame).clazz == tree)
nextP = p; // generic: RAW; noop
else if (((JCTypeApply)frame).arguments.contains(tree))
p.location = p.location.prepend(
((JCTypeApply)frame).arguments.indexOf(tree));
else
throw new AssertionError();
List<JCTree> newPath = path.tail;
return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
}
case ARRAY_TYPE: {
p.location = p.location.prepend(0);
List<JCTree> newPath = path.tail;
return resolveFrame(newPath.head, newPath.tail.head, newPath, p);
}
case TYPE_PARAMETER:
if (path.tail.tail.head.getTag() == JCTree.CLASSDEF) {
JCClassDecl clazz = (JCClassDecl)path.tail.tail.head;
p.type = TargetType.CLASS_TYPE_PARAMETER_BOUND;
p.parameter_index = clazz.typarams.indexOf(path.tail.head);
p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
} else if (path.tail.tail.head.getTag() == JCTree.METHODDEF) {
JCMethodDecl method = (JCMethodDecl)path.tail.tail.head;
p.type = TargetType.METHOD_TYPE_PARAMETER_BOUND;
p.parameter_index = method.typarams.indexOf(path.tail.head);
p.bound_index = ((JCTypeParameter)frame).bounds.indexOf(tree);
} else
throw new AssertionError();
p.pos = frame.pos;
return p;
case VARIABLE:
VarSymbol v = ((JCVariableDecl)frame).sym;
p.pos = frame.pos;
switch (v.getKind()) {
case LOCAL_VARIABLE:
p.type = TargetType.LOCAL_VARIABLE; break;
case FIELD:
p.type = TargetType.FIELD_GENERIC_OR_ARRAY; break;
case PARAMETER:
p.type = TargetType.METHOD_PARAMETER_GENERIC_OR_ARRAY;
p.parameter_index = methodParamIndex(path, frame);
break;
default: throw new AssertionError();
}
return p;
//308 case ANNOTATED_TYPE: {
//308 List<JCTree> newPath = path.tail;
//308 return resolveFrame(newPath.head, newPath.tail.head,
//308 newPath, p);
//308 }
case METHOD_INVOCATION: {
JCMethodInvocation invocation = (JCMethodInvocation)frame;
if (!invocation.typeargs.contains(tree))
throw new AssertionError("{" + tree + "} is not an argument in the invocation: " + invocation);
p.type = TargetType.METHOD_TYPE_ARGUMENT;
p.pos = invocation.pos;
p.type_index = invocation.typeargs.indexOf(tree);
return p;
}
case EXTENDS_WILDCARD:
case SUPER_WILDCARD: {
p.type = TargetType.WILDCARD_BOUND;
List<JCTree> newPath = path.tail;
TypeAnnotationPosition wildcard =
resolveFrame(newPath.head, newPath.tail.head, newPath,
new TypeAnnotationPosition());
if (!wildcard.location.isEmpty())
wildcard.type = wildcard.type.getGenericComplement();
p.wildcard_position = wildcard;
p.pos = frame.pos;
return p;
}
}
return p;
}
private void setTypeAnnotationPos(List<JCTypeAnnotation> annotations, TypeAnnotationPosition position) {
for (JCTypeAnnotation anno : annotations) {
anno.annotation_position = position;
anno.attribute_field.position = position;
}
}
@Override
public void visitNewArray(JCNewArray tree) {
findPosition(tree, tree, tree.annotations);
int dimAnnosCount = tree.dimAnnotations.size();
// handle annotations associated with dimentions
for (int i = 0; i < dimAnnosCount; ++i) {
TypeAnnotationPosition p = new TypeAnnotationPosition();
p.type = TargetType.NEW_GENERIC_OR_ARRAY;
p.pos = tree.pos;
p.location = p.location.append(i);
setTypeAnnotationPos(tree.dimAnnotations.get(i), p);
}
// handle "free" annotations
int i = dimAnnosCount == 0 ? 0 : dimAnnosCount - 1;
JCExpression elemType = tree.elemtype;
while (elemType != null) {
if (elemType.getTag() == JCTree.ANNOTATED_TYPE) {
JCAnnotatedType at = (JCAnnotatedType)elemType;
TypeAnnotationPosition p = new TypeAnnotationPosition();
p.type = TargetType.NEW_GENERIC_OR_ARRAY;
p.pos = tree.pos;
p.location = p.location.append(i);
setTypeAnnotationPos(at.annotations, p);
elemType = at.underlyingType;
} else if (elemType.getTag() == JCTree.TYPEARRAY) {
++i;
elemType = ((JCArrayTypeTree)elemType).elemtype;
} else
break;
}
// find annotations locations of initializer elements
scan(tree.elems);
}
@Override
public void visitAnnotatedType(JCAnnotatedType tree) {
findPosition(tree, peek2(), tree.annotations);
super.visitAnnotatedType(tree);
}
@Override
public void visitMethodDef(JCMethodDecl tree) {
TypeAnnotationPosition p = new TypeAnnotationPosition();
p.type = TargetType.METHOD_RECEIVER;
setTypeAnnotationPos(tree.receiverAnnotations, p);
super.visitMethodDef(tree);
}
@Override
public void visitTypeParameter(JCTypeParameter tree) {
findPosition(tree, peek2(), tree.annotations);
super.visitTypeParameter(tree);
}
void findPosition(JCTree tree, JCTree frame, List<JCTypeAnnotation> annotations) {
if (!annotations.isEmpty()) {
TypeAnnotationPosition p =
resolveFrame(tree, frame, frames.toList(),
new TypeAnnotationPosition());
if (!p.location.isEmpty())
p.type = p.type.getGenericComplement();
setTypeAnnotationPos(annotations, p);
}
}
private int methodParamIndex(List<JCTree> path, JCTree param) {
List<JCTree> curr = path;
if (curr.head != param)
curr = path.tail;
JCMethodDecl method = (JCMethodDecl)curr.tail.head;
return method.params.indexOf(param);
}
}
private static class TypeAnnotationLift extends TreeScanner {
List<Attribute.TypeCompound> recordedTypeAnnotations = List.nil();
boolean isInner = false;
@Override
public void visitClassDef(JCClassDecl tree) {
if (isInner) {
// tree is an inner class tree. stop now.
// TransTypes.visitClassDef makes an invocation for each class
// separately.
return;
}
isInner = true;
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
recordedTypeAnnotations = List.nil();
try {
super.visitClassDef(tree);
} finally {
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
recordedTypeAnnotations = prevTAs;
}
}
@Override
public void visitMethodDef(JCMethodDecl tree) {
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
recordedTypeAnnotations = List.nil();
try {
super.visitMethodDef(tree);
} finally {
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
recordedTypeAnnotations = prevTAs;
}
}
@Override
public void visitVarDef(JCVariableDecl tree) {
List<Attribute.TypeCompound> prevTAs = recordedTypeAnnotations;
recordedTypeAnnotations = List.nil();
ElementKind kind = tree.sym.getKind();
if (kind == ElementKind.LOCAL_VARIABLE && tree.mods.annotations.nonEmpty()) {
// need to lift the annotations
TypeAnnotationPosition position = new TypeAnnotationPosition();
position.pos = tree.pos;
position.type = TargetType.LOCAL_VARIABLE;
for (Attribute.Compound attribute : tree.sym.attributes_field) {
Attribute.TypeCompound tc =
new Attribute.TypeCompound(attribute.type, attribute.values, position);
recordedTypeAnnotations = recordedTypeAnnotations.append(tc);
}
}
try {
super.visitVarDef(tree);
} finally {
if (kind.isField() || kind == ElementKind.LOCAL_VARIABLE)
tree.sym.typeAnnotations = tree.sym.typeAnnotations.appendList(recordedTypeAnnotations);
recordedTypeAnnotations = kind.isField() ? prevTAs : prevTAs.appendList(recordedTypeAnnotations);
}
}
@Override
public void visitApply(JCMethodInvocation tree) {
scan(tree.meth);
scan(tree.typeargs);
scan(tree.args);
}
public void visitAnnotation(JCAnnotation tree) {
if (tree instanceof JCTypeAnnotation)
recordedTypeAnnotations = recordedTypeAnnotations.append(((JCTypeAnnotation)tree).attribute_field);
super.visitAnnotation(tree);
}
}
}
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2011, 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
......@@ -1061,8 +1061,9 @@ public class Types {
highSub = (lowSub == null) ? null : asSub(bHigh, aHigh.tsym);
}
if (highSub != null) {
assert a.tsym == highSub.tsym && a.tsym == lowSub.tsym
: a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym;
if (!(a.tsym == highSub.tsym && a.tsym == lowSub.tsym)) {
Assert.error(a.tsym + " != " + highSub.tsym + " != " + lowSub.tsym);
}
if (!disjointTypes(aHigh.allparams(), highSub.allparams())
&& !disjointTypes(aHigh.allparams(), lowSub.allparams())
&& !disjointTypes(aLow.allparams(), highSub.allparams())
......@@ -1703,9 +1704,9 @@ public class Types {
bt.supertype_field = bounds.head;
bt.interfaces_field = bounds.tail;
}
assert bt.supertype_field.tsym.completer != null
|| !bt.supertype_field.isInterface()
: bt.supertype_field;
Assert.check(bt.supertype_field.tsym.completer != null
|| !bt.supertype_field.isInterface(),
bt.supertype_field);
return bt;
}
......@@ -1834,7 +1835,7 @@ public class Types {
// t.interfaces_field is null after
// completion, we can assume that t is not the
// type of a class/interface declaration.
assert t != t.tsym.type : t.toString();
Assert.check(t != t.tsym.type, t);
List<Type> actuals = t.allparams();
List<Type> formals = t.tsym.type.allparams();
if (t.hasErasedSupertypes()) {
......@@ -2646,7 +2647,7 @@ public class Types {
act2 = act2.tail;
typarams = typarams.tail;
}
assert(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty());
Assert.check(act1.isEmpty() && act2.isEmpty() && typarams.isEmpty());
return new ClassType(class1.getEnclosingType(), merged.toList(), class1.tsym);
}
......@@ -2758,7 +2759,7 @@ public class Types {
// calculate lub(A, B)
while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR)
ts = ts.tail;
assert !ts.isEmpty();
Assert.check(!ts.isEmpty());
List<Type> cl = closure(ts.head);
for (Type t : ts.tail) {
if (t.tag == CLASS || t.tag == TYPEVAR)
......@@ -3138,7 +3139,7 @@ public class Types {
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
assert (from.tsym.flags() & INTERFACE) != 0;
Assert.check((from.tsym.flags() & INTERFACE) != 0);
reverse = true;
to = from;
from = target;
......@@ -3173,12 +3174,12 @@ public class Types {
boolean reverse = false;
Type target = to;
if ((to.tsym.flags() & INTERFACE) == 0) {
assert (from.tsym.flags() & INTERFACE) != 0;
Assert.check((from.tsym.flags() & INTERFACE) != 0);
reverse = true;
to = from;
from = target;
}
assert (from.tsym.flags() & FINAL) != 0;
Assert.check((from.tsym.flags() & FINAL) != 0);
Type t1 = asSuper(from, to.tsym);
if (t1 == null) return false;
Type t2 = to;
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -563,7 +563,7 @@ public class Attr extends JCTree.Visitor {
if (bound != null && bound.tsym instanceof ClassSymbol) {
ClassSymbol c = (ClassSymbol)bound.tsym;
if ((c.flags_field & COMPOUND) != 0) {
assert (c.flags_field & UNATTRIBUTED) != 0 : c;
Assert.check((c.flags_field & UNATTRIBUTED) != 0, c);
attribClass(typaram.pos(), c);
}
}
......@@ -905,7 +905,10 @@ public class Attr extends JCTree.Visitor {
// or perhaps expr implements Iterable<T>?
Type base = types.asSuper(exprType, syms.iterableType.tsym);
if (base == null) {
log.error(tree.expr.pos(), "foreach.not.applicable.to.type");
log.error(tree.expr.pos(),
"foreach.not.applicable.to.type",
exprType,
diags.fragment("type.req.array.or.iterable"));
elemtype = types.createErrorType(exprType);
} else {
List<Type> iterableParams = base.allparams();
......@@ -970,7 +973,7 @@ public class Attr extends JCTree.Visitor {
if (enumSwitch) {
Symbol sym = enumConstant(c.pat, seltype);
if (sym == null) {
log.error(c.pat.pos(), "enum.const.req");
log.error(c.pat.pos(), "enum.label.must.be.unqualified.enum");
} else if (!labels.add(sym)) {
log.error(c.pos(), "duplicate.case.label");
}
......@@ -1334,7 +1337,6 @@ public class Attr extends JCTree.Visitor {
// The types of the actual method type arguments.
List<Type> typeargtypes = null;
boolean typeargtypesNonRefOK = false;
Name methName = TreeInfo.name(tree.meth);
......@@ -1434,7 +1436,7 @@ public class Attr extends JCTree.Visitor {
localEnv.info.varArgs = false;
Type mtype = attribExpr(tree.meth, localEnv, mpt);
if (localEnv.info.varArgs)
assert mtype.isErroneous() || tree.varargsElement != null;
Assert.check(mtype.isErroneous() || tree.varargsElement != null);
// Compute the result type.
Type restype = mtype.getReturnType();
......@@ -1463,21 +1465,7 @@ public class Attr extends JCTree.Visitor {
restype.tsym);
}
// Special case logic for JSR 292 types.
if (rs.allowTransitionalJSR292 &&
tree.meth.getTag() == JCTree.SELECT &&
!typeargtypes.isEmpty()) {
JCFieldAccess mfield = (JCFieldAccess) tree.meth;
// MethodHandle.<T>invoke(abc) and InvokeDynamic.<T>foo(abc)
// has type <T>, and T can be a primitive type.
if (mfield.sym != null &&
mfield.sym.isPolymorphicSignatureInstance())
typeargtypesNonRefOK = true;
}
if (!(rs.allowTransitionalJSR292 && typeargtypesNonRefOK)) {
chk.checkRefTypes(tree.typeargs, typeargtypes);
}
chk.checkRefTypes(tree.typeargs, typeargtypes);
// Check that value of resulting type is admissible in the
// current context. Also, capture the return type
......@@ -1667,7 +1655,7 @@ public class Attr extends JCTree.Visitor {
typeargtypes,
localEnv.info.varArgs);
if (localEnv.info.varArgs)
assert tree.constructorType.isErroneous() || tree.varargsElement != null;
Assert.check(tree.constructorType.isErroneous() || tree.varargsElement != null);
}
if (cdef != null) {
......@@ -1727,7 +1715,7 @@ public class Attr extends JCTree.Visitor {
Symbol sym = rs.resolveConstructor(
tree.pos(), localEnv, clazztype, argtypes,
typeargtypes, true, tree.varargsElement != null);
assert sym.kind < AMBIGUOUS || tree.constructor.type.isErroneous();
Assert.check(sym.kind < AMBIGUOUS || tree.constructor.type.isErroneous());
tree.constructor = sym;
if (tree.constructor.kind > ERRONEOUS) {
tree.constructorType = syms.errType;
......@@ -2243,10 +2231,10 @@ public class Attr extends JCTree.Visitor {
// Determine the symbol represented by the selection.
env.info.varArgs = false;
Symbol sym = selectSym(tree, site, env, pt, pkind);
Symbol sym = selectSym(tree, sitesym, site, env, pt, pkind);
if (sym.exists() && !isType(sym) && (pkind & (PCK | TYP)) != 0) {
site = capture(site);
sym = selectSym(tree, site, env, pt, pkind);
sym = selectSym(tree, sitesym, site, env, pt, pkind);
}
boolean varArgs = env.info.varArgs;
tree.sym = sym;
......@@ -2335,6 +2323,14 @@ public class Attr extends JCTree.Visitor {
* @param pkind The expected kind(s) of the Select expression.
*/
private Symbol selectSym(JCFieldAccess tree,
Type site,
Env<AttrContext> env,
Type pt,
int pkind) {
return selectSym(tree, site.tsym, site, env, pt, pkind);
}
private Symbol selectSym(JCFieldAccess tree,
Symbol location,
Type site,
Env<AttrContext> env,
Type pt,
......@@ -2346,12 +2342,12 @@ public class Attr extends JCTree.Visitor {
case PACKAGE:
return rs.access(
rs.findIdentInPackage(env, site.tsym, name, pkind),
pos, site, name, true);
pos, location, site, name, true);
case ARRAY:
case CLASS:
if (pt.tag == METHOD || pt.tag == FORALL) {
return rs.resolveQualifiedMethod(
pos, env, site, name, pt.getParameterTypes(), pt.getTypeArguments());
pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
} else if (name == names._this || name == names._super) {
return rs.resolveSelf(pos, env, site.tsym, name);
} else if (name == names._class) {
......@@ -2368,7 +2364,7 @@ public class Attr extends JCTree.Visitor {
// We are seeing a plain identifier as selector.
Symbol sym = rs.findIdentInType(env, site, name, pkind);
if ((pkind & ERRONEOUS) == 0)
sym = rs.access(sym, pos, site, name, true);
sym = rs.access(sym, pos, location, site, name, true);
return sym;
}
case WILDCARD:
......@@ -2376,12 +2372,12 @@ public class Attr extends JCTree.Visitor {
case TYPEVAR:
// Normally, site.getUpperBound() shouldn't be null.
// It should only happen during memberEnter/attribBase
// when determining the super type which *must* be
// when determining the super type which *must* beac
// done before attributing the type variables. In
// other words, we are seeing this illegal program:
// class B<T> extends A<T.foo> {}
Symbol sym = (site.getUpperBound() != null)
? selectSym(tree, capture(site.getUpperBound()), env, pt, pkind)
? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind)
: null;
if (sym == null) {
log.error(pos, "type.var.cant.be.deref");
......@@ -2390,7 +2386,7 @@ public class Attr extends JCTree.Visitor {
Symbol sym2 = (sym.flags() & Flags.PRIVATE) != 0 ?
rs.new AccessError(env, site, sym) :
sym;
rs.access(sym2, pos, site, name, true);
rs.access(sym2, pos, location, site, name, true);
return sym;
}
case ERROR:
......@@ -2961,7 +2957,7 @@ public class Attr extends JCTree.Visitor {
extending, implementing, List.<JCTree>nil());
ClassSymbol c = (ClassSymbol)a.getUpperBound().tsym;
assert (c.flags() & COMPOUND) != 0;
Assert.check((c.flags() & COMPOUND) != 0);
cd.sym = c;
c.sourcefile = env.toplevel.sourcefile;
......@@ -2989,10 +2985,6 @@ public class Attr extends JCTree.Visitor {
result = tree.type = syms.errType;
}
public void visitAnnotatedType(JCAnnotatedType tree) {
result = tree.type = attribType(tree.getUnderlyingType(), env);
}
public void visitErroneous(JCErroneous tree) {
if (tree.errs != null)
for (JCTree err : tree.errs)
......@@ -3097,7 +3089,7 @@ public class Attr extends JCTree.Visitor {
/** Finish the attribution of a class. */
private void attribClassBody(Env<AttrContext> env, ClassSymbol c) {
JCClassDecl tree = (JCClassDecl)env.tree;
assert c == tree.sym;
Assert.check(c == tree.sym);
// Validate annotations
chk.validateAnnotations(tree.mods.annotations, c);
......@@ -3138,12 +3130,9 @@ public class Attr extends JCTree.Visitor {
tree.type = c.type;
boolean assertsEnabled = false;
assert assertsEnabled = true;
if (assertsEnabled) {
for (List<JCTypeParameter> l = tree.typarams;
l.nonEmpty(); l = l.tail)
assert env.info.scope.lookup(l.head.name).scope != null;
for (List<JCTypeParameter> l = tree.typarams;
l.nonEmpty(); l = l.tail) {
Assert.checkNonNull(env.info.scope.lookup(l.head.name).scope);
}
// Check that a generic class doesn't extend Throwable
......@@ -3167,7 +3156,7 @@ public class Attr extends JCTree.Visitor {
if (sym == null ||
sym.kind != VAR ||
((VarSymbol) sym).getConstValue() == null)
log.error(l.head.pos(), "icls.cant.have.static.decl");
log.error(l.head.pos(), "icls.cant.have.static.decl", sym.location());
}
}
......@@ -3184,9 +3173,6 @@ public class Attr extends JCTree.Visitor {
(c.flags() & ABSTRACT) == 0) {
checkSerialVersionUID(tree, c);
}
// Check type annotations applicability rules
validateTypeAnnotations(tree);
}
// where
/** check if a class is a subtype of Serializable, if that is available. */
......@@ -3234,35 +3220,6 @@ public class Attr extends JCTree.Visitor {
return types.capture(type);
}
private void validateTypeAnnotations(JCTree tree) {
tree.accept(typeAnnotationsValidator);
}
//where
private final JCTree.Visitor typeAnnotationsValidator =
new TreeScanner() {
public void visitAnnotation(JCAnnotation tree) {
if (tree instanceof JCTypeAnnotation) {
chk.validateTypeAnnotation((JCTypeAnnotation)tree, false);
}
super.visitAnnotation(tree);
}
public void visitTypeParameter(JCTypeParameter tree) {
chk.validateTypeAnnotations(tree.annotations, true);
// don't call super. skip type annotations
scan(tree.bounds);
}
public void visitMethodDef(JCMethodDecl tree) {
// need to check static methods
if ((tree.sym.flags() & Flags.STATIC) != 0) {
for (JCTypeAnnotation a : tree.receiverAnnotations) {
if (chk.isTypeAnnotation(a, false))
log.error(a.pos(), "annotation.type.not.applicable");
}
}
super.visitMethodDef(tree);
}
};
// <editor-fold desc="post-attribution visitor">
/**
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -506,43 +506,18 @@ public class Check {
* @param a The type that should be bounded by bs.
* @param bs The bound.
*/
private void checkExtends(DiagnosticPosition pos, Type a, TypeVar bs) {
private boolean checkExtends(Type a, TypeVar bs) {
if (a.isUnbound()) {
return;
return true;
} else if (a.tag != WILDCARD) {
a = types.upperBound(a);
for (List<Type> l = types.getBounds(bs); l.nonEmpty(); l = l.tail) {
if (!types.isSubtype(a, l.head)) {
log.error(pos, "not.within.bounds", a);
return;
}
}
return types.isSubtype(a, bs.bound);
} else if (a.isExtendsBound()) {
if (!types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings))
log.error(pos, "not.within.bounds", a);
return types.isCastable(bs.getUpperBound(), types.upperBound(a), Warner.noWarnings);
} else if (a.isSuperBound()) {
if (types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound()))
log.error(pos, "not.within.bounds", a);
return !types.notSoftSubtype(types.lowerBound(a), bs.getUpperBound());
}
}
/** Check that a type is within some bounds.
*
* Used in TypeApply to verify that, e.g., X in V<X> is a valid
* type argument.
* @param pos Position to be used for error reporting.
* @param a The type that should be bounded by bs.
* @param bs The bound.
*/
private void checkCapture(JCTypeApply tree) {
List<JCExpression> args = tree.getTypeArguments();
for (Type arg : types.capture(tree.type).getTypeArguments()) {
if (arg.tag == TYPEVAR && arg.getUpperBound().isErroneous()) {
log.error(args.head.pos, "not.within.bounds", args.head.type);
break;
}
args = args.tail;
}
return true;
}
/** Check that type is different from 'void'.
......@@ -775,6 +750,79 @@ public class Check {
}
}
/**
* Check that type 't' is a valid instantiation of a generic class
* (see JLS 4.5)
*
* @param t class type to be checked
* @return true if 't' is well-formed
*/
public boolean checkValidGenericType(Type t) {
return firstIncompatibleTypeArg(t) == null;
}
//WHERE
private Type firstIncompatibleTypeArg(Type type) {
List<Type> formals = type.tsym.type.allparams();
List<Type> actuals = type.allparams();
List<Type> args = type.getTypeArguments();
List<Type> forms = type.tsym.type.getTypeArguments();
ListBuffer<Type> tvars_buf = new ListBuffer<Type>();
// For matching pairs of actual argument types `a' and
// formal type parameters with declared bound `b' ...
while (args.nonEmpty() && forms.nonEmpty()) {
// exact type arguments needs to know their
// bounds (for upper and lower bound
// calculations). So we create new TypeVars with
// bounds substed with actuals.
tvars_buf.append(types.substBound(((TypeVar)forms.head),
formals,
actuals));
args = args.tail;
forms = forms.tail;
}
args = type.getTypeArguments();
List<Type> tvars_cap = types.substBounds(formals,
formals,
types.capture(type).allparams());
while (args.nonEmpty() && tvars_cap.nonEmpty()) {
// Let the actual arguments know their bound
args.head.withTypeVar((TypeVar)tvars_cap.head);
args = args.tail;
tvars_cap = tvars_cap.tail;
}
args = type.getTypeArguments();
List<Type> tvars = tvars_buf.toList();
while (args.nonEmpty() && tvars.nonEmpty()) {
Type actual = types.subst(args.head,
type.tsym.type.getTypeArguments(),
tvars_buf.toList());
if (!checkExtends(actual, (TypeVar)tvars.head) &&
!tvars.head.getUpperBound().isErroneous()) {
return args.head;
}
args = args.tail;
tvars = tvars.tail;
}
args = type.getTypeArguments();
tvars = tvars_buf.toList();
for (Type arg : types.capture(type).getTypeArguments()) {
if (arg.tag == TYPEVAR &&
arg.getUpperBound().isErroneous() &&
!tvars.head.getUpperBound().isErroneous()) {
return args.head;
}
tvars = tvars.tail;
}
return null;
}
/** Check that given modifiers are legal for given symbol and
* return modifiers together with any implicit modififiers for that symbol.
* Warning: we can't use flags() here since this method
......@@ -987,11 +1035,20 @@ public class Check {
@Override
public void visitTypeApply(JCTypeApply tree) {
if (tree.type.tag == CLASS) {
List<Type> formals = tree.type.tsym.type.allparams();
List<Type> actuals = tree.type.allparams();
List<JCExpression> args = tree.arguments;
List<Type> forms = tree.type.tsym.type.getTypeArguments();
ListBuffer<Type> tvars_buf = new ListBuffer<Type>();
Type incompatibleArg = firstIncompatibleTypeArg(tree.type);
if (incompatibleArg != null) {
for (JCTree arg : tree.arguments) {
if (arg.type == incompatibleArg) {
log.error(arg, "not.within.bounds", incompatibleArg, forms.head);
}
forms = forms.tail;
}
}
forms = tree.type.tsym.type.getTypeArguments();
boolean is_java_lang_Class = tree.type.tsym.flatName() == names.java_lang_Class;
......@@ -1001,46 +1058,10 @@ public class Check {
validateTree(args.head,
!(isOuter && is_java_lang_Class),
false);
// exact type arguments needs to know their
// bounds (for upper and lower bound
// calculations). So we create new TypeVars with
// bounds substed with actuals.
tvars_buf.append(types.substBound(((TypeVar)forms.head),
formals,
actuals));
args = args.tail;
forms = forms.tail;
}
args = tree.arguments;
List<Type> tvars_cap = types.substBounds(formals,
formals,
types.capture(tree.type).allparams());
while (args.nonEmpty() && tvars_cap.nonEmpty()) {
// Let the actual arguments know their bound
args.head.type.withTypeVar((TypeVar)tvars_cap.head);
args = args.tail;
tvars_cap = tvars_cap.tail;
}
args = tree.arguments;
List<Type> tvars = tvars_buf.toList();
while (args.nonEmpty() && tvars.nonEmpty()) {
Type actual = types.subst(args.head.type,
tree.type.tsym.type.getTypeArguments(),
tvars_buf.toList());
checkExtends(args.head.pos(),
actual,
(TypeVar)tvars.head);
args = args.tail;
tvars = tvars.tail;
}
checkCapture(tree);
// Check that this type is either fully parameterized, or
// not parameterized at all.
if (tree.type.getEnclosingType().isRaw())
......@@ -1086,11 +1107,6 @@ public class Check {
}
}
@Override
public void visitAnnotatedType(JCAnnotatedType tree) {
tree.underlyingType.accept(this);
}
/** Default visitor method: do nothing.
*/
@Override
......@@ -2239,14 +2255,6 @@ public class Check {
validateAnnotation(a, s);
}
/** Check the type annotations
*/
public void validateTypeAnnotations(List<JCTypeAnnotation> annotations, boolean isTypeParameter) {
if (skipAnnotations) return;
for (JCTypeAnnotation a : annotations)
validateTypeAnnotation(a, isTypeParameter);
}
/** Check an annotation of a symbol.
*/
public void validateAnnotation(JCAnnotation a, Symbol s) {
......@@ -2261,15 +2269,6 @@ public class Check {
}
}
public void validateTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
if (a.type == null)
throw new AssertionError("annotation tree hasn't been attributed yet: " + a);
validateAnnotationTree(a);
if (!isTypeAnnotation(a, isTypeParameter))
log.error(a.pos(), "annotation.type.not.applicable");
}
/** Is s a method symbol that overrides a method in a superclass? */
boolean isOverrider(Symbol s) {
if (s.kind != MTH || s.isStatic())
......@@ -2288,25 +2287,6 @@ public class Check {
return false;
}
/** Is the annotation applicable to type annotations */
boolean isTypeAnnotation(JCTypeAnnotation a, boolean isTypeParameter) {
Attribute.Compound atTarget =
a.annotationType.type.tsym.attribute(syms.annotationTargetType.tsym);
if (atTarget == null) return true;
Attribute atValue = atTarget.member(names.value);
if (!(atValue instanceof Attribute.Array)) return true; // error recovery
Attribute.Array arr = (Attribute.Array) atValue;
for (Attribute app : arr.values) {
if (!(app instanceof Attribute.Enum)) return true; // recovery
Attribute.Enum e = (Attribute.Enum) app;
if (!isTypeParameter && e.value.name == names.TYPE_USE)
return true;
else if (isTypeParameter && e.value.name == names.TYPE_PARAMETER)
return true;
}
return false;
}
/** Is the annotation applicable to the symbol? */
boolean annotationApplicable(JCAnnotation a, Symbol s) {
Attribute.Compound atTarget =
......@@ -2438,7 +2418,7 @@ public class Check {
*/
void checkNonCyclicElements(JCClassDecl tree) {
if ((tree.sym.flags_field & ANNOTATION) == 0) return;
assert (tree.sym.flags_field & LOCKED) == 0;
Assert.check((tree.sym.flags_field & LOCKED) == 0);
try {
tree.sym.flags_field |= LOCKED;
for (JCTree def : tree.defs) {
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -37,7 +37,6 @@ import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
import com.sun.tools.javac.code.Symbol.*;
import com.sun.tools.javac.comp.Resolve;
import com.sun.tools.javac.tree.JCTree.*;
import static com.sun.tools.javac.code.Flags.*;
......@@ -709,7 +708,7 @@ public class Flow extends TreeScanner {
lint = lint.augment(tree.sym.attributes_field);
assert pendingExits.isEmpty();
Assert.check(pendingExits.isEmpty());
try {
boolean isInitialConstructor =
......@@ -747,7 +746,7 @@ public class Flow extends TreeScanner {
PendingExit exit = exits.head;
exits = exits.tail;
if (exit.thrown == null) {
assert exit.tree.getTag() == JCTree.RETURN;
Assert.check(exit.tree.getTag() == JCTree.RETURN);
if (isInitialConstructor) {
inits = exit.inits;
for (int i = firstadr; i < nextadr; i++)
......@@ -1350,11 +1349,6 @@ public class Flow extends TreeScanner {
}
}
public void visitAnnotatedType(JCAnnotatedType tree) {
// annotations don't get scanned
tree.underlyingType.accept(this);
}
public void visitIdent(JCIdent tree) {
if (tree.sym.kind == VAR) {
checkInit(tree.pos(), (VarSymbol)tree.sym);
......@@ -1373,7 +1367,6 @@ public class Flow extends TreeScanner {
if (!tree.type.isErroneous()
&& lint.isEnabled(Lint.LintCategory.CAST)
&& types.isSameType(tree.expr.type, tree.clazz.type)
&& !(ignoreAnnotatedCasts && containsTypeAnnotation(tree.clazz))
&& !is292targetTypeCast(tree)) {
log.warning(Lint.LintCategory.CAST,
tree.pos(), "redundant.cast", tree.expr.type);
......@@ -1382,8 +1375,9 @@ public class Flow extends TreeScanner {
//where
private boolean is292targetTypeCast(JCTypeCast tree) {
boolean is292targetTypeCast = false;
if (tree.expr.getTag() == JCTree.APPLY) {
JCMethodInvocation apply = (JCMethodInvocation)tree.expr;
JCExpression expr = TreeInfo.skipParens(tree.expr);
if (expr.getTag() == JCTree.APPLY) {
JCMethodInvocation apply = (JCMethodInvocation)expr;
Symbol sym = TreeInfo.symbol(apply.meth);
is292targetTypeCast = sym != null &&
sym.kind == MTH &&
......@@ -1396,23 +1390,6 @@ public class Flow extends TreeScanner {
// Do nothing for TopLevel since each class is visited individually
}
/**************************************************************************
* utility methods for ignoring type-annotated casts lint checking
*************************************************************************/
private static final boolean ignoreAnnotatedCasts = true;
private static class AnnotationFinder extends TreeScanner {
public boolean foundTypeAnno = false;
public void visitAnnotation(JCAnnotation tree) {
foundTypeAnno = foundTypeAnno || (tree instanceof JCTypeAnnotation);
}
}
private boolean containsTypeAnnotation(JCTree e) {
AnnotationFinder finder = new AnnotationFinder();
finder.scan(e);
return finder.foundTypeAnno;
}
/**************************************************************************
* main method
*************************************************************************/
......
......@@ -27,6 +27,7 @@ package com.sun.tools.javac.comp;
import com.sun.tools.javac.tree.JCTree;
import com.sun.tools.javac.tree.JCTree.JCTypeCast;
import com.sun.tools.javac.tree.TreeInfo;
import com.sun.tools.javac.util.*;
import com.sun.tools.javac.util.List;
import com.sun.tools.javac.code.*;
......@@ -204,19 +205,20 @@ public class Infer {
* Throw a NoInstanceException if this not possible.
*/
void maximizeInst(UndetVar that, Warner warn) throws NoInstanceException {
List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
if (that.inst == null) {
if (that.hibounds.isEmpty())
if (hibounds.isEmpty())
that.inst = syms.objectType;
else if (that.hibounds.tail.isEmpty())
that.inst = that.hibounds.head;
else if (hibounds.tail.isEmpty())
that.inst = hibounds.head;
else
that.inst = types.glb(that.hibounds);
that.inst = types.glb(hibounds);
}
if (that.inst == null ||
that.inst.isErroneous())
throw ambiguousNoInstanceException
.setMessage("no.unique.maximal.instance.exists",
that.qtype, that.hibounds);
that.qtype, hibounds);
}
//where
private boolean isSubClass(Type t, final List<Type> ts) {
......@@ -240,37 +242,46 @@ public class Infer {
return true;
}
private Filter<Type> errorFilter = new Filter<Type>() {
@Override
public boolean accepts(Type t) {
return !t.isErroneous();
}
};
/** Instantiate undetermined type variable to the lub of all its lower bounds.
* Throw a NoInstanceException if this not possible.
*/
void minimizeInst(UndetVar that, Warner warn) throws NoInstanceException {
List<Type> lobounds = Type.filter(that.lobounds, errorFilter);
if (that.inst == null) {
if (that.lobounds.isEmpty())
if (lobounds.isEmpty())
that.inst = syms.botType;
else if (that.lobounds.tail.isEmpty())
that.inst = that.lobounds.head.isPrimitive() ? syms.errType : that.lobounds.head;
else if (lobounds.tail.isEmpty())
that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head;
else {
that.inst = types.lub(that.lobounds);
that.inst = types.lub(lobounds);
}
if (that.inst == null || that.inst.tag == ERROR)
throw ambiguousNoInstanceException
.setMessage("no.unique.minimal.instance.exists",
that.qtype, that.lobounds);
that.qtype, lobounds);
// VGJ: sort of inlined maximizeInst() below. Adding
// bounds can cause lobounds that are above hibounds.
if (that.hibounds.isEmpty())
List<Type> hibounds = Type.filter(that.hibounds, errorFilter);
if (hibounds.isEmpty())
return;
Type hb = null;
if (that.hibounds.tail.isEmpty())
hb = that.hibounds.head;
else for (List<Type> bs = that.hibounds;
if (hibounds.tail.isEmpty())
hb = hibounds.head;
else for (List<Type> bs = hibounds;
bs.nonEmpty() && hb == null;
bs = bs.tail) {
if (isSubClass(bs.head, that.hibounds))
if (isSubClass(bs.head, hibounds))
hb = types.fromUnknownFun.apply(bs.head);
}
if (hb == null ||
!types.isSubtypeUnchecked(hb, that.hibounds, warn) ||
!types.isSubtypeUnchecked(hb, hibounds, warn) ||
!types.isSubtypeUnchecked(that.inst, hb, warn))
throw ambiguousNoInstanceException;
}
......@@ -396,7 +407,9 @@ public class Infer {
// for varargs arguments as well
if (useVarargs) {
Type elemType = types.elemtype(varargsFormal);
//note: if applicability check is triggered by most specific test,
//the last argument of a varargs is _not_ an array type (see JLS 15.12.2.5)
Type elemType = types.elemtypeOrType(varargsFormal);
Type elemUndet = types.subst(elemType, tvars, undetvars);
while (actuals.nonEmpty()) {
Type actual = actuals.head.baseType();
......@@ -527,7 +540,8 @@ public class Infer {
for (List<Type> tvs = tvars, args = arguments;
tvs.nonEmpty();
tvs = tvs.tail, args = args.tail) {
if (args.head instanceof UndetVar) continue;
if (args.head instanceof UndetVar ||
tvars.head.getUpperBound().isErroneous()) continue;
List<Type> bounds = types.subst(types.getBounds((TypeVar)tvs.head), tvars, arguments);
if (!types.isSubtypeUnchecked(args.head, bounds, warn))
throw invalidInstanceException
......@@ -538,43 +552,39 @@ public class Infer {
/**
* Compute a synthetic method type corresponding to the requested polymorphic
* method signature. If no explicit return type is supplied, a provisional
* return type is computed (just Object in case of non-transitional 292)
* method signature. The target return type is computed from the immediately
* enclosing scope surrounding the polymorphic-signature call.
*/
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, Type site,
Name name,
MethodSymbol spMethod, // sig. poly. method or null if none
List<Type> argtypes,
List<Type> typeargtypes) {
List<Type> argtypes) {
final Type restype;
if (rs.allowTransitionalJSR292 && typeargtypes.nonEmpty()) {
restype = typeargtypes.head;
} else {
//The return type for a polymorphic signature call is computed from
//the enclosing tree E, as follows: if E is a cast, then use the
//target type of the cast expression as a return type; if E is an
//expression statement, the return type is 'void' - otherwise the
//return type is simply 'Object'. A correctness check ensures that
//env.next refers to the lexically enclosing environment in which
//the polymorphic signature call environment is nested.
switch (env.next.tree.getTag()) {
case JCTree.TYPECAST:
JCTypeCast castTree = (JCTypeCast)env.next.tree;
restype = (castTree.expr == env.tree) ?
castTree.clazz.type :
syms.objectType;
break;
case JCTree.EXEC:
JCTree.JCExpressionStatement execTree =
(JCTree.JCExpressionStatement)env.next.tree;
restype = (execTree.expr == env.tree) ?
syms.voidType :
syms.objectType;
break;
default:
restype = syms.objectType;
}
//The return type for a polymorphic signature call is computed from
//the enclosing tree E, as follows: if E is a cast, then use the
//target type of the cast expression as a return type; if E is an
//expression statement, the return type is 'void' - otherwise the
//return type is simply 'Object'. A correctness check ensures that
//env.next refers to the lexically enclosing environment in which
//the polymorphic signature call environment is nested.
switch (env.next.tree.getTag()) {
case JCTree.TYPECAST:
JCTypeCast castTree = (JCTypeCast)env.next.tree;
restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
castTree.clazz.type :
syms.objectType;
break;
case JCTree.EXEC:
JCTree.JCExpressionStatement execTree =
(JCTree.JCExpressionStatement)env.next.tree;
restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
syms.voidType :
syms.objectType;
break;
default:
restype = syms.objectType;
}
List<Type> paramtypes = Type.map(argtypes, implicitArgType);
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -1057,7 +1057,7 @@ public class Lower extends TreeTranslator {
}
// Otherwise replace the variable by its proxy.
sym = proxies.lookup(proxyName(sym.name)).sym;
assert sym != null && (sym.flags_field & FINAL) != 0;
Assert.check(sym != null && (sym.flags_field & FINAL) != 0);
tree = make.at(tree.pos).Ident(sym);
}
JCExpression base = (tree.getTag() == JCTree.SELECT) ? ((JCFieldAccess) tree).selected : null;
......@@ -1208,7 +1208,7 @@ public class Lower extends TreeTranslator {
*/
void makeAccessible(Symbol sym) {
JCClassDecl cdef = classDef(sym.owner.enclClass());
assert cdef != null : "class def not found: " + sym + " in " + sym.owner;
if (cdef == null) Assert.error("class def not found: " + sym + " in " + sym.owner);
if (sym.name == names.init) {
cdef.defs = cdef.defs.prepend(
accessConstructorDef(cdef.pos, sym, accessConstrs.get(sym)));
......@@ -1458,7 +1458,7 @@ public class Lower extends TreeTranslator {
expr = make.Ident(var.sym).setType(resource.type);
stats.add(var);
} else {
assert resource instanceof JCExpression;
Assert.check(resource instanceof JCExpression);
VarSymbol syntheticTwrVar =
new VarSymbol(SYNTHETIC | FINAL,
makeSyntheticName(names.fromString("twrVar" +
......@@ -1552,7 +1552,7 @@ public class Lower extends TreeTranslator {
List<VarSymbol> ots = outerThisStack;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c);
assert false;
Assert.error();
return makeNull();
}
VarSymbol ot = ots.head;
......@@ -1565,14 +1565,14 @@ public class Lower extends TreeTranslator {
log.error(pos,
"no.encl.instance.of.type.in.scope",
c);
assert false; // should have been caught in Attr
Assert.error(); // should have been caught in Attr
return tree;
}
ot = ots.head;
} while (ot.owner != otc);
if (otc.owner.kind != PCK && !otc.hasOuterInstance()) {
chk.earlyRefError(pos, c);
assert false; // should have been caught in Attr
Assert.error(); // should have been caught in Attr
return makeNull();
}
tree = access(make.at(pos).Select(tree, ot));
......@@ -1610,7 +1610,7 @@ public class Lower extends TreeTranslator {
List<VarSymbol> ots = outerThisStack;
if (ots.isEmpty()) {
log.error(pos, "no.encl.instance.of.type.in.scope", c);
assert false;
Assert.error();
return makeNull();
}
VarSymbol ot = ots.head;
......@@ -1623,7 +1623,7 @@ public class Lower extends TreeTranslator {
log.error(pos,
"no.encl.instance.of.type.in.scope",
c);
assert false;
Assert.error();
return tree;
}
ot = ots.head;
......@@ -1640,9 +1640,9 @@ public class Lower extends TreeTranslator {
JCStatement initField(int pos, Name name) {
Scope.Entry e = proxies.lookup(name);
Symbol rhs = e.sym;
assert rhs.owner.kind == MTH;
Assert.check(rhs.owner.kind == MTH);
Symbol lhs = e.next().sym;
assert rhs.owner.owner == lhs.owner;
Assert.check(rhs.owner.owner == lhs.owner);
make.at(pos);
return
make.Exec(
......@@ -1655,9 +1655,9 @@ public class Lower extends TreeTranslator {
*/
JCStatement initOuterThis(int pos) {
VarSymbol rhs = outerThisStack.head;
assert rhs.owner.kind == MTH;
Assert.check(rhs.owner.kind == MTH);
VarSymbol lhs = outerThisStack.tail.head;
assert rhs.owner.owner == lhs.owner;
Assert.check(rhs.owner.owner == lhs.owner);
make.at(pos);
return
make.Exec(
......@@ -1856,7 +1856,7 @@ public class Lower extends TreeTranslator {
// where
/** Create an attributed tree of the form left.name(). */
private JCMethodInvocation makeCall(JCExpression left, Name name, List<JCExpression> args) {
assert left.type != null;
Assert.checkNonNull(left.type);
Symbol funcsym = lookupMethod(make_pos, name, left.type,
TreeInfo.types(args));
return make.App(make.Select(left, funcsym), args);
......@@ -2399,7 +2399,7 @@ public class Lower extends TreeTranslator {
names.valueOf,
tree.sym.type,
List.of(syms.stringType));
assert (valueOfSym.flags() & STATIC) != 0;
Assert.check((valueOfSym.flags() & STATIC) != 0);
VarSymbol nameArgSym = valueOfSym.params.head;
JCIdent nameVal = make.Ident(nameArgSym);
JCStatement enum_ValueOf =
......@@ -2585,11 +2585,6 @@ public class Lower extends TreeTranslator {
result = tree;
}
public void visitAnnotatedType(JCAnnotatedType tree) {
tree.underlyingType = translate(tree.underlyingType);
result = tree.underlyingType;
}
public void visitTypeCast(JCTypeCast tree) {
tree.clazz = translate(tree.clazz);
if (tree.type.isPrimitive() != tree.expr.type.isPrimitive())
......@@ -3421,7 +3416,7 @@ public class Lower extends TreeTranslator {
if (expression != null) { // expression for a "default" case is null
String labelExpr = (String) expression.type.constValue();
Integer mapping = caseLabelToPosition.put(labelExpr, casePosition);
assert mapping == null;
Assert.checkNull(mapping);
int hashCode = labelExpr.hashCode();
Set<String> stringSet = hashToString.get(hashCode);
......@@ -3431,7 +3426,7 @@ public class Lower extends TreeTranslator {
hashToString.put(hashCode, stringSet);
} else {
boolean added = stringSet.add(labelExpr);
assert added;
Assert.check(added);
}
}
casePosition++;
......@@ -3483,7 +3478,7 @@ public class Lower extends TreeTranslator {
for(Map.Entry<Integer, Set<String>> entry : hashToString.entrySet()) {
int hashCode = entry.getKey();
Set<String> stringsWithHashCode = entry.getValue();
assert stringsWithHashCode.size() >= 1;
Assert.check(stringsWithHashCode.size() >= 1);
JCStatement elsepart = null;
for(String caseLabel : stringsWithHashCode ) {
......@@ -3697,8 +3692,7 @@ public class Lower extends TreeTranslator {
cdef.type,
List.<Type>nil());
assert(ordinalSym != null);
assert(ordinalSym instanceof MethodSymbol);
Assert.check(ordinalSym instanceof MethodSymbol);
JCStatement ret = make.Return(make.Ident(ordinalSymbol));
cdef.defs = cdef.defs.append(make.MethodDef((MethodSymbol)ordinalSym,
......@@ -3714,8 +3708,7 @@ public class Lower extends TreeTranslator {
cdef.type,
List.<Type>nil());
assert(nameSym != null);
assert(nameSym instanceof MethodSymbol);
Assert.check(nameSym instanceof MethodSymbol);
JCStatement ret = make.Return(make.Ident(nameSymbol));
......@@ -3766,8 +3759,7 @@ public class Lower extends TreeTranslator {
cdef.type,
List.of(cdef.sym.type));
assert(compareToSym != null);
assert(compareToSym instanceof MethodSymbol);
Assert.check(compareToSym instanceof MethodSymbol);
JCMethodDecl compareToDecl = (JCMethodDecl) TreeInfo.declarationFor(compareToSym, cdef);
......
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2011, 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
......@@ -581,8 +581,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
JCVariableDecl lastParam = null;
for (List<JCVariableDecl> l = tree.params; l.nonEmpty(); l = l.tail) {
JCVariableDecl param = lastParam = l.head;
assert param.sym != null;
params.append(param.sym);
params.append(Assert.checkNonNull(param.sym));
}
m.params = params.toList();
......@@ -699,7 +698,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
*********************************************************************/
Type attribImportType(JCTree tree, Env<AttrContext> env) {
assert completionEnabled;
Assert.check(completionEnabled);
try {
// To prevent deep recursion, suppress completion of some
// types.
......@@ -725,7 +724,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
return "annotate " + annotations + " onto " + s + " in " + s.owner;
}
public void enterAnnotation() {
assert s.kind == PCK || s.attributes_field == null;
Assert.check(s.kind == PCK || s.attributes_field == null);
JavaFileObject prev = log.useSource(localEnv.toplevel.sourcefile);
try {
if (s.attributes_field != null &&
......@@ -782,8 +781,8 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
types.isSameType(c.type, syms.polymorphicSignatureType)) {
if (!target.hasMethodHandles()) {
// Somebody is compiling JDK7 source code to a JDK6 target.
// Make it a strict warning, since it is unlikely but important.
log.strictWarning(env.tree.pos(),
// Make it an error, since it is unlikely but important.
log.error(env.tree.pos(),
"wrong.target.for.polymorphic.signature.definition",
target.name);
}
......@@ -836,7 +835,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
// Suppress some (recursive) MemberEnter invocations
if (!completionEnabled) {
// Re-install same completer for next time around and return.
assert (sym.flags() & Flags.COMPOUND) == 0;
Assert.check((sym.flags() & Flags.COMPOUND) == 0);
sym.completer = this;
return;
}
......@@ -928,10 +927,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
if (hasDeprecatedAnnotation(tree.mods.annotations))
c.flags_field |= DEPRECATED;
annotateLater(tree.mods.annotations, baseEnv, c);
// class type parameters use baseEnv but everything uses env
for (JCTypeParameter tp : tree.typarams)
tp.accept(new TypeAnnotate(baseEnv));
tree.accept(new TypeAnnotate(env));
chk.checkNonCyclicDecl(tree);
......@@ -989,7 +984,7 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
c.owner.kind == PCK && c.owner != syms.unnamedPackage &&
reader.packageExists(c.fullname))
{
log.error(tree.pos, "clash.with.pkg.of.same.name", c);
log.error(tree.pos, "clash.with.pkg.of.same.name", Kinds.kindName(sym), c);
}
} catch (CompletionFailure ex) {
......@@ -1014,86 +1009,6 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
}
}
// A sub-phase that "compiles" annotations in annotated types.
private class TypeAnnotate extends TreeScanner {
private Env<AttrContext> env;
public TypeAnnotate(Env<AttrContext> env) { this.env = env; }
private void enterTypeAnnotations(List<JCTypeAnnotation> annotations) {
Set<TypeSymbol> annotated = new HashSet<TypeSymbol>();
if (!skipAnnotations)
for (List<JCTypeAnnotation> al = annotations; al.nonEmpty(); al = al.tail) {
JCTypeAnnotation a = al.head;
Attribute.Compound c = annotate.enterAnnotation(a,
syms.annotationType,
env);
if (c == null) continue;
Attribute.TypeCompound tc = new Attribute.TypeCompound(c.type, c.values, a.annotation_position);
a.attribute_field = tc;
// Note: @Deprecated has no effect on local variables and parameters
if (!annotated.add(a.type.tsym))
log.error(a.pos, "duplicate.annotation");
}
}
// each class (including enclosed inner classes) should be visited
// separately through MemberEnter.complete(Symbol)
// this flag is used to prevent from visiting inner classes.
private boolean isEnclosingClass = false;
@Override
public void visitClassDef(final JCClassDecl tree) {
if (isEnclosingClass)
return;
isEnclosingClass = true;
scan(tree.mods);
// type parameter need to be visited with a separate env
// scan(tree.typarams);
scan(tree.extending);
scan(tree.implementing);
scan(tree.defs);
}
private void annotate(final JCTree tree, final List<JCTypeAnnotation> annotations) {
annotate.later(new Annotate.Annotator() {
public String toString() {
return "annotate " + annotations + " onto " + tree;
}
public void enterAnnotation() {
JavaFileObject prev = log.useSource(env.toplevel.sourcefile);
try {
enterTypeAnnotations(annotations);
} finally {
log.useSource(prev);
}
}
});
}
@Override
public void visitAnnotatedType(final JCAnnotatedType tree) {
annotate(tree, tree.annotations);
super.visitAnnotatedType(tree);
}
@Override
public void visitTypeParameter(final JCTypeParameter tree) {
annotate(tree, tree.annotations);
super.visitTypeParameter(tree);
}
@Override
public void visitNewArray(final JCNewArray tree) {
annotate(tree, tree.annotations);
for (List<JCTypeAnnotation> dimAnnos : tree.dimAnnotations)
annotate(tree, dimAnnos);
super.visitNewArray(tree);
}
@Override
public void visitMethodDef(JCMethodDecl tree) {
annotate(tree, tree.receiverAnnotations);
super.visitMethodDef(tree);
}
}
private Env<AttrContext> baseEnv(JCClassDecl tree, Env<AttrContext> env) {
Scope baseScope = new Scope.ClassScope(tree.sym, scopeCounter);
//import already entered local classes into base scope
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -70,8 +70,6 @@ public class Resolve {
public final boolean boxingEnabled; // = source.allowBoxing();
public final boolean varargsEnabled; // = source.allowVarargs();
public final boolean allowMethodHandles;
public final boolean allowInvokeDynamic;
public final boolean allowTransitionalJSR292;
private final boolean debugResolve;
Scope polymorphicSignatureScope;
......@@ -111,13 +109,8 @@ public class Resolve {
varargsEnabled = source.allowVarargs();
Options options = Options.instance(context);
debugResolve = options.isSet("debugresolve");
allowTransitionalJSR292 = options.isSet("allowTransitionalJSR292");
Target target = Target.instance(context);
allowMethodHandles = allowTransitionalJSR292 ||
target.hasMethodHandles();
allowInvokeDynamic = (allowTransitionalJSR292 ||
target.hasInvokedynamic()) &&
options.isSet("invokedynamic");
allowMethodHandles = target.hasMethodHandles();
polymorphicSignatureScope = new Scope(syms.noSymbol);
inapplicableMethodException = new InapplicableMethodException(diags);
......@@ -336,8 +329,7 @@ public class Resolve {
boolean useVarargs,
Warner warn)
throws Infer.InferenceException {
boolean polymorphicSignature = (m.isPolymorphicSignatureGeneric() && allowMethodHandles) ||
isTransitionalDynamicCallSite(site, m);
boolean polymorphicSignature = m.isPolymorphicSignatureGeneric() && allowMethodHandles;
if (useVarargs && (m.flags() & VARARGS) == 0)
throw inapplicableMethodException.setMessage(null);
Type mt = types.memberType(site, m);
......@@ -346,10 +338,7 @@ public class Resolve {
// need to inferred.
List<Type> tvars = env.info.tvars;
if (typeargtypes == null) typeargtypes = List.nil();
if (allowTransitionalJSR292 && polymorphicSignature && typeargtypes.nonEmpty()) {
//transitional 292 call sites might have wrong number of targs
}
else if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
if (mt.tag != FORALL && typeargtypes.nonEmpty()) {
// This is not a polymorphic method, but typeargs are supplied
// which is fine, see JLS3 15.12.2.1
} else if (mt.tag == FORALL && typeargtypes.nonEmpty()) {
......@@ -387,7 +376,7 @@ public class Resolve {
if (instNeeded)
return polymorphicSignature ?
infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes, typeargtypes) :
infer.instantiatePolymorphicSignatureInstance(env, site, m.name, (MethodSymbol)m, argtypes) :
infer.instantiateMethod(env,
tvars,
(MethodType)mt,
......@@ -402,14 +391,6 @@ public class Resolve {
return mt;
}
boolean isTransitionalDynamicCallSite(Type site, Symbol sym) {
return allowTransitionalJSR292 && // old logic that doesn't use annotations
!sym.isPolymorphicSignatureInstance() &&
((allowMethodHandles && site == syms.methodHandleType && // invokeExact, invokeGeneric, invoke
(sym.name == names.invoke && sym.isPolymorphicSignatureGeneric())) ||
(site == syms.invokeDynamicType && allowInvokeDynamic)); // InvokeDynamic.XYZ
}
/** Same but returns null instead throwing a NoInstanceException
*/
Type instantiate(Env<AttrContext> env,
......@@ -679,7 +660,7 @@ public class Resolve {
boolean operator) {
if (sym.kind == ERR) return bestSoFar;
if (!sym.isInheritedIn(site.tsym, types)) return bestSoFar;
assert sym.kind < AMBIGUOUS;
Assert.check(sym.kind < AMBIGUOUS);
try {
rawInstantiate(env, site, sym, argtypes, typeargtypes,
allowBoxing, useVarargs, Warner.noWarnings);
......@@ -1255,6 +1236,7 @@ public class Resolve {
*/
Symbol access(Symbol sym,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
boolean qualified,
......@@ -1265,25 +1247,48 @@ public class Resolve {
if (!site.isErroneous() &&
!Type.isErroneous(argtypes) &&
(typeargtypes==null || !Type.isErroneous(typeargtypes)))
logResolveError(errSym, pos, site, name, argtypes, typeargtypes);
logResolveError(errSym, pos, location, site, name, argtypes, typeargtypes);
sym = errSym.access(name, qualified ? site.tsym : syms.noSymbol);
}
return sym;
}
/** Same as above, but without type arguments and arguments.
/** Same as original access(), but without location.
*/
Symbol access(Symbol sym,
DiagnosticPosition pos,
Type site,
Name name,
boolean qualified,
List<Type> argtypes,
List<Type> typeargtypes) {
return access(sym, pos, site.tsym, site, name, qualified, argtypes, typeargtypes);
}
/** Same as original access(), but without type arguments and arguments.
*/
Symbol access(Symbol sym,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
boolean qualified) {
if (sym.kind >= AMBIGUOUS)
return access(sym, pos, site, name, qualified, List.<Type>nil(), null);
return access(sym, pos, location, site, name, qualified, List.<Type>nil(), null);
else
return sym;
}
/** Same as original access(), but without location, type arguments and arguments.
*/
Symbol access(Symbol sym,
DiagnosticPosition pos,
Type site,
Name name,
boolean qualified) {
return access(sym, pos, site.tsym, site, name, qualified);
}
/** Check that sym is not an abstract method.
*/
void checkNonAbstract(DiagnosticPosition pos, Symbol sym) {
......@@ -1399,6 +1404,11 @@ public class Resolve {
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
Type site, Name name, List<Type> argtypes,
List<Type> typeargtypes) {
return resolveQualifiedMethod(pos, env, site.tsym, site, name, argtypes, typeargtypes);
}
Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env,
Symbol location, Type site, Name name, List<Type> argtypes,
List<Type> typeargtypes) {
Symbol sym = startResolution();
List<MethodResolutionPhase> steps = methodResolutionSteps;
while (steps.nonEmpty() &&
......@@ -1412,26 +1422,25 @@ public class Resolve {
steps = steps.tail;
}
if (sym.kind >= AMBIGUOUS) {
if (site.tsym.isPolymorphicSignatureGeneric() ||
isTransitionalDynamicCallSite(site, sym)) {
if (site.tsym.isPolymorphicSignatureGeneric()) {
//polymorphic receiver - synthesize new method symbol
env.info.varArgs = false;
sym = findPolymorphicSignatureInstance(env,
site, name, null, argtypes, typeargtypes);
site, name, null, argtypes);
}
else {
//if nothing is found return the 'first' error
MethodResolutionPhase errPhase =
firstErroneousResolutionPhase();
sym = access(methodResolutionCache.get(errPhase),
pos, site, name, true, argtypes, typeargtypes);
pos, location, site, name, true, argtypes, typeargtypes);
env.info.varArgs = errPhase.isVarargsRequired;
}
} else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
//non-instantiated polymorphic signature - synthesize new method symbol
env.info.varArgs = false;
sym = findPolymorphicSignatureInstance(env,
site, name, (MethodSymbol)sym, argtypes, typeargtypes);
site, name, (MethodSymbol)sym, argtypes);
}
return sym;
}
......@@ -1449,15 +1458,9 @@ public class Resolve {
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, Type site,
Name name,
MethodSymbol spMethod, // sig. poly. method or null if none
List<Type> argtypes,
List<Type> typeargtypes) {
if (typeargtypes.nonEmpty() && (site.tsym.isPolymorphicSignatureGeneric() ||
(spMethod != null && spMethod.isPolymorphicSignatureGeneric()))) {
log.warning(env.tree.pos(), "type.parameter.on.polymorphic.signature");
}
List<Type> argtypes) {
Type mtype = infer.instantiatePolymorphicSignatureInstance(env,
site, name, spMethod, argtypes, typeargtypes);
site, name, spMethod, argtypes);
long flags = ABSTRACT | HYPOTHETICAL | POLYMORPHIC_SIGNATURE |
(spMethod != null ?
spMethod.flags() & Flags.AccessFlags :
......@@ -1497,7 +1500,7 @@ public class Resolve {
List<Type> argtypes,
List<Type> typeargtypes) {
Symbol sym = resolveQualifiedMethod(
pos, env, site, name, argtypes, typeargtypes);
pos, env, site.tsym, site, name, argtypes, typeargtypes);
if (sym.kind == MTH) return (MethodSymbol)sym;
else throw new FatalError(
diags.fragment("fatal.err.cant.locate.meth",
......@@ -1572,11 +1575,13 @@ public class Resolve {
null;
Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {
@Override
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos,
Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
String key = details == null ?
"cant.apply.diamond" :
"cant.apply.diamond.1";
return diags.create(dkind, log.currentSource(), pos, key, diags.fragment("diamond", site.tsym), details);
return diags.create(dkind, log.currentSource(), pos, key,
diags.fragment("diamond", site.tsym), details);
}
};
MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
......@@ -1755,17 +1760,18 @@ public class Resolve {
public void logAccessError(Env<AttrContext> env, JCTree tree, Type type) {
AccessError error = new AccessError(env, type.getEnclosingType(), type.tsym);
logResolveError(error, tree.pos(), type.getEnclosingType(), null, null, null);
logResolveError(error, tree.pos(), type.getEnclosingType().tsym, type.getEnclosingType(), null, null, null);
}
//where
private void logResolveError(ResolveError error,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
List<Type> typeargtypes) {
JCDiagnostic d = error.getDiagnostic(JCDiagnostic.DiagnosticType.ERROR,
pos, site, name, argtypes, typeargtypes);
pos, location, site, name, argtypes, typeargtypes);
if (d != null) {
d.setFlag(DiagnosticFlag.RESOLVE_ERROR);
log.report(d);
......@@ -1835,6 +1841,7 @@ public class Resolve {
*/
abstract JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -1900,6 +1907,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -1910,16 +1918,23 @@ public class Resolve {
return null;
if (isOperator(name)) {
boolean isUnaryOp = argtypes.size() == 1;
String key = argtypes.size() == 1 ?
"operator.cant.be.applied" :
"operator.cant.be.applied.1";
Type first = argtypes.head;
Type second = !isUnaryOp ? argtypes.tail.head : null;
return diags.create(dkind, log.currentSource(), pos,
"operator.cant.be.applied", name, argtypes);
key, name, first, second);
}
boolean hasLocation = false;
if (!site.tsym.name.isEmpty()) {
if (site.tsym.kind == PCK && !site.tsym.exists()) {
if (!location.name.isEmpty()) {
if (location.kind == PCK && !site.tsym.exists()) {
return diags.create(dkind, log.currentSource(), pos,
"doesnt.exist", site.tsym);
"doesnt.exist", location);
}
hasLocation = true;
hasLocation = !location.name.equals(names._this) &&
!location.name.equals(names._super);
}
boolean isConstructor = kind == ABSENT_MTH &&
name == names.table.names.init;
......@@ -1930,7 +1945,7 @@ public class Resolve {
return diags.create(dkind, log.currentSource(), pos,
errKey, kindname, idname, //symbol kindname, name
typeargtypes, argtypes, //type parameters and arguments (if any)
typeKindName(site), site); //location kindname, type
getLocationDiag(location)); //location kindname, type
}
else {
return diags.create(dkind, log.currentSource(), pos,
......@@ -1951,6 +1966,16 @@ public class Resolve {
}
return key + suffix;
}
private JCDiagnostic getLocationDiag(Symbol location) {
boolean isVar = location.kind == VAR;
String key = isVar ?
"location.1" :
"location";
return diags.fragment(key,
kindName(location),
location,
isVar ? location.type : null);
}
}
/**
......@@ -1991,6 +2016,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -2042,6 +2068,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -2057,7 +2084,7 @@ public class Resolve {
return new JCDiagnostic.MultilineDiagnostic(err, candidateDetails(site));
} else {
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind, pos,
site, name, argtypes, typeargtypes);
location, site, name, argtypes, typeargtypes);
}
}
......@@ -2157,6 +2184,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -2166,7 +2194,7 @@ public class Resolve {
if (sym.name == names.init && sym.owner != site.tsym) {
return new SymbolNotFoundError(ABSENT_MTH).getDiagnostic(dkind,
pos, site, name, argtypes, typeargtypes);
pos, location, site, name, argtypes, typeargtypes);
}
else if ((sym.flags() & PUBLIC) != 0
|| (env != null && this.site != null
......@@ -2201,6 +2229,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......@@ -2231,6 +2260,7 @@ public class Resolve {
@Override
JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind,
DiagnosticPosition pos,
Symbol location,
Type site,
Name name,
List<Type> argtypes,
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -69,7 +69,6 @@ public class TransTypes extends TreeTranslator {
private boolean allowEnums;
private Types types;
private final Resolve resolve;
private final TypeAnnotations typeAnnotations;
/**
* Flag to indicate whether or not to generate bridge methods.
......@@ -91,7 +90,6 @@ public class TransTypes extends TreeTranslator {
types = Types.instance(context);
make = TreeMaker.instance(context);
resolve = Resolve.instance(context);
typeAnnotations = TypeAnnotations.instance(context);
}
/** A hashtable mapping bridge methods to the methods they override after
......@@ -182,7 +180,7 @@ public class TransTypes extends TreeTranslator {
parameters = parameters.tail;
}
Type parameter = parameters.head;
assert varargsElement != null || args.length() == 1;
Assert.check(varargsElement != null || args.length() == 1);
if (varargsElement != null) {
while (args.nonEmpty()) {
args.head = translate(args.head, varargsElement);
......@@ -445,14 +443,12 @@ public class TransTypes extends TreeTranslator {
}
public void visitClassDef(JCClassDecl tree) {
typeAnnotations.taFillAndLift(tree, true);
translateClass(tree.sym);
result = tree;
}
JCMethodDecl currentMethod = null;
public void visitMethodDef(JCMethodDecl tree) {
tree.sym.typeAnnotations = tree.sym.typeAnnotations;
JCMethodDecl previousMethod = currentMethod;
try {
currentMethod = tree;
......@@ -598,7 +594,7 @@ public class TransTypes extends TreeTranslator {
if (tree.varargsElement != null)
tree.varargsElement = types.erasure(tree.varargsElement);
else
assert tree.args.length() == argtypes.length();
Assert.check(tree.args.length() == argtypes.length());
tree.args = translateArgs(tree.args, argtypes, tree.varargsElement);
// Insert casts of method invocation results as needed.
......
/*
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -472,7 +472,7 @@ public class JavacFileManager extends BaseFileManager implements StandardJavaFil
*/
protected Archive openArchive(File zipFileName) throws IOException {
File origZipFileName = zipFileName;
if (!ignoreSymbolFile && paths.isBootClassPathRtJar(zipFileName)) {
if (!ignoreSymbolFile && paths.isDefaultBootClassPathRtJar(zipFileName)) {
File file = zipFileName.getParentFile().getParentFile(); // ${java.home}
if (new File(file.getName()).equals(new File("jre")))
file = file.getParentFile();
......
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2011, 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
......@@ -112,7 +112,7 @@ public class Paths {
* rt.jar as found on the default bootclass path. If the user specified a
* bootclasspath, null is used.
*/
private File bootClassPathRtJar = null;
private File defaultBootClassPathRtJar = null;
/**
* Is bootclasspath the default?
......@@ -143,8 +143,10 @@ public class Paths {
// no defaults for other paths
p = null;
} else {
if (location == PLATFORM_CLASS_PATH)
if (location == PLATFORM_CLASS_PATH) {
defaultBootClassPathRtJar = null;
isDefaultBootClassPath = false;
}
p = new Path();
for (File f: path)
p.addFile(f, warn); // TODO: is use of warn appropriate?
......@@ -185,8 +187,8 @@ public class Paths {
: Collections.unmodifiableCollection(p);
}
boolean isBootClassPathRtJar(File file) {
return file.equals(bootClassPathRtJar);
boolean isDefaultBootClassPathRtJar(File file) {
return file.equals(defaultBootClassPathRtJar);
}
/**
......@@ -355,7 +357,7 @@ public class Paths {
}
private Path computeBootClassPath() {
bootClassPathRtJar = null;
defaultBootClassPathRtJar = null;
Path path = new Path();
String bootclasspathOpt = options.get(BOOTCLASSPATH);
......@@ -380,7 +382,7 @@ public class Paths {
File rt_jar = new File("rt.jar");
for (File file : getPathEntries(files)) {
if (new File(file.getName()).equals(rt_jar))
bootClassPathRtJar = file;
defaultBootClassPathRtJar = file;
}
}
......
/*
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2005, 2011, 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
......@@ -42,6 +42,7 @@ import java.nio.charset.CharsetDecoder;
import com.sun.tools.javac.file.JavacFileManager.Archive;
import com.sun.tools.javac.file.RelativePath.RelativeDirectory;
import com.sun.tools.javac.file.RelativePath.RelativeFile;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.List;
/**
......@@ -146,7 +147,7 @@ public class ZipFileIndexArchive implements Archive {
@Override
public InputStream openInputStream() throws IOException {
if (inputStream == null) {
assert entry != null; // see constructor
Assert.checkNonNull(entry); // see constructor
inputStream = new ByteArrayInputStream(zfIndex.read(entry));
}
return inputStream;
......
/*
* Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2011, 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
......@@ -101,7 +101,7 @@ implements CRTFlags {
continue;
SourceRange pos = positions.get(entry.tree);
assert pos != null : "CRT: tree source positions are undefined";
Assert.checkNonNull(pos, "CRT: tree source positions are undefined");
if ((pos.startPos == Position.NOPOS) || (pos.endPos == Position.NOPOS))
continue;
......@@ -517,7 +517,7 @@ implements CRTFlags {
}
public void visitTree(JCTree tree) {
assert false;
Assert.error();
}
/** The start position of given tree.
......
/*
* Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -80,6 +80,9 @@ public class ClassFile {
public final static int CONSTANT_Methodref = 10;
public final static int CONSTANT_InterfaceMethodref = 11;
public final static int CONSTANT_NameandType = 12;
public final static int CONSTANT_MethodHandle = 15;
public final static int CONSTANT_MethodType = 16;
public final static int CONSTANT_InvokeDynamic = 18;
public final static int MAX_PARAMETERS = 0xff;
public final static int MAX_DIMENSIONS = 0xff;
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -207,10 +207,6 @@ public class ClassReader implements Completer {
/** The minor version number of the class file being read. */
int minorVersion;
/** Switch: debug output for JSR 308-related operations.
*/
boolean debugJSR308;
/** A table to hold the constant pool indices for method parameter
* names, as given in LocalVariableTable attributes.
*/
......@@ -246,9 +242,9 @@ public class ClassReader implements Completer {
if (classes != null) return;
if (definitive) {
assert packages == null || packages == syms.packages;
Assert.check(packages == null || packages == syms.packages);
packages = syms.packages;
assert classes == null || classes == syms.classes;
Assert.check(classes == null || classes == syms.classes);
classes = syms.classes;
} else {
packages = new HashMap<Name, PackageSymbol>();
......@@ -297,7 +293,6 @@ public class ClassReader implements Completer {
: null;
typevars = new Scope(syms.noSymbol);
debugJSR308 = options.isSet("TA:reader");
lintClassfile = Lint.instance(context).isEnabled(LintCategory.CLASSFILE);
......@@ -439,14 +434,19 @@ public class ClassReader implements Completer {
}
case CONSTANT_Class:
case CONSTANT_String:
case CONSTANT_MethodType:
bp = bp + 2;
break;
case CONSTANT_MethodHandle:
bp = bp + 3;
break;
case CONSTANT_Fieldref:
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
case CONSTANT_NameandType:
case CONSTANT_Integer:
case CONSTANT_Float:
case CONSTANT_InvokeDynamic:
bp = bp + 4;
break;
case CONSTANT_Long:
......@@ -515,6 +515,15 @@ public class ClassReader implements Completer {
case CONSTANT_Double:
poolObj[i] = new Double(getDouble(index + 1));
break;
case CONSTANT_MethodHandle:
skipBytes(4);
break;
case CONSTANT_MethodType:
skipBytes(3);
break;
case CONSTANT_InvokeDynamic:
skipBytes(5);
break;
default:
throw badClassFile("bad.const.pool.tag", Byte.toString(tag));
}
......@@ -535,7 +544,7 @@ public class ClassReader implements Completer {
int index = poolIdx[i];
int len = getChar(index + 1);
int start = index + 3;
assert buf[start] == '[' || buf[start + len - 1] != ';';
Assert.check(buf[start] == '[' || buf[start + len - 1] != ';');
// by the above assertion, the following test can be
// simplified to (buf[start] == '[')
return (buf[start] == '[' || buf[start + len - 1] == ';')
......@@ -1046,7 +1055,7 @@ public class ClassReader implements Completer {
readingClassAttr = true;
try {
ClassType ct1 = (ClassType)c.type;
assert c == currentOwner;
Assert.check(c == currentOwner);
ct1.typarams_field = readTypeParams(nextChar());
ct1.supertype_field = sigToType();
ListBuffer<Type> is = new ListBuffer<Type>();
......@@ -1128,20 +1137,6 @@ public class ClassReader implements Completer {
}
},
// v51 attributes
new AttributeReader(names.RuntimeVisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
void read(Symbol sym, int attrLen) {
attachTypeAnnotations(sym);
}
},
new AttributeReader(names.RuntimeInvisibleTypeAnnotations, V51, CLASS_OR_MEMBER_ATTRIBUTE) {
void read(Symbol sym, int attrLen) {
attachTypeAnnotations(sym);
}
},
// The following attributes for a Code attribute are not currently handled
// StackMapTable
// SourceDebugExtension
......@@ -1351,17 +1346,6 @@ public class ClassReader implements Completer {
}
}
void attachTypeAnnotations(final Symbol sym) {
int numAttributes = nextChar();
if (numAttributes != 0) {
ListBuffer<TypeAnnotationProxy> proxies =
ListBuffer.lb();
for (int i = 0; i < numAttributes; i++)
proxies.append(readTypeAnnotation());
annotate.later(new TypeAnnotationCompleter(sym, proxies.toList()));
}
}
/** Attach the default value for an annotation element.
*/
void attachAnnotationDefault(final Symbol sym) {
......@@ -1398,121 +1382,6 @@ public class ClassReader implements Completer {
return new CompoundAnnotationProxy(t, pairs.toList());
}
TypeAnnotationProxy readTypeAnnotation() {
CompoundAnnotationProxy proxy = readCompoundAnnotation();
TypeAnnotationPosition position = readPosition();
if (debugJSR308)
System.out.println("TA: reading: " + proxy + " @ " + position
+ " in " + log.currentSourceFile());
return new TypeAnnotationProxy(proxy, position);
}
TypeAnnotationPosition readPosition() {
byte tag = nextByte();
if (!TargetType.isValidTargetTypeValue(tag))
throw this.badClassFile("bad.type.annotation.value", tag);
TypeAnnotationPosition position = new TypeAnnotationPosition();
TargetType type = TargetType.fromTargetTypeValue(tag);
position.type = type;
switch (type) {
// type case
case TYPECAST:
case TYPECAST_GENERIC_OR_ARRAY:
// object creation
case INSTANCEOF:
case INSTANCEOF_GENERIC_OR_ARRAY:
// new expression
case NEW:
case NEW_GENERIC_OR_ARRAY:
position.offset = nextChar();
break;
// local variable
case LOCAL_VARIABLE:
case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
int table_length = nextChar();
position.lvarOffset = new int[table_length];
position.lvarLength = new int[table_length];
position.lvarIndex = new int[table_length];
for (int i = 0; i < table_length; ++i) {
position.lvarOffset[i] = nextChar();
position.lvarLength[i] = nextChar();
position.lvarIndex[i] = nextChar();
}
break;
// method receiver
case METHOD_RECEIVER:
// Do nothing
break;
// type parameters
case CLASS_TYPE_PARAMETER:
case METHOD_TYPE_PARAMETER:
position.parameter_index = nextByte();
break;
// type parameter bounds
case CLASS_TYPE_PARAMETER_BOUND:
case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
case METHOD_TYPE_PARAMETER_BOUND:
case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
position.parameter_index = nextByte();
position.bound_index = nextByte();
break;
// wildcard
case WILDCARD_BOUND:
case WILDCARD_BOUND_GENERIC_OR_ARRAY:
position.wildcard_position = readPosition();
break;
// Class extends and implements clauses
case CLASS_EXTENDS:
case CLASS_EXTENDS_GENERIC_OR_ARRAY:
position.type_index = nextChar();
break;
// throws
case THROWS:
position.type_index = nextChar();
break;
case CLASS_LITERAL:
case CLASS_LITERAL_GENERIC_OR_ARRAY:
position.offset = nextChar();
break;
// method parameter: not specified
case METHOD_PARAMETER_GENERIC_OR_ARRAY:
position.parameter_index = nextByte();
break;
// method type argument: wasn't specified
case NEW_TYPE_ARGUMENT:
case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
case METHOD_TYPE_ARGUMENT:
case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
position.offset = nextChar();
position.type_index = nextByte();
break;
// We don't need to worry abut these
case METHOD_RETURN_GENERIC_OR_ARRAY:
case FIELD_GENERIC_OR_ARRAY:
break;
case UNKNOWN:
break;
default:
throw new AssertionError("unknown type: " + position);
}
if (type.hasLocation()) {
int len = nextChar();
ListBuffer<Integer> loc = ListBuffer.lb();
for (int i = 0; i < len; i++)
loc = loc.append((int)nextByte());
position.location = loc.toList();
}
return position;
}
Attribute readAttributeValue() {
char c = (char) buf[bp++];
switch (c) {
......@@ -1825,45 +1694,6 @@ public class ClassReader implements Completer {
}
}
class TypeAnnotationCompleter extends AnnotationCompleter {
List<TypeAnnotationProxy> proxies;
TypeAnnotationCompleter(Symbol sym,
List<TypeAnnotationProxy> proxies) {
super(sym, List.<CompoundAnnotationProxy>nil());
this.proxies = proxies;
}
List<Attribute.TypeCompound> deproxyTypeCompoundList(List<TypeAnnotationProxy> proxies) {
ListBuffer<Attribute.TypeCompound> buf = ListBuffer.lb();
for (TypeAnnotationProxy proxy: proxies) {
Attribute.Compound compound = deproxyCompound(proxy.compound);
Attribute.TypeCompound typeCompound = new Attribute.TypeCompound(compound, proxy.position);
buf.add(typeCompound);
}
return buf.toList();
}
@Override
public void enterAnnotation() {
JavaFileObject previousClassFile = currentClassFile;
try {
currentClassFile = classFile;
List<Attribute.TypeCompound> newList = deproxyTypeCompoundList(proxies);
if (debugJSR308)
System.out.println("TA: reading: adding " + newList
+ " to symbol " + sym + " in " + log.currentSourceFile());
sym.typeAnnotations = ((sym.typeAnnotations == null)
? newList
: newList.prependList(sym.typeAnnotations));
} finally {
currentClassFile = previousClassFile;
}
}
}
/************************************************************************
* Reading Symbols
......@@ -2005,6 +1835,13 @@ public class ClassReader implements Completer {
sym.savedParameterNames = paramNames.reverse();
}
/**
* skip n bytes
*/
void skipBytes(int n) {
bp = bp + n;
}
/** Skip a field or method
*/
void skipMember() {
......@@ -2092,9 +1929,9 @@ public class ClassReader implements Completer {
if (ct.interfaces_field == null)
ct.interfaces_field = is.reverse();
if (fieldCount != nextChar()) assert false;
Assert.check(fieldCount == nextChar());
for (int i = 0; i < fieldCount; i++) enterMember(c, readField());
if (methodCount != nextChar()) assert false;
Assert.check(methodCount == nextChar());
for (int i = 0; i < methodCount; i++) enterMember(c, readMethod());
typevars = typevars.leave();
......@@ -2203,7 +2040,7 @@ public class ClassReader implements Completer {
public ClassSymbol defineClass(Name name, Symbol owner) {
ClassSymbol c = new ClassSymbol(0, name, owner);
if (owner.kind == PCK)
assert classes.get(c.flatname) == null : c;
Assert.checkNull(classes.get(c.flatname), c);
c.completer = this;
return c;
}
......@@ -2343,9 +2180,9 @@ public class ClassReader implements Completer {
if (classfile != null) {
JavaFileObject previousClassFile = currentClassFile;
try {
assert !filling :
"Filling " + classfile.toUri() +
" during " + previousClassFile;
if (filling) {
Assert.error("Filling " + classfile.toUri() + " during " + previousClassFile);
}
currentClassFile = classfile;
if (verbose) {
printVerbose("loading", currentClassFile.toString());
......@@ -2491,7 +2328,7 @@ public class ClassReader implements Completer {
public PackageSymbol enterPackage(Name fullname) {
PackageSymbol p = packages.get(fullname);
if (p == null) {
assert !fullname.isEmpty() : "rootPackage missing!";
Assert.check(!fullname.isEmpty(), "rootPackage missing!");
p = new PackageSymbol(
Convert.shortName(fullname),
enterPackage(Convert.packagePart(fullname)));
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -65,10 +65,6 @@ public class ClassWriter extends ClassFile {
private final Options options;
/** Switch: debugging output for JSR 308-related operations.
*/
private boolean debugJSR308;
/** Switch: verbose output.
*/
private boolean verbose;
......@@ -180,7 +176,6 @@ public class ClassWriter extends ClassFile {
types = Types.instance(context);
fileManager = context.get(JavaFileManager.class);
debugJSR308 = options.isSet("TA:writer");
verbose = options.isSet(VERBOSE);
scramble = options.isSet("-scramble");
scrambleAll = options.isSet("-scrambleAll");
......@@ -224,11 +219,14 @@ public class ClassWriter extends ClassFile {
/** Return flags as a string, separated by " ".
*/
public static String flagNames(long flags) {
StringBuffer sbuf = new StringBuffer();
StringBuilder sbuf = new StringBuilder();
int i = 0;
long f = flags & StandardFlags;
while (f != 0) {
if ((f & 1) != 0) sbuf.append(" " + flagName[i]);
if ((f & 1) != 0) {
sbuf.append(" ");
sbuf.append(flagName[i]);
}
f = f >> 1;
i++;
}
......@@ -381,7 +379,7 @@ public class ClassWriter extends ClassFile {
? types.erasure(outer)
: outer);
sigbuf.appendByte('.');
assert c.flatname.startsWith(c.owner.enclClass().flatname);
Assert.check(c.flatname.startsWith(c.owner.enclClass().flatname));
sigbuf.appendName(rawOuter
? c.flatname.subName(c.owner.enclClass().flatname.getByteLength()+1,c.flatname.getByteLength())
: c.name);
......@@ -421,7 +419,7 @@ public class ClassWriter extends ClassFile {
/** Return signature of given type
*/
Name typeSig(Type type) {
assert sigbuf.length == 0;
Assert.check(sigbuf.length == 0);
//- System.out.println(" ? " + type);
assembleSig(type);
Name n = sigbuf.toName(names);
......@@ -471,7 +469,7 @@ public class ClassWriter extends ClassFile {
int i = 1;
while (i < pool.pp) {
Object value = pool.pool[i];
assert value != null;
Assert.checkNonNull(value);
if (value instanceof Pool.Method)
value = ((Pool.Method)value).m;
else if (value instanceof Pool.Variable)
......@@ -534,7 +532,7 @@ public class ClassWriter extends ClassFile {
poolbuf.appendByte(CONSTANT_Class);
poolbuf.appendChar(pool.put(xClassName(type)));
} else {
assert false : "writePool " + value;
Assert.error("writePool " + value);
}
i++;
}
......@@ -677,7 +675,6 @@ public class ClassWriter extends ClassFile {
acount++;
}
acount += writeJavaAnnotations(sym.getAnnotationMirrors());
acount += writeTypeAnnotations(sym.typeAnnotations);
return acount;
}
......@@ -772,46 +769,6 @@ public class ClassWriter extends ClassFile {
return attrCount;
}
int writeTypeAnnotations(List<Attribute.TypeCompound> typeAnnos) {
if (typeAnnos.isEmpty()) return 0;
ListBuffer<Attribute.TypeCompound> visibles = ListBuffer.lb();
ListBuffer<Attribute.TypeCompound> invisibles = ListBuffer.lb();
for (Attribute.TypeCompound tc : typeAnnos) {
if (tc.position.type == TargetType.UNKNOWN
|| !tc.position.emitToClassfile())
continue;
switch (types.getRetention(tc)) {
case SOURCE: break;
case CLASS: invisibles.append(tc); break;
case RUNTIME: visibles.append(tc); break;
default: ;// /* fail soft */ throw new AssertionError(vis);
}
}
int attrCount = 0;
if (visibles.length() != 0) {
int attrIndex = writeAttr(names.RuntimeVisibleTypeAnnotations);
databuf.appendChar(visibles.length());
for (Attribute.TypeCompound p : visibles)
writeTypeAnnotation(p);
endAttr(attrIndex);
attrCount++;
}
if (invisibles.length() != 0) {
int attrIndex = writeAttr(names.RuntimeInvisibleTypeAnnotations);
databuf.appendChar(invisibles.length());
for (Attribute.TypeCompound p : invisibles)
writeTypeAnnotation(p);
endAttr(attrIndex);
attrCount++;
}
return attrCount;
}
/** A visitor to write an attribute including its leading
* single-character marker.
*/
......@@ -844,7 +801,7 @@ public class ClassWriter extends ClassFile {
databuf.appendByte('Z');
break;
case CLASS:
assert value instanceof String;
Assert.check(value instanceof String);
databuf.appendByte('s');
value = names.fromString(value.toString()); // CONSTANT_Utf8
break;
......@@ -888,104 +845,6 @@ public class ClassWriter extends ClassFile {
p.snd.accept(awriter);
}
}
void writeTypeAnnotation(Attribute.TypeCompound c) {
if (debugJSR308)
System.out.println("TA: writing " + c + " at " + c.position
+ " in " + log.currentSourceFile());
writeCompoundAttribute(c);
writePosition(c.position);
}
void writePosition(TypeAnnotationPosition p) {
databuf.appendByte(p.type.targetTypeValue());
switch (p.type) {
// type case
case TYPECAST:
case TYPECAST_GENERIC_OR_ARRAY:
// object creation
case INSTANCEOF:
case INSTANCEOF_GENERIC_OR_ARRAY:
// new expression
case NEW:
case NEW_GENERIC_OR_ARRAY:
databuf.appendChar(p.offset);
break;
// local variable
case LOCAL_VARIABLE:
case LOCAL_VARIABLE_GENERIC_OR_ARRAY:
databuf.appendChar(p.lvarOffset.length); // for table length
for (int i = 0; i < p.lvarOffset.length; ++i) {
databuf.appendChar(p.lvarOffset[i]);
databuf.appendChar(p.lvarLength[i]);
databuf.appendChar(p.lvarIndex[i]);
}
break;
// method receiver
case METHOD_RECEIVER:
// Do nothing
break;
// type parameters
case CLASS_TYPE_PARAMETER:
case METHOD_TYPE_PARAMETER:
databuf.appendByte(p.parameter_index);
break;
// type parameters bounds
case CLASS_TYPE_PARAMETER_BOUND:
case CLASS_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
case METHOD_TYPE_PARAMETER_BOUND:
case METHOD_TYPE_PARAMETER_BOUND_GENERIC_OR_ARRAY:
databuf.appendByte(p.parameter_index);
databuf.appendByte(p.bound_index);
break;
// wildcards
case WILDCARD_BOUND:
case WILDCARD_BOUND_GENERIC_OR_ARRAY:
writePosition(p.wildcard_position);
break;
// Class extends and implements clauses
case CLASS_EXTENDS:
case CLASS_EXTENDS_GENERIC_OR_ARRAY:
databuf.appendChar(p.type_index);
break;
// throws
case THROWS:
databuf.appendChar(p.type_index);
break;
case CLASS_LITERAL:
case CLASS_LITERAL_GENERIC_OR_ARRAY:
databuf.appendChar(p.offset);
break;
// method parameter: not specified
case METHOD_PARAMETER_GENERIC_OR_ARRAY:
databuf.appendByte(p.parameter_index);
break;
// method type argument: wasn't specified
case NEW_TYPE_ARGUMENT:
case NEW_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
case METHOD_TYPE_ARGUMENT:
case METHOD_TYPE_ARGUMENT_GENERIC_OR_ARRAY:
databuf.appendChar(p.offset);
databuf.appendByte(p.type_index);
break;
// We don't need to worry abut these
case METHOD_RETURN_GENERIC_OR_ARRAY:
case FIELD_GENERIC_OR_ARRAY:
break;
case UNKNOWN:
break;
default:
throw new AssertionError("unknown position: " + p);
}
// Append location data for generics/arrays.
if (p.type.hasLocation()) {
databuf.appendChar(p.location.size());
for (int i : p.location)
databuf.appendByte((byte)i);
}
}
/**********************************************************************
* Writing Objects
**********************************************************************/
......@@ -1159,11 +1018,11 @@ public class ClassWriter extends ClassFile {
Code.LocalVar var = code.varBuffer[i];
// write variable info
assert var.start_pc >= 0;
assert var.start_pc <= code.cp;
Assert.check(var.start_pc >= 0
&& var.start_pc <= code.cp);
databuf.appendChar(var.start_pc);
assert var.length >= 0;
assert (var.start_pc + var.length) <= code.cp;
Assert.check(var.length >= 0
&& (var.start_pc + var.length) <= code.cp);
databuf.appendChar(var.length);
VarSymbol sym = var.sym;
databuf.appendChar(pool.put(sym.name));
......@@ -1195,7 +1054,7 @@ public class ClassWriter extends ClassFile {
databuf.appendChar(pool.put(typeSig(sym.type)));
databuf.appendChar(var.reg);
}
assert count == nGenericVars;
Assert.check(count == nGenericVars);
endAttr(alenIdx);
acount++;
}
......@@ -1266,7 +1125,7 @@ public class ClassWriter extends ClassFile {
}
break;
case JSR202: {
assert code.stackMapBuffer == null;
Assert.checkNull(code.stackMapBuffer);
for (int i=0; i<nframes; i++) {
if (debugstackmap) System.out.print(" " + i + ":");
StackMapTableFrame frame = code.stackMapTableBuffer[i];
......@@ -1606,7 +1465,7 @@ public class ClassWriter extends ClassFile {
*/
public void writeClassFile(OutputStream out, ClassSymbol c)
throws IOException, PoolOverflow, StringOverflow {
assert (c.flags() & COMPOUND) == 0;
Assert.check((c.flags() & COMPOUND) == 0);
databuf.reset();
poolbuf.reset();
sigbuf.reset();
......@@ -1643,7 +1502,7 @@ public class ClassWriter extends ClassFile {
case MTH: if ((e.sym.flags() & HYPOTHETICAL) == 0) methodsCount++;
break;
case TYP: enterInner((ClassSymbol)e.sym); break;
default : assert false;
default : Assert.error();
}
}
databuf.appendChar(fieldsCount);
......@@ -1659,7 +1518,7 @@ public class ClassWriter extends ClassFile {
for (List<Type> l = interfaces; !sigReq && l.nonEmpty(); l = l.tail)
sigReq = l.head.allparams().length() != 0;
if (sigReq) {
assert source.allowGenerics();
Assert.check(source.allowGenerics());
int alenIdx = writeAttr(names.Signature);
if (typarams.length() != 0) assembleParamsSig(typarams);
assembleSig(supertype);
......@@ -1698,7 +1557,6 @@ public class ClassWriter extends ClassFile {
acount += writeFlagAttrs(c.flags());
acount += writeJavaAnnotations(c.getAnnotationMirrors());
acount += writeTypeAnnotations(c.typeAnnotations);
acount += writeEnclosingMethodAttribute(c);
poolbuf.appendInt(JAVA_MAGIC);
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -372,7 +372,7 @@ public class Code {
}
void postop() {
assert alive || state.stacksize == 0;
Assert.check(alive || state.stacksize == 0);
}
/** Emit a multinewarray instruction.
......@@ -583,7 +583,7 @@ public class Code {
case areturn:
case ireturn:
case freturn:
assert state.nlocks == 0;
Assert.check(state.nlocks == 0);
state.pop(1);
markDead();
break;
......@@ -604,7 +604,7 @@ public class Code {
break;
case lreturn:
case dreturn:
assert state.nlocks == 0;
Assert.check(state.nlocks == 0);
state.pop(2);
markDead();
break;
......@@ -612,7 +612,7 @@ public class Code {
state.push(state.stack[state.stacksize-1]);
break;
case return_:
assert state.nlocks == 0;
Assert.check(state.nlocks == 0);
markDead();
break;
case arraylength:
......@@ -1147,7 +1147,7 @@ public class Code {
int pc = curPc();
alive = true;
this.state = state.dup();
assert state.stacksize <= max_stack;
Assert.check(state.stacksize <= max_stack);
if (debugCode) System.err.println("entry point " + state);
pendingStackMap = needStackMap;
return pc;
......@@ -1160,7 +1160,7 @@ public class Code {
int pc = curPc();
alive = true;
this.state = state.dup();
assert state.stacksize <= max_stack;
Assert.check(state.stacksize <= max_stack);
this.state.push(pushed);
if (debugCode) System.err.println("entry point " + state);
pendingStackMap = needStackMap;
......@@ -1289,7 +1289,7 @@ public class Code {
}
frame.locals = new Type[localCount];
for (int i=0, j=0; i<localsSize; i++, j++) {
assert(j < localCount);
Assert.check(j < localCount);
frame.locals[j] = locals[i];
if (width(locals[i]) > 1) i++;
}
......@@ -1435,8 +1435,8 @@ public class Code {
boolean changed = false;
State newState = state;
for (; chain != null; chain = chain.next) {
assert state != chain.state;
assert target > chain.pc || state.stacksize == 0;
Assert.check(state != chain.state
&& (target > chain.pc || state.stacksize == 0));
if (target >= cp) {
target = cp;
} else if (get1(target) == goto_) {
......@@ -1464,9 +1464,9 @@ public class Code {
fatcode = true;
else
put2(chain.pc + 1, target - chain.pc);
assert !alive ||
Assert.check(!alive ||
chain.state.stacksize == newState.stacksize &&
chain.state.nlocks == newState.nlocks;
chain.state.nlocks == newState.nlocks);
}
fixedPc = true;
if (cp == target) {
......@@ -1481,7 +1481,7 @@ public class Code {
}
}
}
assert !changed || state != newState;
Assert.check(!changed || state != newState);
if (state != newState) {
setDefined(newState.defined);
state = newState;
......@@ -1492,11 +1492,11 @@ public class Code {
/** Resolve chain to point to current code pointer.
*/
public void resolve(Chain chain) {
assert
Assert.check(
!alive ||
chain==null ||
state.stacksize == chain.state.stacksize &&
state.nlocks == chain.state.nlocks;
state.nlocks == chain.state.nlocks);
pendingJumps = mergeChains(chain, pendingJumps);
}
......@@ -1514,9 +1514,9 @@ public class Code {
// recursive merge sort
if (chain2 == null) return chain1;
if (chain1 == null) return chain2;
assert
Assert.check(
chain1.state.stacksize == chain2.state.stacksize &&
chain1.state.nlocks == chain2.state.nlocks;
chain1.state.nlocks == chain2.state.nlocks);
if (chain1.pc < chain2.pc)
return new Chain(
chain2.pc,
......@@ -1631,7 +1631,7 @@ public class Code {
void unlock(int register) {
nlocks--;
assert locks[nlocks] == register;
Assert.check(locks[nlocks] == register);
locks[nlocks] = -1;
}
......@@ -1673,7 +1673,7 @@ public class Code {
stacksize--;
Type result = stack[stacksize];
stack[stacksize] = null;
assert result != null && width(result) == 1;
Assert.check(result != null && width(result) == 1);
return result;
}
......@@ -1686,8 +1686,8 @@ public class Code {
stacksize -= 2;
Type result = stack[stacksize];
stack[stacksize] = null;
assert stack[stacksize+1] == null;
assert result != null && width(result) == 2;
Assert.check(stack[stacksize+1] == null
&& result != null && width(result) == 2);
return result;
}
......@@ -1712,8 +1712,8 @@ public class Code {
case ARRAY:
int width = width(t);
Type old = stack[stacksize-width];
assert types.isSubtype(types.erasure(old),
types.erasure(t));
Assert.check(types.isSubtype(types.erasure(old),
types.erasure(t)));
stack[stacksize-width] = t;
break;
default:
......@@ -1739,8 +1739,8 @@ public class Code {
State join(State other) {
defined = defined.andSet(other.defined);
assert stacksize == other.stacksize;
assert nlocks == other.nlocks;
Assert.check(stacksize == other.stacksize
&& nlocks == other.nlocks);
for (int i=0; i<stacksize; ) {
Type t = stack[i];
Type tother = other.stack[i];
......@@ -1751,7 +1751,7 @@ public class Code {
error();
int w = width(result);
stack[i] = result;
if (w == 2) assert stack[i+1] == null;
if (w == 2) Assert.checkNull(stack[i+1]);
i += w;
}
return this;
......@@ -1847,7 +1847,7 @@ public class Code {
System.arraycopy(lvar, 0, new_lvar, 0, lvar.length);
lvar = new_lvar;
}
assert lvar[adr] == null;
Assert.checkNull(lvar[adr]);
if (pendingJumps != null) resolvePending();
lvar[adr] = new LocalVar(v);
state.defined.excl(adr);
......@@ -1912,29 +1912,12 @@ public class Code {
if (length < Character.MAX_VALUE) {
v.length = length;
putVar(v);
fillLocalVarPosition(v);
}
}
}
state.defined.excl(adr);
}
private void fillLocalVarPosition(LocalVar lv) {
if (lv == null || lv.sym == null
|| lv.sym.typeAnnotations == null)
return;
for (Attribute.TypeCompound ta : lv.sym.typeAnnotations) {
TypeAnnotationPosition p = ta.position;
while (p != null) {
p.lvarOffset = new int[] { (int)lv.start_pc };
p.lvarLength = new int[] { (int)lv.length };
p.lvarIndex = new int[] { (int)lv.reg };
p.isValidOffset = true;
p = p.wildcard_position;
}
}
}
/** Put a live variable range into the buffer to be output to the
* class file.
*/
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -500,7 +500,7 @@ public class Gen extends JCTree.Visitor {
}
break;
default:
assert false;
Assert.error();
}
}
// Insert any instance initializers into all constructors.
......@@ -857,7 +857,7 @@ public class Gen extends JCTree.Visitor {
pts = pts.tail;
}
// require lists be of same length
assert pts.isEmpty();
Assert.check(pts.isEmpty());
}
/* ************************************************************************
......@@ -1111,7 +1111,7 @@ public class Gen extends JCTree.Visitor {
public void visitSwitch(JCSwitch tree) {
int limit = code.nextreg;
assert tree.selector.type.tag != CLASS;
Assert.check(tree.selector.type.tag != CLASS);
int startpcCrt = genCrt ? code.curPc() : 0;
Item sel = genExpr(tree.selector, syms.intType);
List<JCCase> cases = tree.cases;
......@@ -1148,7 +1148,7 @@ public class Gen extends JCTree.Visitor {
if (hi < val) hi = val;
nlabels++;
} else {
assert defaultIndex == -1;
Assert.check(defaultIndex == -1);
defaultIndex = i;
}
l = l.tail;
......@@ -1290,7 +1290,7 @@ public class Gen extends JCTree.Visitor {
syncEnv.info.finalize = new GenFinalizer() {
void gen() {
genLast();
assert syncEnv.info.gaps.length() % 2 == 0;
Assert.check(syncEnv.info.gaps.length() % 2 == 0);
syncEnv.info.gaps.append(code.curPc());
}
void genLast() {
......@@ -1329,10 +1329,10 @@ public class Gen extends JCTree.Visitor {
tryEnv.info.cont,
jsrState);
}
assert tryEnv.info.gaps.length() % 2 == 0;
Assert.check(tryEnv.info.gaps.length() % 2 == 0);
tryEnv.info.gaps.append(code.curPc());
} else {
assert tryEnv.info.gaps.length() % 2 == 0;
Assert.check(tryEnv.info.gaps.length() % 2 == 0);
tryEnv.info.gaps.append(code.curPc());
genLast();
}
......@@ -1640,14 +1640,14 @@ public class Gen extends JCTree.Visitor {
public void visitBreak(JCBreak tree) {
Env<GenContext> targetEnv = unwind(tree.target, env);
assert code.state.stacksize == 0;
Assert.check(code.state.stacksize == 0);
targetEnv.info.addExit(code.branch(goto_));
endFinalizerGaps(env, targetEnv);
}
public void visitContinue(JCContinue tree) {
Env<GenContext> targetEnv = unwind(tree.target, env);
assert code.state.stacksize == 0;
Assert.check(code.state.stacksize == 0);
targetEnv.info.addCont(code.branch(goto_));
endFinalizerGaps(env, targetEnv);
}
......@@ -1682,7 +1682,6 @@ public class Gen extends JCTree.Visitor {
*************************************************************************/
public void visitApply(JCMethodInvocation tree) {
setTypeAnnotationPositions(tree.pos);
// Generate code for method.
Item m = genExpr(tree.meth, methodType);
// Generate code for all arguments, where the expected types are
......@@ -1718,48 +1717,10 @@ public class Gen extends JCTree.Visitor {
result = items.makeStackItem(pt);
}
private void setTypeAnnotationPositions(int treePos) {
MethodSymbol meth = code.meth;
for (Attribute.TypeCompound ta : meth.typeAnnotations) {
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset = new int[] { code.cp };
ta.position.isValidOffset = true;
}
}
if (code.meth.getKind() != ElementKind.CONSTRUCTOR
&& code.meth.getKind() != ElementKind.STATIC_INIT)
return;
for (Attribute.TypeCompound ta : meth.owner.typeAnnotations) {
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset = new int[] { code.cp };
ta.position.isValidOffset = true;
}
}
ClassSymbol clazz = meth.enclClass();
for (Symbol s : new com.sun.tools.javac.model.FilteredMemberList(clazz.members())) {
if (!s.getKind().isField())
continue;
for (Attribute.TypeCompound ta : s.typeAnnotations) {
if (ta.position.pos == treePos) {
ta.position.offset = code.cp;
ta.position.lvarOffset = new int[] { code.cp };
ta.position.isValidOffset = true;
}
}
}
}
public void visitNewClass(JCNewClass tree) {
// Enclosing instances or anonymous classes should have been eliminated
// by now.
assert tree.encl == null && tree.def == null;
setTypeAnnotationPositions(tree.pos);
Assert.check(tree.encl == null && tree.def == null);
code.emitop2(new_, makeRef(tree.pos(), tree.type));
code.emitop0(dup);
......@@ -1774,7 +1735,6 @@ public class Gen extends JCTree.Visitor {
}
public void visitNewArray(JCNewArray tree) {
setTypeAnnotationPositions(tree.pos);
if (tree.elems != null) {
Type elemtype = types.elemtype(tree.type);
......@@ -1942,7 +1902,7 @@ public class Gen extends JCTree.Visitor {
genNullCheck(tree.pos());
break;
default:
assert false;
Assert.error();
}
}
}
......@@ -2017,7 +1977,7 @@ public class Gen extends JCTree.Visitor {
items.makeMemberItem(getStringBufferAppend(tree, t), false).invoke();
}
Symbol getStringBufferAppend(JCTree tree, Type t) {
assert t.constValue() == null;
Assert.checkNull(t.constValue());
Symbol method = stringBufferAppend.get(t);
if (method == null) {
method = rs.resolveInternalMethod(tree.pos(),
......@@ -2104,7 +2064,6 @@ public class Gen extends JCTree.Visitor {
}
public void visitTypeCast(JCTypeCast tree) {
setTypeAnnotationPositions(tree.pos);
result = genExpr(tree.expr, tree.clazz.type).load();
// Additional code is only needed if we cast to a reference type
// which is not statically a supertype of the expression's type.
......@@ -2121,8 +2080,6 @@ public class Gen extends JCTree.Visitor {
}
public void visitTypeTest(JCInstanceOf tree) {
setTypeAnnotationPositions(tree.pos);
genExpr(tree.expr, tree.expr.type).load();
code.emitop2(instanceof_, makeRef(tree.pos(), tree.clazz.type));
result = items.makeStackItem(syms.booleanType);
......@@ -2163,16 +2120,10 @@ public class Gen extends JCTree.Visitor {
Symbol sym = tree.sym;
if (tree.name == names._class) {
assert target.hasClassLiterals();
setTypeAnnotationPositions(tree.pos);
Assert.check(target.hasClassLiterals());
code.emitop2(ldc2, makeRef(tree.pos(), tree.selected.type));
result = items.makeStackItem(pt);
return;
} else if (tree.name == names.TYPE) {
// Set the annotation positions for primitive class literals
// (e.g. int.class) which have been converted to TYPE field
// access on the corresponding boxed type (e.g. Integer.TYPE).
setTypeAnnotationPositions(tree.pos);
}
Symbol ssym = TreeInfo.symbol(tree.selected);
......@@ -2202,9 +2153,6 @@ public class Gen extends JCTree.Visitor {
}
result = items.
makeImmediateItem(sym.type, ((VarSymbol) sym).getConstValue());
} else if (allowInvokedynamic && sym.kind == MTH && ssym == syms.invokeDynamicType.tsym) {
base.drop();
result = items.makeDynamicItem(sym);
} else {
if (!accessSuper)
sym = binaryQualifier(sym, tree.selected.type);
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -848,7 +848,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
break;
default:
assert false: "unknown compile policy";
Assert.error("unknown compile policy");
}
} catch (Abort ex) {
if (devVerbose)
......@@ -1066,7 +1066,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
classSymbols = classSymbols.prepend((ClassSymbol)sym);
continue;
}
assert sym.kind == Kinds.PCK;
Assert.check(sym.kind == Kinds.PCK);
log.warning("proc.package.does.not.exist", nameStr);
pckSymbols = pckSymbols.prepend((PackageSymbol)sym);
} catch (CompletionFailure e) {
......@@ -1086,8 +1086,8 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
if (c != this)
annotationProcessingOccurred = c.annotationProcessingOccurred = true;
// doProcessing will have handled deferred diagnostics
assert c.log.deferDiagnostics == false;
assert c.log.deferredDiagnostics.size() == 0;
Assert.check(c.log.deferDiagnostics == false
&& c.log.deferredDiagnostics.size() == 0);
return c;
} finally {
procEnvImpl.close();
......@@ -1324,7 +1324,7 @@ public class JavaCompiler implements ClassReader.SourceCompleter {
return;
List<JCTree> pdef = lower.translateTopLevelClass(env, env.tree, localMake);
if (pdef.head != null) {
assert pdef.tail.isEmpty();
Assert.check(pdef.tail.isEmpty());
results.add(new Pair<Env<AttrContext>, JCClassDecl>(env, (JCClassDecl)pdef.head));
}
}
......
......@@ -284,13 +284,6 @@ public class Main {
}
}
// phase this out with JSR 292 PFD
if ("no".equals(options.get("allowTransitionalJSR292"))) {
options.put("allowTransitionalJSR292", null);
} else if (target.hasInvokedynamic() && options.isUnset("allowTransitionalJSR292")) {
options.put("allowTransitionalJSR292", "allowTransitionalJSR292");
}
// handle this here so it works even if no other options given
String showClass = options.get("showClass");
if (showClass != null) {
......
/*
* Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2011, 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
......@@ -445,7 +445,7 @@ public class Scanner implements Lexer {
*/
private void scanHexFractionAndSuffix(boolean seendigit) {
this.radix = 16;
assert ch == '.';
Assert.check(ch == '.');
putChar(ch);
scanChar();
skipIllegalUnderscores();
......
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册