355 boolean init;
356 if ((init = (owner.name == names.init)) || owner.name == names.clinit) {
357 owner = owner.owner;
358 apportionTypeAnnotations(tree,
359 init ? owner::getInitTypeAttributes : owner::getClassInitTypeAttributes,
360 init ? owner::setInitTypeAttributes : owner::setClassInitTypeAttributes,
361 sym::appendUniqueTypeAttributes);
362 }
363 if (localContext.self != null && localContext.self.getKind() == ElementKind.FIELD) {
364 owner = localContext.self;
365 apportionTypeAnnotations(tree,
366 owner::getRawTypeAttributes,
367 owner::setTypeAttributes,
368 sym::appendUniqueTypeAttributes);
369 }
370 }
371
372 //create the method declaration hoisting the lambda body
373 JCMethodDecl lambdaDecl = make.MethodDef(make.Modifiers(sym.flags_field),
374 sym.name,
375 make.QualIdent(lambdaType.getReturnType().tsym),
376 List.nil(),
377 localContext.syntheticParams,
378 lambdaType.getThrownTypes() == null ?
379 List.nil() :
380 make.Types(lambdaType.getThrownTypes()),
381 null,
382 null);
383 lambdaDecl.sym = sym;
384 lambdaDecl.type = lambdaType;
385
386 //translate lambda body
387 //As the lambda body is translated, all references to lambda locals,
388 //captured variables, enclosing members are adjusted accordingly
389 //to refer to the static method parameters (rather than i.e. accessing
390 //captured members directly).
391 lambdaDecl.body = translate(makeLambdaBody(tree, lambdaDecl));
392
393 boolean dedupe = false;
394 if (deduplicateLambdas && !debugLinesOrVars && !localContext.isSerializable()) {
395 DedupedLambda dedupedLambda = new DedupedLambda(lambdaDecl.sym, lambdaDecl.body);
1838 this.owner = owner(true);
1839 this.depth = frameStack.size() - 1;
1840 this.prev = context();
1841 ClassSymbol csym =
1842 types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.target, ABSTRACT | INTERFACE);
1843 this.bridges = types.functionalInterfaceBridges(csym);
1844 }
1845
1846 /** does this functional expression need to be created using alternate metafactory? */
1847 boolean needsAltMetafactory() {
1848 return tree.target.isIntersection() ||
1849 isSerializable() ||
1850 bridges.length() > 1;
1851 }
1852
1853 /** does this functional expression require serialization support? */
1854 boolean isSerializable() {
1855 if (forceSerializable) {
1856 return true;
1857 }
1858 return types.asSuper(tree.target, syms.serializableType.tsym) != null;
1859 }
1860
1861 /**
1862 * @return Name of the enclosing method to be folded into synthetic
1863 * method name
1864 */
1865 String enclosingMethodName() {
1866 return syntheticMethodNameComponent(owner.name);
1867 }
1868
1869 /**
1870 * @return Method name in a form that can be folded into a
1871 * component of a synthetic method name
1872 */
1873 String syntheticMethodNameComponent(Name name) {
1874 if (name == null) {
1875 return "null";
1876 }
1877 String methodName = name.toString();
1878 if (methodName.equals("<clinit>")) {
2315 TypeVar tv = (TypeVar) t;
2316 return isIntersectionOrUnionType(tv.getUpperBound());
2317 }
2318 return false;
2319 }
2320
2321 /**
2322 * Does this reference need to be converted to a lambda
2323 * (i.e. var args need to be expanded or "super" is used)
2324 */
2325 final boolean needsConversionToLambda() {
2326 return interfaceParameterIsIntersectionOrUnionType() ||
2327 isSuper ||
2328 needsVarArgsConversion() ||
2329 isArrayOp() ||
2330 (!nestmateLambdas && isPrivateInOtherClass()) ||
2331 isProtectedInSuperClassOfEnclosingClassInOtherPackage(tree.sym, owner) ||
2332 !receiverAccessible() ||
2333 (tree.getMode() == ReferenceMode.NEW &&
2334 tree.kind != ReferenceKind.ARRAY_CTOR &&
2335 (tree.sym.owner.isDirectlyOrIndirectlyLocal() || tree.sym.owner.isInner()));
2336 }
2337
2338 Type generatedRefSig() {
2339 return types.erasure(tree.sym.type);
2340 }
2341
2342 Type bridgedRefSig() {
2343 return types.erasure(types.findDescriptorSymbol(tree.target.tsym).type);
2344 }
2345 }
2346 }
2347 // </editor-fold>
2348
2349 /*
2350 * These keys provide mappings for various translated lambda symbols
2351 * and the prevailing order must be maintained.
2352 */
2353 enum LambdaSymbolKind {
2354 PARAM, // original to translated lambda parameters
2355 LOCAL_VAR, // original to translated lambda locals
|
355 boolean init;
356 if ((init = (owner.name == names.init)) || owner.name == names.clinit) {
357 owner = owner.owner;
358 apportionTypeAnnotations(tree,
359 init ? owner::getInitTypeAttributes : owner::getClassInitTypeAttributes,
360 init ? owner::setInitTypeAttributes : owner::setClassInitTypeAttributes,
361 sym::appendUniqueTypeAttributes);
362 }
363 if (localContext.self != null && localContext.self.getKind() == ElementKind.FIELD) {
364 owner = localContext.self;
365 apportionTypeAnnotations(tree,
366 owner::getRawTypeAttributes,
367 owner::setTypeAttributes,
368 sym::appendUniqueTypeAttributes);
369 }
370 }
371
372 //create the method declaration hoisting the lambda body
373 JCMethodDecl lambdaDecl = make.MethodDef(make.Modifiers(sym.flags_field),
374 sym.name,
375 make.QualIdent(lambdaType.getReturnType().tsym).setType(lambdaType.getReturnType()),
376 List.nil(),
377 localContext.syntheticParams,
378 lambdaType.getThrownTypes() == null ?
379 List.nil() :
380 make.Types(lambdaType.getThrownTypes()),
381 null,
382 null);
383 lambdaDecl.sym = sym;
384 lambdaDecl.type = lambdaType;
385
386 //translate lambda body
387 //As the lambda body is translated, all references to lambda locals,
388 //captured variables, enclosing members are adjusted accordingly
389 //to refer to the static method parameters (rather than i.e. accessing
390 //captured members directly).
391 lambdaDecl.body = translate(makeLambdaBody(tree, lambdaDecl));
392
393 boolean dedupe = false;
394 if (deduplicateLambdas && !debugLinesOrVars && !localContext.isSerializable()) {
395 DedupedLambda dedupedLambda = new DedupedLambda(lambdaDecl.sym, lambdaDecl.body);
1838 this.owner = owner(true);
1839 this.depth = frameStack.size() - 1;
1840 this.prev = context();
1841 ClassSymbol csym =
1842 types.makeFunctionalInterfaceClass(attrEnv, names.empty, tree.target, ABSTRACT | INTERFACE);
1843 this.bridges = types.functionalInterfaceBridges(csym);
1844 }
1845
1846 /** does this functional expression need to be created using alternate metafactory? */
1847 boolean needsAltMetafactory() {
1848 return tree.target.isIntersection() ||
1849 isSerializable() ||
1850 bridges.length() > 1;
1851 }
1852
1853 /** does this functional expression require serialization support? */
1854 boolean isSerializable() {
1855 if (forceSerializable) {
1856 return true;
1857 }
1858 return types.asSuper(tree.target.referenceProjectionOrSelf(), syms.serializableType.tsym) != null;
1859 }
1860
1861 /**
1862 * @return Name of the enclosing method to be folded into synthetic
1863 * method name
1864 */
1865 String enclosingMethodName() {
1866 return syntheticMethodNameComponent(owner.name);
1867 }
1868
1869 /**
1870 * @return Method name in a form that can be folded into a
1871 * component of a synthetic method name
1872 */
1873 String syntheticMethodNameComponent(Name name) {
1874 if (name == null) {
1875 return "null";
1876 }
1877 String methodName = name.toString();
1878 if (methodName.equals("<clinit>")) {
2315 TypeVar tv = (TypeVar) t;
2316 return isIntersectionOrUnionType(tv.getUpperBound());
2317 }
2318 return false;
2319 }
2320
2321 /**
2322 * Does this reference need to be converted to a lambda
2323 * (i.e. var args need to be expanded or "super" is used)
2324 */
2325 final boolean needsConversionToLambda() {
2326 return interfaceParameterIsIntersectionOrUnionType() ||
2327 isSuper ||
2328 needsVarArgsConversion() ||
2329 isArrayOp() ||
2330 (!nestmateLambdas && isPrivateInOtherClass()) ||
2331 isProtectedInSuperClassOfEnclosingClassInOtherPackage(tree.sym, owner) ||
2332 !receiverAccessible() ||
2333 (tree.getMode() == ReferenceMode.NEW &&
2334 tree.kind != ReferenceKind.ARRAY_CTOR &&
2335 (tree.sym.owner.isDirectlyOrIndirectlyLocal() || tree.sym.owner.isInner() || tree.sym.owner.isValueClass()));
2336 }
2337
2338 Type generatedRefSig() {
2339 return types.erasure(tree.sym.type);
2340 }
2341
2342 Type bridgedRefSig() {
2343 return types.erasure(types.findDescriptorSymbol(tree.target.tsym).type);
2344 }
2345 }
2346 }
2347 // </editor-fold>
2348
2349 /*
2350 * These keys provide mappings for various translated lambda symbols
2351 * and the prevailing order must be maintained.
2352 */
2353 enum LambdaSymbolKind {
2354 PARAM, // original to translated lambda parameters
2355 LOCAL_VAR, // original to translated lambda locals
|