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. 浅谈webuploader上传文件

    官网:http://c7.gg/fw4sn 案例: 文件上传进度 // 文件上传过程中创建进度条实时显示. uploader.on( 'uploadProgress', function( file, ...

  2. STL中的algorithm

    STL中的algorithm #include<algorithm>中的泛函算法,需要添加头文件. 搜索算法:find() .search() .count() .find_if() .s ...

  3. 软件工程—WC功能实现 (JAVA)

    软件工程-WC功能实现(JAVA) Github项目地址:https://github.com/Ousyoung/wc 项目要求 ​ wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和 ...

  4. 软件工程作业 - 实现WC功能(java)

    项目地址:https://github.com/yogurt1998/WordCount 要求 基本要求 -c 统计文件字符数(实现) -w 统计文件单词数(实现) -l 统计文件行数(实现) 扩展功 ...

  5. Quartz.net 的 FAQ

    Quartz 是什么? Quartz 是作业调度系统,可以集成进其他软件系统.这里[作业调度程序]一词是指,在预定义时间执行(或通知)其他组件的系统. Quartz 有什么优点? 灵活,有多种使用方式 ...

  6. [LeetCode] Unique Paths && Unique Paths II && Minimum Path Sum (动态规划之 Matrix DP )

    Unique Paths https://oj.leetcode.com/problems/unique-paths/ A robot is located at the top-left corne ...

  7. oracle只导出触发器

    只要触发器,其他都不要 方法1:plsql develop调用exp:tools->export object—>trigger 方法2:select dbms_metadata.get_ ...

  8. webpack快速入门——配置JS压缩,打包

    1 .首先在webpack.config.js中引入 const uglify = require('uglifyjs-webpack-plugin'); 2.然后在plugins配置里 plugin ...

  9. css字体中英速查表

    例1(小米米官网):font-family: "Arial","Microsoft YaHei","黑体","宋体",s ...

  10. C的Define

    #define Conn(x,y) x##y  //表示x连接y #define ToChar(x) #@x //给x加上单引号 #define ToString(x) #x  //给x加双引号 #d ...