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属性
这个属性写入的地方如下:

读取值的地方如下:

AttrContext的更多相关文章
- Annotate类
在Annotate类中有个Annotator接口,定义如下: /** A client that has annotations to add registers an annotator, * th ...
- Attr.checkId()方法
1.符号sym是TYP02 举个例子,如下: package bazola; class Point { // ... } class Tree<A> { class AttrVisito ...
- Scope及其子类介绍
之前写的文章: 关于作用域范围Scope Scope及相关的子类如下: 同时有些Scope还继承了Scope.ScopeListener类,如下: 1.StarImportScope及ImportSc ...
- Check类的validate方法解读
此方法的实现如下: public void validate(JCTree tree, Env<AttrContext> env, boolean checkRaw) { Validato ...
- Javac之Environment
关于Env的源代码如下: /** A class for environments, instances of which are passed as * arguments to tree visi ...
- Javac之关于方法的调用1
方法的调用从Attr类的visitApply()方法进入,如下: /** Visitor method for method invocations. * NOTE: The method part ...
- javac的Resolve类解读
方法1:isInitializer() /** An environment is an "initializer" if it is a constructor or * an ...
- JDK8在泛型类型推导上的变化
概述 JDK8升级,大部分问题可能在编译期就碰到了,但是有些时候比较蛋疼,编译期没有出现问题,但是在运行期就出了问题,比如今天要说的这个话题,所以大家再升级的时候还是要多测测再上线,当然JDK8给我们 ...
随机推荐
- centos7安装 docker
centos7安装 docker 切换到 root用户,执行: [root@localhost frinder]# yum install docker已加载插件:fastestmirror, lan ...
- 从0学习JQ
转 张子秋的博客 为以后用到的时候好查询! 从零开始学习jQuery (一) 开天辟地入门篇 从零开始学习jQuery (二) 万能的选择器 从零开始学习jQuery (三) 管理jQuery包装集 ...
- PHP 生成16 uuid
从c# 翻译而来 <?php $i=1; $guidStr=string_make_guid(); echo $guidStr."\n"; $byte_array = unp ...
- paip.双网卡多网卡不能上网的联网配置
paip.双网卡多网卡不能上网的联网配置 作者Attilax , EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net/att ...
- Win10系统下编译OSG3.4
环境说明 1.Win10专业版.64位: 2.VS2012旗舰版:QT5.2.0: 3.cmake-3.9.0.64位: 资源准备 1.OSG3.4源码包 http://trac.opensceneg ...
- NetCore入门篇:(二)Net Core项目创建
一.新建项目 1.选择菜单:文件 -> 新建 -> 项目 2.选择模板:NET Core -> ASP.NET Core Web 应用程序,输入名称 3.选择框架:ASP.NET C ...
- WPF 的Listbox 滚动处理
操作需求场景:Listbox 高150 item 高150 listbox有几十个item ,希望鼠标滚轮滚动一次listbox 能滚动到下一个item, 代码实现: <Grid x:Name ...
- 网络流——二分图最优匹配KM算法
前言 其实这个东西只是为了把网络流的内容凑齐而写的(反正我是没有看到过这样子的题不知道田忌赛马算不算) 算法过程 我们令左边的点(其实二分图没有什么左右)为女生,右边的点为男生,那么: 为每一个女生定 ...
- 【转】Lucene工作原理——反向索引
原文链接: http://my.oschina.net/wangfree/blog/77045 倒排索引 倒排索引(反向索引) 倒排索引源于实际应用中需要根据属性的值来查找记录.这种索引表中的每一项 ...
- Day 28面向对象的进阶-内置函数(__new__,__del__)
元类 创造 类 所有类的type 都是他的元类 类创造 对象 具体创造对象的方法 __new__方法 class 类名(classmata = type)#默认是 class 类名(class ...