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. C语言 fread()与fwrite()函数说明与示例

    1.作用 读写文件数据块. 2.函数原型 (1)size_t fread ( void * ptr, size_t size, size_t count, FILE * stream ); 其中,pt ...

  2. java编程中Properties类的具体作用和使用!

    如果不熟悉 java.util.Properties类,那么现在告诉您它是用来在一个文件中存储键-值对的,其中键和值是用等号分隔的.(如清单 1 所示).最近更新的java.util.Properti ...

  3. php连接微软MSSQL(sql server)完全攻略

    http://www.jb51.net/article/98364.htm php连接微软MSSQL(sql server)完全攻略 作者:吵吵 字体:[增加 减小] 类型:转载 时间:2016-11 ...

  4. 一句话为当前窗口客户区捉图: GetFormImage 来自万一的博客

    一句话为当前窗口客户区捉图: GetFormImage http://www.cnblogs.com/del/archive/2008/10/24/1318738.html unit Unit1; i ...

  5. 百分之 95% 的程序员不知道 Trending 是什么。

    前言如果学习到的知识不成体系,那么遇到问题时就会非常难解决.常有人问你从哪里了解新技术怎么判断其发展趋势的,除了关注 Hacker News 以及庞大的 Awesome 还有没有其它方式?有啊当然是每 ...

  6. (zxing.net)一维码MSI的简介、实现与解码

    一.简介 MSI/Plessey 条码(也被称为 MSI 或 Modified Plessey)是一款数字条码,多用于超市.存储用的仓库和其他贮藏室的货架.货架上的条码可以告知货架上的产品.应放数量和 ...

  7. Buck工作原理分析,连续模式,断续模式

    Part01:Buck电路工作原理: 图1-1 Buck电路拓扑结构 Buck电路的拓扑结构如图1-1所示: (1) input接输入电源,既直流电动势: (2) IGBT1为开关管,可以选择以全控型 ...

  8. Android - Android Studio 3.0去掉方法参数提示

    升级到3.0之后,最明显的一个就是在调用方法的时候多了一个参数提示.有利有弊,看着不是很舒服.就想去掉. 提示样式如下: 去掉提示: 原文地址: https://blog.csdn.net/stude ...

  9. Android Studio - Unable to create Debug Bridge: Unable to start adb server: adb server version (32) doesn't match this client (40)

    错误提示:Unable to create Debug Bridge: Unable to start adb server: adb server version (32) doesn't matc ...

  10. bzoj2095: [Poi2010]Bridges(二分+混合图求欧拉回路)

    传送门 这篇题解讲的真吼->这里 首先我们可以二分一个答案,然后把所有权值小于这个答案的都加入图中 那么问题就转化为一张混合图(既有有向边又有无向边)中是否存在欧拉回路 首先 无向图存在欧拉回路 ...