标签:静态方法 ica anti ecif generic bool selector sele int
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);
}
调用的地方如下截图。
只有变量、方法或者静态块时才会对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{} }
标签:静态方法 ica anti ecif generic bool selector sele int
原文地址:https://www.cnblogs.com/extjs4/p/9285113.html