mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 16:15:16 +00:00
added supporting for @val variables inside lambdas.
This commit is contained in:
1 parent
444d77faa2
commit
0f0cb68eac
8 files changed
+113
-3
No files matched your search
@@ -19,5 +19,6 @@ Szymon Pacanowski <spacanowski@gmail.com>
|
||||
Taiki Sugawara <buzz.taiki@gmail.com>
|
||||
Thomas Darimont <thomas.darimont@gmail.com>
|
||||
Yun Zhi Lin <yun@yunspace.com>
|
||||
Bulgakov Alexander <buls@yandex.ru>
|
||||
|
||||
By adding your name to this list, you grant full and irrevocable copyright and patent indemnity to Project Lombok and all use of Project Lombok, and you certify that you have the right to do so for all commits you add to Project Lombok.
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2009-2015 The Project Lombok Authors.
|
||||
* Copyright (C) 2009-2016 The Project Lombok Authors.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
@@ -28,6 +28,8 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
import javax.annotation.processing.Messager;
|
||||
import javax.tools.Diagnostic;
|
||||
@@ -315,7 +317,6 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
// @Foo int x, y; is handled in javac by putting the same annotation node on 2 JCVariableDecls.
|
||||
return null;
|
||||
}
|
||||
|
||||
return putInMap(new JavacNode(this, annotation, null, Kind.ANNOTATION));
|
||||
}
|
||||
|
||||
@@ -333,12 +334,40 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
if (statement instanceof JCClassDecl) return buildType((JCClassDecl)statement);
|
||||
if (statement instanceof JCVariableDecl) return buildLocalVar((JCVariableDecl)statement, Kind.LOCAL);
|
||||
if (statement instanceof JCTry) return buildTry((JCTry) statement);
|
||||
|
||||
if (statement.getClass().getSimpleName().equals("JCLambda")) return buildLambda(statement);
|
||||
if (setAndGetAsHandled(statement)) return null;
|
||||
|
||||
return drill(statement);
|
||||
}
|
||||
|
||||
private JavacNode buildLambda(JCTree jcTree) {
|
||||
return buildStatementOrExpression(getBody(jcTree));
|
||||
}
|
||||
|
||||
private JCTree getBody(JCTree jcTree) {
|
||||
try {
|
||||
return (JCTree) getBodyMethod(jcTree.getClass()).invoke(jcTree);
|
||||
} catch (Exception e) {
|
||||
throw Javac.sneakyThrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
private final static ConcurrentMap<Class<?>, Method> getBodyMethods = new ConcurrentHashMap<Class<?>, Method>();
|
||||
|
||||
private Method getBodyMethod(Class<?> c) {
|
||||
Method m = getBodyMethods.get(c);
|
||||
if (m != null) {
|
||||
return m;
|
||||
}
|
||||
try {
|
||||
m = c.getMethod("getBody");
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw Javac.sneakyThrow(e);
|
||||
}
|
||||
getBodyMethods.putIfAbsent(c, m);
|
||||
return getBodyMethods.get(c);
|
||||
}
|
||||
|
||||
private JavacNode drill(JCTree statement) {
|
||||
try {
|
||||
List<JavacNode> childNodes = new ArrayList<JavacNode>();
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public class ValFinal {
|
||||
public void test() {
|
||||
final int x = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// version 8:
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
};
|
||||
|
||||
public void easyLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
};
|
||||
}
|
||||
|
||||
public void easyIntersectionLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final int i = 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
import lombok.val;
|
||||
public class ValFinal {
|
||||
public ValFinal() {
|
||||
super();
|
||||
}
|
||||
public void test() {
|
||||
final @val int x = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// version 8:
|
||||
|
||||
import lombok.val;
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @val int i = 1;
|
||||
};
|
||||
ValInLambda() {
|
||||
super();
|
||||
}
|
||||
public void easyLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @val int i = 1;
|
||||
};
|
||||
}
|
||||
public void easyIntersectionLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
final @val int i = 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import lombok.val;
|
||||
public class ValFinal {
|
||||
public void test() {
|
||||
final val x = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// version 8:
|
||||
|
||||
import lombok.val;
|
||||
|
||||
class ValInLambda {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
val i = 1;
|
||||
};
|
||||
|
||||
public void easyLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
val i = 1;
|
||||
};
|
||||
}
|
||||
|
||||
public void easyIntersectionLambda() {
|
||||
Runnable foo = (Runnable) () -> {
|
||||
val i = 1;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user