JCTree簡要分析
文章目錄
JCTree簡要分析
JCAnnotatedType
JCAnnotation
JCArrayAccess
JCArrayTypeTree
JCAssert
JCAssign
JCAssignOp
JCBinary
JCBlock
JCBreak
JCCase
JCCatch
JCClassDecl
JCCompilationUnit
JCConditional
JCContinue
JCDoWhileLoop
JCEnhancedForLoop
JCErroneous
JCExpression
JCExpressionStatement
JCFieldAccess
JCForloop
JCFunctionalExpression
JCIdent
JCIf
JCImport
JCinstanceOf
JCLabeledStatement
JCLambda
JCLiteral
JCMemberReference
JCMethodDecl
JCMethodinvocation
JCModifiers
JCNewArray
JCNewClass
JCParens
JCPrimitiveTypeTree
JCReturn
JCSkip
JCStatement
JCSWitch
JCSynchronized
JCThrow
JCTry
JCTypeApply
JCTypeCast
JCTypelntersection
unknown
JCTypeParameter
JCTypeUnion
JCUnary
JCVariableDecl
JCWhileLoop
JCWildcard
JCAnnotatedType
被注解的泛型:(注解的Target為ElementType.TYPE_USE時可注解泛型)
public static class A<T extends @Reality String> {
}
1
2
3
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;
}
1
2
3
4
5
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;
}
1
2
3
4
5
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;
}
1
2
3
4
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;
}
1
2
3
JCAssert
assert斷言:assert cond : detail
protected JCAssert(JCTree.JCExpression var1, JCTree.JCExpression var2) {
this.cond = var1;
this.detail = var2;
}
1
2
3
4
JCAssign
賦值:lhs = rhs 例如 i = 1
protected JCAssign(JCTree.JCExpression var1, JCTree.JCExpression var2) {
this.lhs = var1; //左表達式
this.rhs = var2; //右表達式
}
1
2
3
4
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;
}
1
2
3
4
5
6
賦值符號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), // %=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}
1
2
3
4
5
6
二元運算符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, // %
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
JCBlock
語句塊:{stats} 或 static{stats}(flags = 8L時)
protected JCBlock(long var1, List<JCTree.JCStatement> var3) {
this.stats = var3;
this.flags = var1;
}
1
2
3
4
JCBreak
break語句:break:label
label 為標簽名
target 為跳轉目標
protected JCBreak(Name var1, JCTree var2) {
this.label = var1;
this.target = var2;
}
1
2
3
4
JCCase
case語句:case pat : stats
protected JCCase(JCTree.JCExpression var1, List<JCTree.JCStatement> var2) {
this.pat = var1;
this.stats = var2;
}
1
2
3
4
JCCatch
catch捕捉異常:catch(param) body
param 定義異常變量 Exception e
body 代碼塊
protected JCCatch(JCTree.JCVariableDecl var1, JCTree.JCBlock var2) {
this.param = var1;
this.body = var2;
}
1
2
3
4
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);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
mods (JCModifiers) = public
name (Name) = (NameImpl) MainActivity
extending (JCExpression) = (JCIdent) AppCompatActivity
implementing (JCExpression) 實現的接口
defs (List<JCTree>) :
defs(1) : JCMethodDecl
public <init>() {
super();
}
1
2
3
defs(2) : JCBlock
static {
kk = 2;
}
1
2
3
defs(3) : JCVariableDecl
private int kk = 1
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();
}
1
2
3
4
5
6
7
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;
}
1
2
3
4
5
6
7
8
9
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:
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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;
}
1
2
3
4
5
JCContinue
continue跳過一次循環,與break相似:continue label
protected JCContinue(Name var1, JCTree var2) {
this.label = var1;
this.target = var2;
}
1
2
3
4
JCDoWhileLoop
do-while循環:do{body}while(cond)
protected JCDoWhileLoop(JCTree.JCStatement var1, JCTree.JCExpression var2) {
this.body = var1;
this.cond = var2;
}
1
2
3
4
JCEnhancedForLoop
增強循環:for(var : expr) body
例如:
for (String s : list) {
print(s);
}
1
2
3
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;
}
1
2
3
4
5
JCErroneous
Error trees
JCExpression
表達式,賦值、調用方法等都算一個表達式,凡是繼承JCExpression都算一個表達式
JCExpressionStatement
內部封裝了JCExpression,實際上還是個表達式
protected JCExpressionStatement(JCTree.JCExpression var1) {
this.expr = var1;
}
1
2
3
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;
}
1
2
3
4
5
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;
}
1
2
3
4
5
6
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;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
其中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;
}
1
2
3
4
5
JCImport
import語句:
import qulid
static (if staticImport) import qulid
protected JCImport(JCTree var1, boolean var2) {
this.qualid = var1;
this.staticImport = var2;
}
1
2
3
4
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;
}
1
2
3
4
JCLabeledStatement
帶有標簽的語句:label : body
protected JCLabeledStatement(Name var1, JCTree.JCStatement var2) {
this.label = var1;
this.body = var2;
}
1
2
3
4
JCLambda
lambda表達式:此處表達式主體只有一句表達式
textView.setOnClickListener(v -> v.setVisibility(View.INVISIBLE));
1
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);
});
1
2
3
body (JCTree) = (JCBlock) {v.setVisibility(View.VISIBLE);}
getBodyKind() (BodyKind) = STATEMENT
當參數v指明類型為View時:
textView.setOnClickListener((View v) -> v.setVisibility(View.INVISIBLE));
1
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;
}
1
2
3
4
typetag的可選值有:
INT : int
LONG : long
FLOAT : float
DOUBLE : double
CHAR : char
CLASS : String
BOT : null
1
2
3
4
5
6
7
JCMemberReference
lambda表達式中的方法引用:expr::name
例子:new B(“123”).setObjectUtil(ObjectUtil::new);
JCMemberReference ObjectUtil::new
mode (ReferenceMode) = NEW
name (Name) = (NameImpl)
expr (JCExpression) = (JCIdent) ObjectUtil
例子:new B(“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;
}
1
2
3
4
5
6
JCMethodDecl
方法的定義:
例子:
@Reality
private static <T extends String> int print(@NonNull final String s) throws RuntimeException {
Log.e(TAG, s);
return 1;
}
1
2
3
4
5
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) = print(java.lang.String)
例子:
@Reality
@interface B {
int value() default 1;
}
1
2
3
4
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;
}
1
2
3
4
5
6
7
8
9
10
11
12
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;
}
1
2
3
4
5
JCModifiers
類、變量、方法等的修飾符和注解:例如:
@Reality private static final String TAG = "MainActivity";
1
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;
}
1
2
3
4
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
1
2
3
4
5
6
7
8
9
10
11
12
方法默認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[][] 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;
}
1
2
3
4
5
6
7
JCNewClass
new一個對象:
例子:new B(“123”)
JCNewClass new B(“123”)
clazz (JCExpression) = (JCTypeApply) B
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;
}
1
2
3
4
5
6
7
JCParens
括號:(expr) 存在於if、計算式、synchronized中
protected JCParens(JCTree.JCExpression var1) {
this.expr = var1;
}
1
2
3
JCPrimitiveTypeTree
基本類型:
基本類型的賦值:int i = 0 :
typetag = INT
方法的返回值:void print(String s) {Log.e(TAG, s);}
typetag = VOID
protected JCPrimitiveTypeTree(TypeTag var1) {
this.typetag = var1;
}
1
2
3
typetag可選值:
INT : int
LONG : long
FLOAT : float
DOUBLE : double
DOOLEAN : boolean
CHAR : char
BYTE : byte
short : short
VOID : void
1
2
3
4
5
6
7
8
9
JCReturn
return語句:return expr
protected JCReturn(JCTree.JCExpression var1) {
this.expr = var1;
}
1
2
3
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;
}
1
2
3
4
JCSynchronized
synchronized同步鎖:synchronized(lock){block}
protected JCSynchronized(JCTree.JCExpression var1, JCTree.JCBlock var2) {
this.lock = var1;
this.body = var2;
}
1
2
3
4
JCThrow
拋出異常:throw expr
protected JCThrow(JCTree.JCExpression var1) {
this.expr = var1;
}
1
2
3
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;
}
1
2
3
4
5
6
resources不知道是什么
JCTypeApply
泛型參數:List list = new ArrayList<>()
對於List 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;
}
1
2
3
4
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;
}
1
2
3
4
JCTypelntersection
unknown
泛型交叉:
public static class A<T extends String & Runnable> {
}
1
2
3
protected JCTypeIntersection(List<JCTree.JCExpression> var1) {
this.bounds = var1;
}
1
2
3
JCTypeParameter
類的泛型定義:class
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;
}
1
2
3
4
5
JCTypeUnion
catch塊中異常的或定義:T1 | T2 | … Tn
try{
...
}catch (ClassCastException | ArrayIndexOutOfBoundsException e){
...
}
1
2
3
4
5
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;
}
1
2
3
JCUnary
一元運算語句:i++中
opcode = POSTINC
arg = i (實際是JCIdent類型)
protected JCUnary(JCTree.Tag var1, JCTree.JCExpression var2) {
this.opcode = var1;
this.arg = var2;
}
1
2
3
4
/** Unary operators, of type Unary.
*/
POS, // +
NEG, // -
NOT, // !
COMPL, // ~
PREINC, // ++ _
PREDEC, // -- _
POSTINC, // _ ++
POSTDEC, // _ --
1
2
3
4
5
6
7
8
9
10
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;
}
1
2
3
4
5
6
7
JCWhileLoop
while循環:while(cond){body}
為什么body不是Statement List或Block?
protected JCWhileLoop(JCTree.JCExpression var1, JCTree.JCStatement var2) {
this.cond = var1;
this.body = var2;
}
1
2
3
4
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;
}
————————————————
版權聲明:本文為CSDN博主「Lazyjam」的原創文章,遵循CC 4.0 by-sa版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/u013998373/article/details/90050810