src/share/classes/com/sun/tools/javac/comp/LambdaToMethod.java

changeset 1762
31ef33db5e0e
parent 1755
ddb4a2bfcd82
child 1802
8fb68f73d4b1
equal deleted inserted replaced
1761:78717f2d00e8 1762:31ef33db5e0e
26 26
27 import com.sun.tools.javac.tree.*; 27 import com.sun.tools.javac.tree.*;
28 import com.sun.tools.javac.tree.JCTree.*; 28 import com.sun.tools.javac.tree.JCTree.*;
29 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind; 29 import com.sun.tools.javac.tree.JCTree.JCMemberReference.ReferenceKind;
30 import com.sun.tools.javac.tree.TreeMaker; 30 import com.sun.tools.javac.tree.TreeMaker;
31 import com.sun.tools.javac.tree.TreeScanner;
32 import com.sun.tools.javac.tree.TreeTranslator; 31 import com.sun.tools.javac.tree.TreeTranslator;
33 import com.sun.tools.javac.code.Attribute; 32 import com.sun.tools.javac.code.Attribute;
34 import com.sun.tools.javac.code.Kinds; 33 import com.sun.tools.javac.code.Kinds;
35 import com.sun.tools.javac.code.Scope; 34 import com.sun.tools.javac.code.Scope;
36 import com.sun.tools.javac.code.Symbol; 35 import com.sun.tools.javac.code.Symbol;
163 public <T extends JCTree> T translate(T tree) { 162 public <T extends JCTree> T translate(T tree) {
164 TranslationContext<?> newContext = contextMap.get(tree); 163 TranslationContext<?> newContext = contextMap.get(tree);
165 return translate(tree, newContext != null ? newContext : context); 164 return translate(tree, newContext != null ? newContext : context);
166 } 165 }
167 166
168 public <T extends JCTree> T translate(T tree, TranslationContext<?> newContext) { 167 <T extends JCTree> T translate(T tree, TranslationContext<?> newContext) {
169 TranslationContext<?> prevContext = context; 168 TranslationContext<?> prevContext = context;
170 try { 169 try {
171 context = newContext; 170 context = newContext;
172 return super.translate(tree); 171 return super.translate(tree);
173 } 172 }
174 finally { 173 finally {
175 context = prevContext; 174 context = prevContext;
176 } 175 }
177 } 176 }
178 177
179 public <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) { 178 <T extends JCTree> List<T> translate(List<T> trees, TranslationContext<?> newContext) {
180 ListBuffer<T> buf = ListBuffer.lb(); 179 ListBuffer<T> buf = ListBuffer.lb();
181 for (T tree : trees) { 180 for (T tree : trees) {
182 buf.append(translate(tree, newContext)); 181 buf.append(translate(tree, newContext));
183 } 182 }
184 return buf.toList(); 183 return buf.toList();
1301 } 1300 }
1302 } 1301 }
1303 1302
1304 @Override 1303 @Override
1305 public void visitSelect(JCFieldAccess tree) { 1304 public void visitSelect(JCFieldAccess tree) {
1306 if (context() != null && lambdaSelectSymbolFilter(tree.sym)) { 1305 if (context() != null && tree.sym.kind == VAR &&
1306 (tree.sym.name == names._this ||
1307 tree.sym.name == names._super)) {
1308 // A select of this or super means, if we are in a lambda,
1309 // we much have an instance context
1307 TranslationContext<?> localContext = context(); 1310 TranslationContext<?> localContext = context();
1308 while (localContext != null) { 1311 while (localContext != null) {
1309 if (localContext.tree.hasTag(LAMBDA)) { 1312 if (localContext.tree.hasTag(LAMBDA)) {
1310 JCClassDecl clazz = (JCClassDecl)capturedDecl(localContext.depth, tree.sym); 1313 JCClassDecl clazz = (JCClassDecl)capturedDecl(localContext.depth, tree.sym);
1311 if (clazz == null) break; 1314 if (clazz == null) break;
1552 return (sym.kind == VAR || sym.kind == MTH) 1555 return (sym.kind == VAR || sym.kind == MTH)
1553 && !sym.isStatic() 1556 && !sym.isStatic()
1554 && sym.name != names.init; 1557 && sym.name != names.init;
1555 } 1558 }
1556 1559
1557 private boolean lambdaSelectSymbolFilter(Symbol sym) {
1558 return (sym.kind == VAR || sym.kind == MTH) &&
1559 !sym.isStatic() &&
1560 (sym.name == names._this ||
1561 sym.name == names._super);
1562 }
1563
1564 /** 1560 /**
1565 * This is used to filter out those new class expressions that need to 1561 * This is used to filter out those new class expressions that need to
1566 * be qualified with an enclosing tree 1562 * be qualified with an enclosing tree
1567 */ 1563 */
1568 private boolean lambdaNewClassFilter(TranslationContext<?> context, JCNewClass tree) { 1564 private boolean lambdaNewClassFilter(TranslationContext<?> context, JCNewClass tree) {

mercurial