mirror of
https://github.com/openjdk/jdk.git
synced 2026-03-06 14:10:36 +00:00
8016569: javac, add new flag for polymorphic method signatures
Reviewed-by: jjg
This commit is contained in:
parent
3596018eb7
commit
44641445d7
@ -278,6 +278,11 @@ public class Flags {
|
||||
*/
|
||||
public static final long BAD_OVERRIDE = 1L<<45;
|
||||
|
||||
/**
|
||||
* Flag that indicates a signature polymorphic method (292).
|
||||
*/
|
||||
public static final long SIGNATURE_POLYMORPHIC = 1L<<46;
|
||||
|
||||
/** Modifier masks.
|
||||
*/
|
||||
public static final int
|
||||
|
||||
@ -1537,25 +1537,6 @@ public abstract class Symbol implements Element {
|
||||
getKind() == ElementKind.INSTANCE_INIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
|
||||
* (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
|
||||
* a single variable arity parameter (iii) whose declared type is Object[],
|
||||
* (iv) has a return type of Object and (v) is native.
|
||||
*/
|
||||
public boolean isSignaturePolymorphic(Types types) {
|
||||
List<Type> argtypes = type.getParameterTypes();
|
||||
Type firstElemType = argtypes.nonEmpty() ?
|
||||
types.elemtype(argtypes.head) :
|
||||
null;
|
||||
return owner == types.syms.methodHandleType.tsym &&
|
||||
argtypes.length() == 1 &&
|
||||
firstElemType != null &&
|
||||
types.isSameType(firstElemType, types.syms.objectType) &&
|
||||
types.isSameType(type.getReturnType(), types.syms.objectType) &&
|
||||
(flags() & NATIVE) != 0;
|
||||
}
|
||||
|
||||
public Attribute getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
@ -950,6 +950,22 @@ public class Types {
|
||||
/*inlined: ts.isEmpty() && ss.isEmpty();*/
|
||||
}
|
||||
|
||||
/**
|
||||
* A polymorphic signature method (JLS SE 7, 8.4.1) is a method that
|
||||
* (i) is declared in the java.lang.invoke.MethodHandle class, (ii) takes
|
||||
* a single variable arity parameter (iii) whose declared type is Object[],
|
||||
* (iv) has a return type of Object and (v) is native.
|
||||
*/
|
||||
public boolean isSignaturePolymorphic(MethodSymbol msym) {
|
||||
List<Type> argtypes = msym.type.getParameterTypes();
|
||||
return (msym.flags_field & NATIVE) != 0 &&
|
||||
msym.owner == syms.methodHandleType.tsym &&
|
||||
argtypes.tail.tail == null &&
|
||||
argtypes.head.hasTag(TypeTag.ARRAY) &&
|
||||
msym.type.getReturnType().tsym == syms.objectType.tsym &&
|
||||
((ArrayType)argtypes.head).elemtype.tsym == syms.objectType.tsym;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is t the same type as s?
|
||||
*/
|
||||
|
||||
@ -3405,7 +3405,7 @@ public class Attr extends JCTree.Visitor {
|
||||
Env<AttrContext> env,
|
||||
ResultInfo resultInfo) {
|
||||
boolean isPolymorhicSignature =
|
||||
sym.kind == MTH && ((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types);
|
||||
(sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) != 0;
|
||||
return isPolymorhicSignature ?
|
||||
checkSigPolyMethodId(tree, site, sym, env, resultInfo) :
|
||||
checkMethodIdInternal(tree, site, sym, env, resultInfo);
|
||||
|
||||
@ -909,7 +909,7 @@ public class Check {
|
||||
"unchecked.generic.array.creation",
|
||||
argtype);
|
||||
}
|
||||
if (!((MethodSymbol)sym.baseSymbol()).isSignaturePolymorphic(types)) {
|
||||
if ((sym.baseSymbol().flags() & SIGNATURE_POLYMORPHIC) == 0) {
|
||||
TreeInfo.setVarargsElement(env.tree, types.elemtype(argtype));
|
||||
}
|
||||
}
|
||||
|
||||
@ -560,6 +560,10 @@ public class MemberEnter extends JCTree.Visitor implements Completer {
|
||||
chk.setDeferredLintHandler(prevLintHandler);
|
||||
}
|
||||
|
||||
if (types.isSignaturePolymorphic(m)) {
|
||||
m.flags_field |= SIGNATURE_POLYMORPHIC;
|
||||
}
|
||||
|
||||
// Set m.params
|
||||
ListBuffer<VarSymbol> params = new ListBuffer<VarSymbol>();
|
||||
JCVariableDecl lastParam = null;
|
||||
|
||||
@ -2267,7 +2267,7 @@ public class Resolve {
|
||||
sym = super.access(env, pos, location, sym);
|
||||
} else if (allowMethodHandles) {
|
||||
MethodSymbol msym = (MethodSymbol)sym;
|
||||
if (msym.isSignaturePolymorphic(types)) {
|
||||
if ((msym.flags() & SIGNATURE_POLYMORPHIC) != 0) {
|
||||
return findPolymorphicSignatureInstance(env, sym, argtypes);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1985,6 +1985,9 @@ public class ClassReader implements Completer {
|
||||
syms.methodClass);
|
||||
}
|
||||
MethodSymbol m = new MethodSymbol(flags, name, type, currentOwner);
|
||||
if (types.isSignaturePolymorphic(m)) {
|
||||
m.flags_field |= SIGNATURE_POLYMORPHIC;
|
||||
}
|
||||
if (saveParameterNames)
|
||||
initParameterNames(m);
|
||||
Symbol prevOwner = currentOwner;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user