< prev index next > src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
Print this page
import static com.sun.tools.javac.code.Flags.DEFAULT;
import static com.sun.tools.javac.code.Flags.FINAL;
import static com.sun.tools.javac.code.Flags.INTERFACE;
import static com.sun.tools.javac.code.Flags.LAMBDA_METHOD;
import static com.sun.tools.javac.code.Flags.LOCAL_CAPTURE_FIELD;
+ import static com.sun.tools.javac.code.Flags.OUTER_THIS_FIELD;
import static com.sun.tools.javac.code.Flags.PARAMETER;
import static com.sun.tools.javac.code.Flags.PRIVATE;
import static com.sun.tools.javac.code.Flags.STATIC;
import static com.sun.tools.javac.code.Flags.STRICTFP;
import static com.sun.tools.javac.code.Flags.SYNTHETIC;
(tree.sym.kind == VAR || tree.sym.kind == MTH) &&
!seenClasses.contains(tree.sym.owner)) {
if ((tree.sym.flags() & LOCAL_CAPTURE_FIELD) != 0) {
// a local, captured by Lower - re-capture!
addFreeVar((VarSymbol) tree.sym);
+ } else if (isEarlyInstanceFieldInit() &&
+ (tree.sym.flags() & OUTER_THIS_FIELD) != 0) {
+ // If we're in early strict instance initializer we can't assume this$0 is
+ // accessible. So we should make the lambda method static, and deal with
+ // this$0 as if it were a regular capture. This works because language rules
+ // prevent direct access to this/super, so a static lambda method should
+ // always be ok as a translation target in a ctor prologue.
+ addFreeVar((VarSymbol) tree.sym);
} else {
// a reference to an enclosing field or method, we need to capture 'this'
capturesThis = true;
}
} else {
@Override
public void visitAnnotation(JCAnnotation tree) {
// do nothing (annotation values look like captured instance fields)
}
+
+ private boolean isEarlyInstanceFieldInit() {
+ return pendingVar != null &&
+ pendingVar.isStrictInstance();
+ }
}
/*
* These keys provide mappings for various translated lambda symbols
* and the prevailing order must be maintained.
< prev index next >