info属性类型为AttrContext或AttrContextEnv。主要看AtrContext即可。定义了如下关键参数:

/** Contains information specific to the attribute and enter
 *  passes, to be used in place of the generic field in environments.
 *
 */
public class AttrContext {

    /** The scope of local symbols.
     */
    public Scope scope = null;

    /** The number of enclosing `static' modifiers.
     */
    public int staticLevel = 0;

    /** Is this an environment for a this(...) or super(...) call?
     */
    public boolean isSelfCall = false;

    /** Are we evaluating the selector of a `super' or type name?
     */
    public boolean selectSuper = false;

    /** Are arguments to current function applications boxed into an array for varargs?
     */
    public boolean varArgs = false;

    /** A list of type variables that are all-quantifed in current context.
     */
    public List<Type> typeVars = List.nil();

    /** A record of the lint/SuppressWarnings currently in effect
     */
    public Lint lint;

    /** The variable whose initializer is being attributed
     * useful for detecting self-references in variable initializers
     */
    public Symbol enclVar = null;

    // ...
}

获取这个AtrContext的对象可调用dup()方法,如下:

/** Duplicate this context, replacing scope field and copying all others.
 */
public AttrContext dup(Scope scope) {
    AttrContext info = new AttrContext();
    info.scope = scope;
    info.staticLevel = staticLevel;
    info.isSelfCall = isSelfCall;
    info.selectSuper = selectSuper;
    info.varArgs = varArgs;
    info.typeVars = typeVars;
    info.lint = lint;
    info.enclVar = enclVar;
    return info;
}

调用的地方如下截图。

另外一个dup()方法代码如下:

 /** Duplicate this context, copying all fields.
*/
public AttrContext dup() {
        return dup(scope);
}

调用的地方如下截图。

1、staticLevel属性

只有变量、方法或者静态块时才会对staticLevel进行加1操作,对于静态类时不对此值进行操作。

不能在静态或者非静态方法或者静态/非静态块中出现static修饰的变量与类,如:

Object o = new Object(){
	// The field b cannot be declared static in a non-static inner type,
	// unless initialized with a constant expression
	static int b = 2;
};

class InnerD{
	// The member type InnerE cannot be declared static;
	// static types can only be declared in static or top level types
	static class InnerE{}
}

static{
	static int a = 1;
	static class InnerA{}
}

public void methodA(){
	static int a = 1;
	static class InnerA{}
}

2、selectSuper属性

英文注释:Are we evaluating the selector of a `super' or type name?

举例如下:

public class TestScope {
	class A{
		public void t() throws CloneNotSupportedException{
			TestScope.super.clone();
		}
	}
}

当在Attr类的visitSelect中对TestScope.super进行标记时,则这个属性会设置为true  

3、typeVars属性

这个属性写入的地方如下:

读取值的地方如下:

  


  

AttrContext的更多相关文章

  1. Annotate类

    在Annotate类中有个Annotator接口,定义如下: /** A client that has annotations to add registers an annotator, * th ...

  2. Attr.checkId()方法

    1.符号sym是TYP02 举个例子,如下: package bazola; class Point { // ... } class Tree<A> { class AttrVisito ...

  3. Scope及其子类介绍

    之前写的文章: 关于作用域范围Scope Scope及相关的子类如下: 同时有些Scope还继承了Scope.ScopeListener类,如下: 1.StarImportScope及ImportSc ...

  4. Check类的validate方法解读

    此方法的实现如下: public void validate(JCTree tree, Env<AttrContext> env, boolean checkRaw) { Validato ...

  5. Javac之Environment

    关于Env的源代码如下: /** A class for environments, instances of which are passed as * arguments to tree visi ...

  6. Javac之关于方法的调用1

    方法的调用从Attr类的visitApply()方法进入,如下: /** Visitor method for method invocations. * NOTE: The method part ...

  7. javac的Resolve类解读

    方法1:isInitializer() /** An environment is an "initializer" if it is a constructor or * an ...

  8. JDK8在泛型类型推导上的变化

    概述 JDK8升级,大部分问题可能在编译期就碰到了,但是有些时候比较蛋疼,编译期没有出现问题,但是在运行期就出了问题,比如今天要说的这个话题,所以大家再升级的时候还是要多测测再上线,当然JDK8给我们 ...

随机推荐

  1. 判断Mouse事件源类型

    //鼠标事件源类型 public enum MouseEventSource { Mouse, Pen, Touch } /// <summary> /// MainWindow.xaml ...

  2. DOM数据解析

    //DOM : Document Object Model ,一种XML解析的方式,先读取整篇的内容,然后再进行解析,解析速度比较快,如果内出现错误,解析就会失败,iOS不支持DOM解析,goole提 ...

  3. Spring组件扫描 <context:component-scan/>

    目录(?)[-] 总结 使用方式 扫描controller下所以类 扫描符合条件Controller的类推荐 我们在SpringMVC开发项目中,有的用注解和XML配置Bean,这两种都各有自己的优势 ...

  4. POJ1511来回最短路

    POJ1511 问你从1到其它点得所有最短路之和  与  其他点到1得所有最短路之和 得总和 思路很明确就是两次最短路,翻转一次地图就好了 一开始就是两次spfa之间处理好数据得更新管理就好 vect ...

  5. numpy.sort()学习记录

    python的功能真的是只有我想不到,没有它做不到 在学系np.sort中学到了一些 print(array2) [14 13 12 11] [10 9 8 7] [ 6 5 4 3] print(n ...

  6. D3 API总览

    D3图形库API参考 https://github.com/d3/d3/wiki/API--%E4%B8%AD%E6%96%87%E6%89%8B%E5%86%8C d3 官网 API https:/ ...

  7. application cache 应用缓存

    这些应用还是要自己实现一遍,否则真不知道哪里会出问题. 客户端: <!DOCTYPE html> <html manifest = 'demo.appcache'> <h ...

  8. Git安全配置

      今天收到了阿里云异地登录的短信报警,登录阿里云后台发现,有人从深圳登录了我的服务器(本人在北京),查看详细信息一共登录了5次,前两次是使用的git用户进行登录,后两次已经变成了root用户,怀疑是 ...

  9. 关于ListBox的几个问题

    Winfrom ListBox绑定数据源list界面不更新问题与绑定数据源不可CRUD问题 场景:获取一个listbox的选中项添加到另一个listbox中 解决方案-1:不要直接绑定DataSour ...

  10. .NET高级代码审计(第二课) Json.Net反序列化漏洞

    0X00 前言 Newtonsoft.Json,这是一个开源的Json.Net库,官方地址:https://www.newtonsoft.com/json ,一个读写Json效率非常高的.Net库,在 ...