TypeVisitorAdapterTest.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:javalang-compiler 作者:
@Test
public void testMethodReferencesToAnArrayItem() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 8) {
        compile("import java.util.Arrays; public class A{}");
        SymbolType st = new SymbolType(String.class);
        st.setArrayCount(1);
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        symTable.pushSymbol("stringArray", ReferenceType.TYPE, st, null);
        symTable.pushSymbol("this", ReferenceType.TYPE, new SymbolType(getClassLoader().loadClass("A")), null);
        MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class,
                "Arrays.sort(stringArray, String::compareToIgnoreCase)");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("sort", type.getMethod().getName());
        MethodReferenceExpr arg1 = (MethodReferenceExpr) expr.getArgs().get(1);

        SymbolType methodType = (SymbolType) arg1.getReferencedMethodSymbolData();
        Assert.assertNotNull(methodType);
        Assert.assertEquals("compare", methodType.getMethod().getName());
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号