langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java
changeset 31296 9a8e44b62c77
parent 29772 4e4e74b99d27
child 33706 0d21ecb55e6a
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Wed Jul 05 20:38:50 2017 +0200
+++ b/langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java	Tue Jun 23 17:46:23 2015 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 2015, 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
@@ -1197,10 +1197,13 @@
                         //if a class is defined within a lambda, the lambda must capture
                         //its enclosing instance (if any)
                         TranslationContext<?> localContext = context();
-                        while (localContext != null) {
-                            if (localContext.tree.getTag() == LAMBDA) {
+                        final TypeSymbol outerInstanceSymbol = tree.sym.type.getEnclosingType().tsym;
+                        while (localContext != null && !localContext.owner.isStatic()) {
+                            if (localContext.tree.hasTag(LAMBDA)) {
+                                JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol);
+                                if (block == null) break;
                                 ((LambdaTranslationContext)localContext)
-                                        .addSymbol(tree.sym.type.getEnclosingType().tsym, CAPTURED_THIS);
+                                        .addSymbol(outerInstanceSymbol, CAPTURED_THIS);
                             }
                             localContext = localContext.prev;
                         }
@@ -1236,7 +1239,7 @@
                     }
                 } else if (tree.sym.owner.kind == TYP) {
                     TranslationContext<?> localContext = context();
-                    while (localContext != null) {
+                    while (localContext != null  && !localContext.owner.isStatic()) {
                         if (localContext.tree.hasTag(LAMBDA)) {
                             JCTree block = capturedDecl(localContext.depth, tree.sym);
                             if (block == null) break;
@@ -1312,10 +1315,15 @@
             boolean isLocal = def.isLocal();
             if ((inReferencedClass && isLocal || lambdaNewClassFilter(context(), tree))) {
                 TranslationContext<?> localContext = context();
-                while (localContext != null) {
-                    if (localContext.tree.getTag() == LAMBDA) {
+                final TypeSymbol outerInstanceSymbol = tree.type.getEnclosingType().tsym;
+                while (localContext != null  && !localContext.owner.isStatic()) {
+                    if (localContext.tree.hasTag(LAMBDA)) {
+                        if (outerInstanceSymbol != null) {
+                            JCTree block = capturedDecl(localContext.depth, outerInstanceSymbol);
+                            if (block == null) break;
+                        }
                         ((LambdaTranslationContext)localContext)
-                                .addSymbol(tree.type.getEnclosingType().tsym, CAPTURED_THIS);
+                                .addSymbol(outerInstanceSymbol, CAPTURED_THIS);
                     }
                     localContext = localContext.prev;
                 }
@@ -1404,7 +1412,7 @@
                 // A select of this or super means, if we are in a lambda,
                 // we much have an instance context
                 TranslationContext<?> localContext = context();
-                while (localContext != null) {
+                while (localContext != null  && !localContext.owner.isStatic()) {
                     if (localContext.tree.hasTag(LAMBDA)) {
                         JCClassDecl clazz = (JCClassDecl)capturedDecl(localContext.depth, tree.sym);
                         if (clazz == null) break;
@@ -1579,7 +1587,7 @@
                 switch (block.tree.getTag()) {
                     case CLASSDEF:
                         ClassSymbol clazz = ((JCClassDecl)block.tree).sym;
-                        if (sym.isMemberOf(clazz, types)) {
+                        if (clazz.isSubClass(sym, types) || sym.isMemberOf(clazz, types)) {
                             return currentDepth > depth ? null : block.tree;
                         }
                         break;