TypeVisitorAdapterTest.java 文件源码

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

项目:javalang-compiler 作者:
@Test
public void testDiamond() throws Exception {
    if (SourceVersion.latestSupported().ordinal() >= 7) {
        compile("import java.util.List; import java.util.LinkedList; public class A{ List<Integer> bar = new LinkedList<>(); }");
        SymbolTable symTable = getSymbolTable();
        symTable.pushScope();
        SymbolType st = new SymbolType(getClassLoader().loadClass("A"));
        symTable.pushSymbol("a", ReferenceType.VARIABLE, st, null);
        FieldAccessExpr expr = (FieldAccessExpr) ASTManager.parse(Expression.class, "a.bar");
        HashMap<String, Object> ctx = new HashMap<String, Object>();
        expressionAnalyzer.visit(expr, ctx);
        SymbolType type = (SymbolType) expr.getSymbolData();
        Assert.assertNotNull(type);
        Assert.assertEquals("java.util.List", type.getName());
        Assert.assertNotNull(type.getParameterizedTypes());
        Assert.assertEquals("java.lang.Integer", type.getParameterizedTypes().get(0).getName());
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号