mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-14 00:16:47 +00:00
Merge branch 'master' of git@github.com:rzwitserloot/lombok
This commit is contained in:
commit
8eb05b357d
4 files changed
+45
-3
No files matched your search
@@ -34,6 +34,7 @@ import lombok.core.AST;
|
||||
|
||||
import com.sun.tools.javac.code.Symtab;
|
||||
import com.sun.tools.javac.model.JavacElements;
|
||||
import com.sun.tools.javac.model.JavacTypes;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
@@ -61,6 +62,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
private final JavacElements elements;
|
||||
private final TreeMaker treeMaker;
|
||||
private final Symtab symtab;
|
||||
private final JavacTypes javacTypes;
|
||||
private final Log log;
|
||||
private final Context context;
|
||||
|
||||
@@ -80,6 +82,7 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
this.elements = JavacElements.instance(context);
|
||||
this.treeMaker = TreeMaker.instance(context);
|
||||
this.symtab = Symtab.instance(context);
|
||||
this.javacTypes = JavacTypes.instance(context);
|
||||
clearChanged();
|
||||
}
|
||||
|
||||
@@ -135,6 +138,13 @@ public class JavacAST extends AST<JavacAST, JavacNode, JCTree> {
|
||||
return symtab;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The implementation of {@link javax.lang.model.util.Types} of javac. Contains a few extra methods beyond
|
||||
* the ones listed in the official annotation API interface. */
|
||||
public JavacTypes getTypesUtil() {
|
||||
return javacTypes;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@Override protected JavacNode buildTree(JCTree node, Kind kind) {
|
||||
switch (kind) {
|
||||
|
||||
@@ -28,6 +28,7 @@ import javax.tools.Diagnostic;
|
||||
import lombok.core.AST.Kind;
|
||||
|
||||
import com.sun.tools.javac.code.Symtab;
|
||||
import com.sun.tools.javac.model.JavacTypes;
|
||||
import com.sun.tools.javac.tree.JCTree;
|
||||
import com.sun.tools.javac.tree.TreeMaker;
|
||||
import com.sun.tools.javac.tree.JCTree.JCAnnotation;
|
||||
@@ -177,6 +178,15 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
|
||||
return ast.getSymbolTable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient shortcut to the owning JavacAST object's getTypesUtil method.
|
||||
*
|
||||
* @see JavacAST#getTypesUtil()
|
||||
*/
|
||||
public JavacTypes getTypesUtil() {
|
||||
return ast.getTypesUtil();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient shortcut to the owning JavacAST object's getContext method.
|
||||
*
|
||||
|
||||
@@ -242,7 +242,7 @@ public class JavacResolution {
|
||||
}
|
||||
}
|
||||
|
||||
public Map<JCTree, JCTree> resolve(JavacNode node) {
|
||||
public Map<JCTree, JCTree> resolveMethodMember(JavacNode node) {
|
||||
ArrayDeque<JCTree> stack = new ArrayDeque<JCTree>();
|
||||
|
||||
{
|
||||
@@ -268,6 +268,28 @@ public class JavacResolution {
|
||||
}
|
||||
}
|
||||
|
||||
public void resolveClassMember(JavacNode node) {
|
||||
ArrayDeque<JCTree> stack = new ArrayDeque<JCTree>();
|
||||
|
||||
{
|
||||
JavacNode n = node;
|
||||
while (n != null) {
|
||||
stack.push(n.get());
|
||||
n = n.up();
|
||||
}
|
||||
}
|
||||
|
||||
logDisabler.disableLoggers();
|
||||
try {
|
||||
EnvFinder finder = new EnvFinder(node.getContext());
|
||||
while (!stack.isEmpty()) stack.pop().accept(finder);
|
||||
|
||||
attrib(node.get(), finder.get());
|
||||
} finally {
|
||||
logDisabler.enableLoggers();
|
||||
}
|
||||
}
|
||||
|
||||
private void attrib(JCTree tree, Env<AttrContext> env) {
|
||||
if (tree instanceof JCBlock) attr.attribStat(tree, env);
|
||||
else if (tree instanceof JCMethodDecl) attr.attribStat(((JCMethodDecl)tree).body, env);
|
||||
|
||||
@@ -71,14 +71,14 @@ public class HandleVal extends JavacASTAdapter {
|
||||
if (rhsOfEnhancedForLoop == null) {
|
||||
if (local.init.type == null) {
|
||||
JavacResolution resolver = new JavacResolution(localNode.getContext());
|
||||
type = ((JCExpression) resolver.resolve(localNode).get(local.init)).type;
|
||||
type = ((JCExpression) resolver.resolveMethodMember(localNode).get(local.init)).type;
|
||||
} else {
|
||||
type = local.init.type;
|
||||
}
|
||||
} else {
|
||||
if (rhsOfEnhancedForLoop.type == null) {
|
||||
JavacResolution resolver = new JavacResolution(localNode.getContext());
|
||||
type = ((JCExpression) resolver.resolve(localNode.directUp()).get(rhsOfEnhancedForLoop)).type;
|
||||
type = ((JCExpression) resolver.resolveMethodMember(localNode.directUp()).get(rhsOfEnhancedForLoop)).type;
|
||||
} else {
|
||||
type = rhsOfEnhancedForLoop.type;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user