Java Code Examples for com.sun.tools.javac.code.Type#getParameterTypes()
The following examples show how to use
com.sun.tools.javac.code.Type#getParameterTypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LambdaToMethod.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 2
Source File: LambdaToMethod.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 3
Source File: LambdaToMethod.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 4
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 5
Source File: JNIWriter.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
StringBuilder getParameterSignature(Type mType) throws SignatureException { StringBuilder result = new StringBuilder(); for (Type pType : mType.getParameterTypes()) { result.append(getJvmSignature(pType)); } return result; }
Example 6
Source File: TransTypes.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void visitNewClass(JCNewClass tree) { if (tree.encl != null) { if (tree.def == null) { tree.encl = translate(tree.encl, erasure(tree.encl.type)); } else { tree.args = tree.args.prepend(attr.makeNullCheck(tree.encl)); tree.encl = null; } } Type erasedConstructorType = tree.constructorType != null ? erasure(tree.constructorType) : null; List<Type> argtypes = erasedConstructorType != null && allowGraphInference ? erasedConstructorType.getParameterTypes() : tree.constructor.erasure(types).getParameterTypes(); tree.clazz = translate(tree.clazz, null); if (tree.varargsElement != null) tree.varargsElement = types.erasure(tree.varargsElement); tree.args = translateArgs( tree.args, argtypes, tree.varargsElement); tree.def = translate(tree.def, null); if (erasedConstructorType != null) tree.constructorType = erasedConstructorType; tree.type = erasure(tree.type); result = tree; }
Example 7
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 8
Source File: LambdaToMethod.java From hottub with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 9
Source File: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 10
Source File: JNIWriter.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
StringBuilder getParameterSignature(Type mType) throws SignatureException { StringBuilder result = new StringBuilder(); for (Type pType : mType.getParameterTypes()) { result.append(getJvmSignature(pType)); } return result; }
Example 11
Source File: LambdaToMethod.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private MethodType typeToMethodType(Type mt) { Type type = types.erasure(mt); return new MethodType(type.getParameterTypes(), type.getReturnType(), type.getThrownTypes(), syms.methodClass); }
Example 12
Source File: LambdaToMethod.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Generate the bridge */ JCMethodDecl bridge() { int prevPos = make.pos; try { make.at(tree); Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); //an extra argument is prepended to the signature of the bridge in case //the member reference is an instance method reference (in which case //the receiver expression is passed to the bridge itself). Type recType = null; switch (tree.kind) { case IMPLICIT_INNER: recType = tree.sym.owner.type.getEnclosingType(); break; case BOUND: recType = tree.getQualifierExpression().type; break; case UNBOUND: recType = samPTypes.head; samPTypes = samPTypes.tail; break; } //generate the parameter list for the bridged member reference - the //bridge signature will match the signature of the target sam descriptor VarSymbol rcvr = (recType == null) ? null : addParameter("rec$", recType, false); List<Type> refPTypes = tree.sym.type.getParameterTypes(); int refSize = refPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize; List<Type> l = refPTypes; // Use parameter types of the referenced method, excluding final var args for (int i = 0; l.nonEmpty() && i < last; ++i) { addParameter("x$" + i, l.head, true); l = l.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } //generate the bridge method declaration JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()), localContext.bridgeSym.name, make.QualIdent(samDesc.getReturnType().tsym), List.<JCTypeParameter>nil(), params.toList(), tree.sym.type.getThrownTypes() == null ? List.<JCExpression>nil() : make.Types(tree.sym.type.getThrownTypes()), null, null); bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym; bridgeDecl.type = localContext.bridgeSym.type = types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList())); //bridge method body generation - this can be either a method call or a //new instance creation expression, depending on the member reference kind JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE) ? bridgeExpressionInvoke(makeReceiver(rcvr)) : bridgeExpressionNew(); //the body is either a return expression containing a method call, //or the method call itself, depending on whether the return type of //the bridge is non-void/void. bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl); return bridgeDecl; } finally { make.at(prevPos); } }
Example 13
Source File: LambdaToMethod.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 14
Source File: LambdaToMethod.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Generate the bridge */ JCMethodDecl bridge() { int prevPos = make.pos; try { make.at(tree); Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); //an extra argument is prepended to the signature of the bridge in case //the member reference is an instance method reference (in which case //the receiver expression is passed to the bridge itself). Type recType = null; switch (tree.kind) { case IMPLICIT_INNER: recType = tree.sym.owner.type.getEnclosingType(); break; case BOUND: recType = tree.getQualifierExpression().type; break; case UNBOUND: recType = samPTypes.head; samPTypes = samPTypes.tail; break; } //generate the parameter list for the bridged member reference - the //bridge signature will match the signature of the target sam descriptor VarSymbol rcvr = (recType == null) ? null : addParameter("rec$", recType, false); List<Type> refPTypes = tree.sym.type.getParameterTypes(); int refSize = refPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method int last = localContext.needsVarArgsConversion() ? refSize - 1 : refSize; List<Type> l = refPTypes; // Use parameter types of the referenced method, excluding final var args for (int i = 0; l.nonEmpty() && i < last; ++i) { addParameter("x$" + i, l.head, true); l = l.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } //generate the bridge method declaration JCMethodDecl bridgeDecl = make.MethodDef(make.Modifiers(localContext.bridgeSym.flags()), localContext.bridgeSym.name, make.QualIdent(samDesc.getReturnType().tsym), List.<JCTypeParameter>nil(), params.toList(), tree.sym.type.getThrownTypes() == null ? List.<JCExpression>nil() : make.Types(tree.sym.type.getThrownTypes()), null, null); bridgeDecl.sym = (MethodSymbol) localContext.bridgeSym; bridgeDecl.type = localContext.bridgeSym.type = types.createMethodTypeWithParameters(samDesc, TreeInfo.types(params.toList())); //bridge method body generation - this can be either a method call or a //new instance creation expression, depending on the member reference kind JCExpression bridgeExpr = (tree.getMode() == ReferenceMode.INVOKE) ? bridgeExpressionInvoke(makeReceiver(rcvr)) : bridgeExpressionNew(); //the body is either a return expression containing a method call, //or the method call itself, depending on whether the return type of //the bridge is non-void/void. bridgeDecl.body = makeLambdaExpressionBody(bridgeExpr, bridgeDecl); return bridgeDecl; } finally { make.at(prevPos); } }
Example 15
Source File: LambdaToMethod.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 16
Source File: LambdaToMethod.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 17
Source File: LambdaToMethod.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 18
Source File: LambdaToMethod.java From lua-for-android with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 19
Source File: LambdaToMethod.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }
Example 20
Source File: LambdaToMethod.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
/** * Generate the parameter list for the converted member reference. * * @return The receiver variable symbol, if any */ VarSymbol addParametersReturnReceiver() { Type samDesc = localContext.bridgedRefSig(); List<Type> samPTypes = samDesc.getParameterTypes(); List<Type> descPTypes = tree.getDescriptorType(types).getParameterTypes(); // Determine the receiver, if any VarSymbol rcvr; switch (tree.kind) { case BOUND: // The receiver is explicit in the method reference rcvr = addParameter("rec$", tree.getQualifierExpression().type, false); receiverExpression = attr.makeNullCheck(tree.getQualifierExpression()); break; case UNBOUND: // The receiver is the first parameter, extract it and // adjust the SAM and unerased type lists accordingly rcvr = addParameter("rec$", samDesc.getParameterTypes().head, false); samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; break; default: rcvr = null; break; } List<Type> implPTypes = tree.sym.type.getParameterTypes(); int implSize = implPTypes.size(); int samSize = samPTypes.size(); // Last parameter to copy from referenced method, exclude final var args int last = localContext.needsVarArgsConversion() ? implSize - 1 : implSize; // Failsafe -- assure match-up boolean checkForIntersection = tree.varargsElement != null || implSize == descPTypes.size(); // Use parameter types of the implementation method unless the unerased // SAM parameter type is an intersection type, in that case use the // erased SAM parameter type so that the supertype relationship // the implementation method parameters is not obscured. // Note: in this loop, the lists implPTypes, samPTypes, and descPTypes // are used as pointers to the current parameter type information // and are thus not usable afterwards. for (int i = 0; implPTypes.nonEmpty() && i < last; ++i) { // By default use the implementation method parmeter type Type parmType = implPTypes.head; // If the unerased parameter type is a type variable whose // bound is an intersection (eg. <T extends A & B>) then // use the SAM parameter type if (checkForIntersection && descPTypes.head.getKind() == TypeKind.TYPEVAR) { TypeVar tv = (TypeVar) descPTypes.head; if (tv.bound.getKind() == TypeKind.INTERSECTION) { parmType = samPTypes.head; } } addParameter("x$" + i, parmType, true); // Advance to the next parameter implPTypes = implPTypes.tail; samPTypes = samPTypes.tail; descPTypes = descPTypes.tail; } // Flatten out the var args for (int i = last; i < samSize; ++i) { addParameter("xva$" + i, tree.varargsElement, true); } return rcvr; }