@Test
public void testMethodReferencesToConstructors() throws Exception {
if (SourceVersion.latestSupported().ordinal() >= 8) {
compile("import java.util.HashSet; public class A{ public static void foo(B b) {} public interface B{ public Object get();}}");
SymbolTable symTable = getSymbolTable();
symTable.pushSymbol("this", ReferenceType.TYPE, new SymbolType(getClassLoader().loadClass("A")), null);
MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class, "A.foo(HashSet::new)");
HashMap<String, Object> ctx = new HashMap<String, Object>();
expressionAnalyzer.visit(expr, ctx);
SymbolType type = (SymbolType) expr.getSymbolData();
Assert.assertNotNull(type);
Assert.assertEquals("foo", type.getMethod().getName());
MethodReferenceExpr arg1 = (MethodReferenceExpr) expr.getArgs().get(0);
SymbolType methodType = (SymbolType) arg1.getReferencedMethodSymbolData();
Assert.assertNotNull(methodType);
Assert.assertEquals("get", methodType.getMethod().getName());
}
}
TypeVisitorAdapterTest.java 文件源码
java
阅读 22
收藏 0
点赞 0
评论 0
项目:javalang-compiler
作者:
评论列表
文章目录