AttrContext

 

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属性

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

读取值的地方如下:

 

 

 

 

 

 

 

 

  

 

 
 

  

 

 

 

 

 

 

 

 

 

 

 

 

 

 

转载于:https://www.cnblogs.com/extjs4/p/9285113.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值