java AST JCTree简要分析

JCTree简要分析

[toc]

JCAnnotatedType

被注解的泛型:(注解的Target为ElementType.TYPE_USE时可注解泛型)

public static class A<T extends @Reality String> {
    
}
  • JCAnnotatedType @Reality() String
  • annotations (List<JCTree.JCAnnotation>) [0] = (JCAnnotation) @Reality()
  • underlyingType (JCExpression) = (JCIdent) String
protected JCAnnotatedType(List<JCTree.JCAnnotation> var1, JCTree.JCExpression var2) {
    Assert.check(var1 != null && var1.nonEmpty());
    this.annotations = var1;
    this.underlyingType = var2;
}

JCAnnotation

注解:@annotationType(args) 例子:@Reality(callSuper = false)

  • JCAnnotation @Reality(callSuper = false)
  • annotationType (JCTree) = (JCIdent) Reality
  • args (List<JCExpression>) = callSuper = false
  • attribute (Compound) = @com.juno.annotations.Reality(callSuper=false)
protected JCAnnotation(JCTree.Tag var1, JCTree var2, List<JCTree.JCExpression> var3) {
    this.tag = var1;
    this.annotationType = var2;
    this.args = var3;
}

JCArrayAccess

数组访问:a[0] = "123"

  • index (JCExpression) = 0 (JCLiteral)
  • indexed (JCExpression) = a (JCIdent)
protected JCArrayAccess(JCTree.JCExpression var1, JCTree.JCExpression var2) {
    this.indexed = var1;
    this.index = var2;
}

JCArrayTypeTree

数组类型:String[] a = new String[2] 中表达式的右边:

  • elemtype (JCExpression) = String (JCIdent)

二维数组:String[][] a = new String[1][2]解析为:

  • JCArrayTypeTree String[]
  • JCIdent String
protected JCArrayTypeTree(JCTree.JCExpression var1) {
    this.elemtype = var1;
}

JCAssert

assert断言:assert cond : detail

protected JCAssert(JCTree.JCExpression var1, JCTree.JCExpression var2) {
    this.cond = var1;
    this.detail = var2;
}

JCAssign

赋值:lhs = rhs 例如 i = 1

protected JCAssign(JCTree.JCExpression var1, JCTree.JCExpression var2) {
    this.lhs = var1; //左表达式
    this.rhs = var2; //右表达式
}

JCAssignOp

赋值:lhs opcode rhs 例如 i += 1

protected JCAssignOp(JCTree.Tag var1, JCTree var2, JCTree var3, Symbol var4) {
    this.opcode = var1;
    this.lhs = (JCTree.JCExpression)var2;
    this.rhs = (JCTree.JCExpression)var3;
    this.operator = var4;
}

赋值符号opcode的可取值:

/** Assignment operators, of type Assignop.
 */
BITOR_ASG(BITOR),                // |=
BITXOR_ASG(BITXOR),              // ^=
BITAND_ASG(BITAND),              // &=

SL_ASG(SL),                      // <<=
SR_ASG(SR),                      // >>=
USR_ASG(USR),                    // >>>=
PLUS_ASG(PLUS),                  // +=
MINUS_ASG(MINUS),                // -=
MUL_ASG(MUL),                    // *=
DIV_ASG(DIV),                    // /=
MOD_ASG(MOD),                    // %=

JCBinary

将语句分为二叉结构,例如double i = d + i * f 中第一个JCBinary为:

  • lhs = d
  • rhs = i * f
  • operator = null
  • opcode = PLUS

第二个JCBinary为:

  • lhs = i
  • rhs = f
  • operator = null
  • opcode = MUL
protected JCBinary(JCTree.Tag var1, JCTree.JCExpression var2, JCTree.JCExpression var3, Symbol var4) {
    this.opcode = var1;
    this.lhs = var2;
    this.rhs = var3;
    this.operator = var4;
}

二元运算符opcode的可取值:

/** Binary operators, of type Binary.
 */
OR,                              // ||
AND,                             // &&
BITOR,                           // |
BITXOR,                          // ^
BITAND,                          // &
EQ,                              // ==
NE,                              // !=
LT,                              // <
GT,                              // >
LE,                              // <=
GE,                              // >=
SL,                              // <<
SR,                              // >>
USR,                             // >>>
PLUS,                            // +
MINUS,                           // -
MUL,                             // *
DIV,                             // /
MOD,                             // %

JCBlock

语句块:{stats} 或 static{stats}(flags = 8L时)

protected JCBlock(long var1, List<JCTree.JCStatement> var3) {
    this.stats = var3;
    this.flags = var1;
}

JCBreak

break语句:break:label

  • label 为标签名
  • target 为跳转目标
protected JCBreak(Name var1, JCTree var2) {
    this.label = var1;
    this.target = var2;
}

JCCase

case语句:case pat : stats

protected JCCase(JCTree.JCExpression var1, List<JCTree.JCStatement> var2) {
    this.pat = var1;
    this.stats = var2;
}

JCCatch

catch捕捉异常:catch(param) body

  • param 定义异常变量 Exception e
  • body 代码块
protected JCCatch(JCTree.JCVariableDecl var1, JCTree.JCBlock var2) {
    this.param = var1;
    this.body = var2;
}

JCClassDecl

类的定义:

例子:

@Reality
public class MainActivity extends AppCompatActivity {

    private int kk = 1;

    static {
        kk = 2;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}
  • mods (JCModifiers) = public
  • name (Name) = (NameImpl) MainActivity
  • extending (JCExpression) = (JCIdent) AppCompatActivity
  • implementing (JCExpression) 实现的接口
  • defs (List<JCTree>) :
  • defs(1) : JCMethodDecl
    public <init>() {
        super();
    }
    
  • defs(2) : JCBlock
    static {
        kk = 2;
    }
    
  • defs(3) : JCVariableDecl
    private int kk = 1
    
  • defs(4) : JCMethodDecl
    @Override()
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView textView = findViewById(R.id.text);
        Random random = new Random();
    }
    
  • sym (ClassSymbol) = com.juno.utils.MainActivity
protected JCClassDecl(JCTree.JCModifiers var1, Name var2, List<JCTree.JCTypeParameter> var3, JCTree.JCExpression var4, List<JCTree.JCExpression> var5, List<JCTree> var6, ClassSymbol var7) {
    this.mods = var1;
    this.name = var2;
    this.typarams = var3;
    this.extending = var4;
    this.implementing = var5;
    this.defs = var6;
    this.sym = var7;
}

JCCompilationUnit

/**
 * Everything in one source file is kept in a TopLevel structure.
 * @param pid The tree representing the package clause. 
 * @param sourcefile The source file name.
 * @param defs All definitions in this file (ClassDef,Import,and Ski
 * @param packge The package it belongs to.
 * @param namedImportScope A scope for all named imports.
 * @param starImportScope A scope for all import-on-demands.
 * @param linelMap Line starting positions,defined only if option-g is set.
 * @param docComments A hashtable that stores all documentation comments indexed by the tree nodes they refer to.defined only if option-s is set.
 * @param endPositions A hashtable that stores ending positions of source ranges indexed by the tree nodes they belong to. Defined only if option-Xjcov is set.
 */
public static class JCCompilationUnit extends JCTree implements CompilationUnitTre{
    public List<JCAnnotation>packageAnnotations:
    public JCExpression pid:
    public List<JCTree>defs:
    public JavaFileObject sourcefile:
    public Package Symbol packge:
    public ImportScope namedImportScope:
    public StarImportScope starImportScope:
    public long flags:
    public Position.LinelMap linelMap=null:
    public Map<JCTree,String>docComments=null:
    public Map<JCTree,Integer>endPositions=null:
    
    protected JCCompilationUnit(List<JCAnnotation>packageAnnotations,
        JCExpression pid,
        List<JCTree>defs,
        JavaFileObject sourcefile,
        Pack ageSymbol packge,
        ImportScope namedImportScope,
        Star ImportScope starImportScope){
            this.packageAnnotations =packageAnnotations:
            this.pid=pid:
            this.defs=defs:
            this.sourcefile=sourcefile:
            this.packge=packge:
            this.namedImportScope=namedImportScope:
            this.starImportScope=starImportScope:
        }
}

JCConditional

三目运算符:cond ? truepart : falsepart 例如 a ? 1 : 3

protected JCConditional(JCTree.JCExpression var1, JCTree.JCExpression var2, JCTree.JCExpression var3) {
    this.cond = var1;
    this.truepart = var2;
    this.falsepart = var3;
}

JCContinue

continue跳过一次循环,与break相似:continue label

protected JCContinue(Name var1, JCTree var2) {
    this.label = var1;
    this.target = var2;
}

JCDoWhileLoop

do-while循环:do{body}while(cond)

protected JCDoWhileLoop(JCTree.JCStatement var1, JCTree.JCExpression var2) {
    this.body = var1;
    this.cond = var2;
}

JCEnhancedForLoop

增强循环:for(var : expr) body

例如:

for (String s : list) {
    print(s);
}
  • JCVariableDecl String s 定义字符串变量s
  • JCIdent list 遍历的容器
  • JCBlock { print(s); } 遍历块
protected JCEnhancedForLoop(JCTree.JCVariableDecl var1, JCTree.JCExpression var2, JCTree.JCStatement var3) {
    this.var = var1;
    this.expr = var2;
    this.body = var3;
}

JCErroneous

Error trees

JCExpression

表达式,赋值、调用方法等都算一个表达式,凡是继承JCExpression都算一个表达式

JCExpressionStatement

内部封装了JCExpression,实际上还是个表达式

protected JCExpressionStatement(JCTree.JCExpression var1) {
    this.expr = var1;
}

JCFieldAccess

访问父类、其他类的方法、变量时:super.onCreate()

  • selected (JCIdent) = super
  • name (NameImpl) = onCreate
protected JCFieldAccess(JCTree.JCExpression var1, Name var2, Symbol var3) {
    this.selected = var1;
    this.name = var2;
    this.sym = var3;
}

JCForloop

for循环:

  • for (init; cond; step) {body}(body为JCBlock
  • for (init; cond; step) body(body为JCExpressionStatement
protected JCForLoop(List<JCTree.JCStatement> var1, JCTree.JCExpression var2, List<JCTree.JCExpressionStatement> var3, JCTree.JCStatement var4) {
    this.init = var1;
    this.cond = var2;
    this.step = var3;
    this.body = var4;
}

JCFunctionalExpression

函数式表达式:lambda(JCLambda)和method reference(JCMemberReference)继承于JCFunctionalExpression

JCIdent

出现在表达式中的变量名、调用的方法名以及类名等,例子如下(按顺序):

  • Reality 类(注解)
  • AppCompatActivity 类
  • String 类
  • Override 类
  • Bundle 类
  • super super和this都是一个JcIdent
  • savedInstanceState 调用变量的名字
  • setContentView 方法
  • R 类
  • textView 调用变量的名字
  • findViewById 方法
  • R类
@Reality //JCIdent Reality ClassSymbol com.juno.annotations.Reality
//JCIdent AppCompatActivity ClassSymbol android.support.v7.app.AppCompatActivity
public class MainActivity extends AppCompatActivity  {

    //JCIdent String ClassSymbol java.lang.String
    private static final String TAG = "MainActivity";
    
    private int kk = 1;

    @Override //JCIdent Override ClassSymbol java.lang.Override
    //JCIdent Bundle ClassSymbol android.os.Bundle
    protected void onCreate(Bundle savedInstanceState) {
    
        //JCIdent super
        //JCIdent savedInstanceState
        super.onCreate(savedInstanceState);
        
        //JCIdent setContentView 
        //JCIdent R
        setContentView(R.layout.activity_main);
        
        TextView textView;
        //JCIdent textView
        //JCIdent findViewById
        //JCIdent R
        textView = findViewById(R.id.text);

        int i = 0;
        int j = 1;
        
        //JCIdent i
        //JCIdent j
        i = j * 3 + 2;
        
        //JCIdent this
        this.kk = 0;
    }

}

其中TextView textView;这一句是变量定义语句(JCVariableDecl),该语句的vartype属性实际上也是个JCIdent:

  • JCVariableDecl TextView textView
  • name (Name) = textView (NameImpl)
  • vartype (JCExpression) = TextView (JCIdent)

JCIf

if判断语句:if(condition) {thenpart} else {elsepart}

protected JCIf(JCTree.JCExpression var1, JCTree.JCStatement var2, JCTree.JCStatement var3) {
    this.cond = var1;
    this.thenpart = var2;
    this.elsepart = var3;
}

JCImport

import语句:

  • import qulid
  • static (if staticImport) import qulid
protected JCImport(JCTree var1, boolean var2) {
    this.qualid = var1;
    this.staticImport = var2;
}

JCinstanceOf

instanceof语句:expr instanceof clazz,例如textView instanceof View:

  • JCInstanceOf textView instanceof View
  • clazz (JCTree) = (JCIdent) View
  • expr (JCExpression) = (JCIdent) textView
protected JCInstanceOf(JCTree.JCExpression var1, JCTree var2) {
    this.expr = var1;
    this.clazz = var2;
}

JCLabeledStatement

带有标签的语句:label : body

protected JCLabeledStatement(Name var1, JCTree.JCStatement var2) {
    this.label = var1;
    this.body = var2;
}

JCLambda

lambda表达式:此处表达式主体只有一句表达式

textView.setOnClickListener(v -> v.setVisibility(View.INVISIBLE));
  • JCLambda (v)->v.setVisibility(View.INVISIBLE) (表达式整体)
  • params (List<JCTree.JCVariableDecl>) = (List) /*missing*/ v (参数定义列表)
  • body (JCTree) = (JCMethodInvocation) v.setVisibility(View.INVISIBLE) (主体)
  • canCompleteNormally (Boolean) = true (未知)
  • paramKind (ParameterKind) = IMPLICIT (参数类型隐形/明确)
  • getBodyKind() (BodyKind) = EXPRESSION (主体是表达式还是块)

当主体变为语句块时:

textView.setOnClickListener(v -> {
    v.setVisibility(View.VISIBLE);
});
  • body (JCTree) = (JCBlock) {v.setVisibility(View.VISIBLE);}
  • getBodyKind() (BodyKind) = STATEMENT

当参数v指明类型为View时:

textView.setOnClickListener((View v) -> v.setVisibility(View.INVISIBLE));
  • paramKind (ParameterKind) = IMPLICIT (参数类型明确)

JCLiteral

表示常量:int a = 1

  • typetag (TypeTag) = INT
  • value (Object) = (Integer) 1
protected JCLiteral(TypeTag var1, Object var2) {
    this.typetag = var1;
    this.value = var2;
}

typetag的可选值有:

INT : int
LONG : long
FLOAT : float
DOUBLE : double
CHAR : char
CLASS : String
BOT : null

JCMemberReference

lambda表达式中的方法引用:expr::name

例子:new B<String>("123").setObjectUtil(ObjectUtil::new);

  • JCMemberReference ObjectUtil::new
  • mode (ReferenceMode) = NEW
  • name (Name) = (NameImpl) <init>
  • expr (JCExpression) = (JCIdent) ObjectUtil

例子:new B<String>("123").setObjectUtil(this::util);

  • JCMemberReference this::util
  • mode (ReferenceMode) = INVOKE
  • name (Name) = (NameImpl) util
  • expr (JCExpression) = (JCIdent) this
protected JCMemberReference(ReferenceMode var1, Name var2, JCTree.JCExpression var3, List<JCTree.JCExpression> var4) {
    this.mode = var1;
    this.name = var2;
    this.expr = var3;
    this.typeargs = var4;
}

JCMethodDecl

方法的定义:

例子:

@Reality
private static <T extends String> int print(@NonNull final String s) throws RuntimeException {
    Log.e(TAG, s);
    return 1;
}
  • mods (JCModifiers) = @Reality() private static
  • name (Name) = (NameImpl) print
  • restype (JCExpression) = (JCPrimitiveTypeTree) int
  • typarams (JCTypeParameter) = T extends String
  • recvparam = null
  • params (List<JCVariableDecl>) [0] = @NonNull() final String s
  • thrown (JCExpression) = (JCIdent) RuntimeException
  • body (JCBlock) = {
    Log.e(TAG, s);
    return 1;
    }
  • defaultVaule (JCExpression) = null
  • sym (MethodSymbol) = <T>print(java.lang.String)

例子:

@Reality
@interface B {
    int value() default 1;
}
  • name (Name) = (NameImpl) value
  • restype (JCExpression) = (JCPrimitiveTypeTree) int
  • typarams (JCTypeParameter) 泛型列表为空
  • recvparam = null
  • params (List<JCVariableDecl>) 参数定义为空
  • thrown (JCExpression) 抛出列表为空
  • body (JCBlock) 方法体为空
  • defaultVaule (JCExpression) = (JCLiteral) 1
  • sym (MethodSymbol) = value()
protected JCMethodDecl(JCTree.JCModifiers var1, Name var2, JCTree.JCExpression var3, List<JCTree.JCTypeParameter> var4, JCTree.JCVariableDecl var5, List<JCTree.JCVariableDecl> var6, List<JCTree.JCExpression> var7, JCTree.JCBlock var8, JCTree.JCExpression var9, MethodSymbol var10) {
    this.mods = var1;
    this.name = var2;
    this.restype = var3;
    this.typarams = var4;
    this.params = var6;
    this.recvparam = var5;
    this.thrown = var7;
    this.body = var8;
    this.defaultValue = var9;
    this.sym = var10;
}

JCMethodinvocation

方法执行语句: meth(args)

例子:notNull(before)

  • meth (JCExpression) = (JCIdent) notNull
  • args (List<JCExpression>) = (JCIdent) before

例子:proxy.invoke(target, method, args)

  • meth (JCExpression) = (JCFieldAccess) proxy.invoke
  • args (List<JCExpression>) = (JCIdent) target, method, args
protected JCMethodInvocation(List<JCTree.JCExpression> var1, JCTree.JCExpression var2, List<JCTree.JCExpression> var3) {
    this.typeargs = var1 == null ? List.nil() : var1;
    this.meth = var2;
    this.args = var3;
}

JCModifiers

类、变量、方法等的修饰符和注解:例如:

@Reality private static final String TAG = "MainActivity";
  • flags (long) = 26L (2L | 8L | 16L)
  • annotations (List<JCTree.JCAnnotation>) = @Reality()
protected JCModifiers(long var1, List<JCTree.JCAnnotation> var3) {
    this.flags = var1;
    this.annotations = var3;
}

flags的可取值:

1L : public
2L : private
4L : protected
8L : static
16L : final
32L : synchronized
64L : volatile
128L : transient
256L : native
1024L : abstract
2048L : strictfp
8589934592L : default

方法默认flags不为default,而是0L

JCNewArray

new数组:

例子:String[] s = new String[]{"123","456"};

  • JCNewArray new String[]{"123", "456"}
  • elemtype (JCExpression) = (JCIdent) String
  • dims (List<JCTree.JCExpression>) 空
  • elems (List<JCTree.JCExpression>) [0] = (JCLiteral) "123"
  • elems (List<JCTree.JCExpression>) [1] = (JCLiteral) "456"

例子:B<String>[][] b = new B[3][4];

  • JCNewArray new B[3][4]
  • elemtype (JCExpression) = (JCIdent) B
  • dims (List<JCTree.JCExpression>) [0] = (JCLiteral) 3
  • dims (List<JCTree.JCExpression>) [1] = (JCLiteral) 4
  • elems (List<JCTree.JCExpression>) 空
protected JCNewArray(JCTree.JCExpression var1, List<JCTree.JCExpression> var2, List<JCTree.JCExpression> var3) {
    this.elemtype = var1;
    this.dims = var2;
    this.annotations = List.nil();
    this.dimAnnotations = List.nil();
    this.elems = var3;
}

JCNewClass

new一个对象:

例子:new B<String>("123")

  • JCNewClass new B<String>("123")
  • clazz (JCExpression) = (JCTypeApply) B<String>
  • args (List<JCTree.JCExpression>) [0] = (JCLiteral) "123"
protected JCNewClass(JCTree.JCExpression var1, List<JCTree.JCExpression> var2, JCTree.JCExpression var3, List<JCTree.JCExpression> var4, JCTree.JCClassDecl var5) {
    this.encl = var1;
    this.typeargs = var2 == null ? List.nil() : var2;
    this.clazz = var3;
    this.args = var4;
    this.def = var5;
}

JCParens

括号:(expr) 存在于if、计算式、synchronized中

protected JCParens(JCTree.JCExpression var1) {
    this.expr = var1;
}

JCPrimitiveTypeTree

基本类型:

基本类型的赋值:int i = 0 :

  • typetag = INT

方法的返回值:void print(String s) {Log.e(TAG, s);}

  • typetag = VOID
protected JCPrimitiveTypeTree(TypeTag var1) {
    this.typetag = var1;
}

typetag可选值:

INT : int
LONG : long
FLOAT : float
DOUBLE : double
DOOLEAN : boolean
CHAR : char
BYTE : byte
short : short
VOID : void

JCReturn

return语句:return expr

protected JCReturn(JCTree.JCExpression var1) {
    this.expr = var1;
}

JCSkip

空操作,即一个无效的分号 ";"

JCStatement

声明:凡是继承JCStatement都是一个声明,在JCBlock中拿到的都是JCStatement,想在JCBlock中拿到JCExpression就用JCExpressionStatement

JCSWitch

switch语句:switch(selector) {cases}

protected JCSwitch(JCTree.JCExpression var1, List<JCTree.JCCase> var2) {
    this.selector = var1;
    this.cases = var2;
}

JCSynchronized

synchronized同步锁:synchronized(lock){block}

protected JCSynchronized(JCTree.JCExpression var1, JCTree.JCBlock var2) {
    this.lock = var1;
    this.body = var2;
}

JCThrow

抛出异常:throw expr

protected JCThrow(JCTree.JCExpression var1) {
    this.expr = var1;
}

JCTry

try块:try body catchers finally finalizer

protected JCTry(List<JCTree> var1, JCTree.JCBlock var2, List<JCTree.JCCatch> var3, JCTree.JCBlock var4) {
    this.body = var2;
    this.catchers = var3;
    this.finalizer = var4;
    this.resources = var1;
}

resources不知道是什么

JCTypeApply

泛型参数:List<String> list = new ArrayList<>()

对于List<String> list:

  • clazz (JCExpression) = (JCIdent) List
  • arguments (List<JCTree.JCExpression>) [0] = (JCIdent) String

对于new ArrayList<>():

  • clazz (JCExpression) = (JCIdent) ArrayList
  • arguments (List<JCTree.JCExpression>) = empty
protected JCTypeApply(JCTree.JCExpression var1, List<JCTree.JCExpression> var2) {
    this.clazz = var1;
    this.arguments = var2;
}

JCTypeCast

类型转换:(clazz)expr

例子:View textView = ((TextView) findViewById(R.id.text));

  • JCTypeCast (TextView)findViewById(R.id.text)
  • clazz (JCTree) = (JCIdent) TextView
  • expr (JCExpression) = (JCMethodInvocation) findViewById(R.id.text)

例子:TextView t = (TextView) textView;

  • JCTypeCast (TextView)textView
  • clazz (JCTree) = (JCIdent) TextView
  • expr (JCExpression) = (JCIdent) textView
protected JCTypeCast(JCTree var1, JCTree.JCExpression var2) {
    this.clazz = var1;
    this.expr = var2;
}

JCTypelntersection

unknown

泛型交叉:

public static class A<T extends String & Runnable> {

}
protected JCTypeIntersection(List<JCTree.JCExpression> var1) {
    this.bounds = var1;
}

JCTypeParameter

类的泛型定义:class<annotations name bounds>

  • JCTypeParameter @Anno() T extends View
  • name (Name) = (NameImpl) T
  • bounds (List<JCTree.JCExpression>) [0] = (JCIdent) View
    JCAnnotation @MainActivity.A()
protected JCTypeParameter(Name var1, List<JCTree.JCExpression> var2, List<JCTree.JCAnnotation> var3) {
    this.name = var1;
    this.bounds = var2;
    this.annotations = var3;
}

JCTypeUnion

catch块中异常的或定义:T1 | T2 | ... Tn

try{
    ...
}catch (ClassCastException | ArrayIndexOutOfBoundsException e){
    ...
}
  • JCTypeUnion ClassCastException | ArrayIndexOutOfBoundsException
  • alternatives (List<JCTree.JCExpression>) [0] = (JCIdent) ClassCastException
  • alternatives (List<JCTree.JCExpression>) [1] = (JCIdent) ArrayIndexOutOfBoundsException
protected JCTypeUnion(List<JCTree.JCExpression> var1) {
    this.alternatives = var1;
}

JCUnary

一元运算语句:i++中

  • opcode = POSTINC
  • arg = i (实际是JCIdent类型)
protected JCUnary(JCTree.Tag var1, JCTree.JCExpression var2) {
    this.opcode = var1;
    this.arg = var2;
}
/** Unary operators, of type Unary.
 */
POS,                             // +
NEG,                             // -
NOT,                             // !
COMPL,                           // ~
PREINC,                          // ++ _
PREDEC,                          // -- _
POSTINC,                         // _ ++
POSTDEC,                         // _ --

JCVariableDecl

定义变量: mods vartype name = init

例子:final TextView textView = findViewById(R.id.text);

  • JCVariableDecl final TextView textView = findViewById(R.id.text)
  • mods (JCModifiers) = final
  • name (Name) = (NameImpl) textView
  • vartype (JCExpression) = (JCIdent) TextView
  • init (JCExpression) = (JCMethodInvocation) findViewById(R.id.text)

例子:double i = 1 + 2 * 3;

  • JCVariableDecl double i = 1 + 2 * 3
  • name (Name) = (NameImpl) i
  • vartype (JCExpression) = (JCPrimitiveTypeTree) double
  • init (JCExpression) = (JCBinary) 1 + 2 * 3

例子:int k = cond ? 0 : 1;

  • JCVariableDecl int k = cond ? 0 : 1
  • init (JCExpression) = (JCConditional) cond ? 0 : 1
protected JCVariableDecl(JCTree.JCModifiers var1, Name var2, JCTree.JCExpression var3, JCTree.JCExpression var4, VarSymbol var5) {
    this.mods = var1;
    this.name = var2;
    this.vartype = var3;
    this.init = var4;
    this.sym = var5;
}

JCWhileLoop

while循环:while(cond){body}

为什么body不是Statement List或Block?

protected JCWhileLoop(JCTree.JCExpression var1, JCTree.JCStatement var2) {
    this.cond = var1;
    this.body = var2;
}

JCWildcard

泛型中的"?"通配符:Class<? super String> c;

  • JCWildcard ? super String
  • kind (TypeBoundKind) = ? super
  • inner (JCTree) = (JCIdent) String
protected JCWildcard(JCTree.TypeBoundKind var1, JCTree var2) {
    var1.getClass();
    this.kind = var1;
    this.inner = var2;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,386评论 6 479
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,939评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,851评论 0 341
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,953评论 1 278
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,971评论 5 369
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,784评论 1 283
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,126评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,765评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 43,148评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,744评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,858评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,479评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,080评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,053评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,278评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,245评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,590评论 2 343

推荐阅读更多精彩内容