TypeVisitorAdapterTest.java 文件源码

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

项目:javalang-compiler 作者:
@Test
public void testGenericMethodsExplicitTypeInvocation() throws Exception {
    compile("import java.util.ArrayList; import java.io.Serializable;"
            + " public class A { public static <T> T pick(T a1, T a2) { return a2; }}");
    SymbolTable symTable = getSymbolTable();
    ASTSymbolTypeResolver.getInstance().setSymbolTable(symTable);
    symTable.pushScope();
    SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
    symTable.pushSymbol("A", ReferenceType.TYPE, st, null);

    MethodCallExpr expr = (MethodCallExpr) ASTManager.parse(Expression.class,
            "A.<Serializable>pick(\"d\", new ArrayList<String>())");
    HashMap<String, Object> ctx = new HashMap<String, Object>();
    expressionAnalyzer.visit(expr, ctx);
    SymbolType type = (SymbolType) expr.getSymbolData();
    Assert.assertNotNull(type);
    Assert.assertEquals("java.io.Serializable", type.getName());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号