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给我们 ...
随机推荐
- MySQL的NO_BACKSLASH_ESCAPES
官方说明: https://dev.mysql.com/doc/refman/5.7/en/mysql-real-escape-string.html 相关资料: https://dev.mysql. ...
- HDU1269 迷宫城堡 2016-07-24 13:47 84人阅读 评论(0) 收藏
迷宫城堡 Problem Description 为了训练小希的方向感,Gardon建立了一座大城堡,里面有N个房间(N<=10000)和M条通道(M<=100000),每个通道都是单向的 ...
- BUG_vector iterator not dereferencable
1问题: bug提示图下图所示:
- PHP编译安装完成之后没有'php.ini'文件的处理方法
在我们编译安装PHP的时候,编译安装完成是不会自动生成php.ini文件的,所以需要我们手动生成. 1.通过命令行确定php.ini文件的位置 php -r "phpinfo();" ...
- delphi中如何控制listview的每行的颜色
我们可以设定一个字段的值,用以判断用什么颜色显示listview的颜色,例子如下 procedure TMainForm.ListView2CustomDrawItem(Sender: TCustom ...
- Android SDK目录结构
Android版本下载:从4.0到8.0版本: Android SDK目录结构图: sdk全称:software develop kits 软件开发工具集 add-ons:Google API map ...
- Django:如何给文章列表添加图片
思路: 使用ajax方式将图片和文本一起通过formData提交到后台,Django后台通过request.POST和request.FILES方式接收数据 1.前端代码 {% extends 'ba ...
- 设计模式之模版方法模式(Template Method Pattern)
一.什么是模版方法模式? 首先,模版方法模式是用来封装算法骨架的,也就是算法流程 既然被称为模版,那么它肯定允许扩展类套用这个模版,为了应对变化,那么它也一定允许扩展类做一些改变 事实就是这样,模版方 ...
- 给IDistributedCache新增了扩展方法GetOrCreate、GetOrCreateAsync
public static class DistributedCacheExtensions { public static TItem GetOrCreate<TItem>(this I ...
- day 93 Restframwork
苑昊博客: http://www.cnblogs.com/yuanchenqi/articles/7570003.html 一.queryset 特性 from django.db import m ...