Java 文件结构
- PackageElement:Java文件的包名
- TypeElement:Java文件的类型Class、Interface、Enum、Annotation等
- VariableElement:Java文件的属性Field
- ExecutableElement:Java文件的方法
方法
-
getSimpleName().toString()
获取当前element的名字(类名、方法名、属性名、当前包名等)
MainActivity、onCreate、textView、percentrelativelayout
-
asType().toString()
获取当前element的实际类型
android.view.View com.stone.percentrelativelayout.MainActivity com.stone.percentrelativelayout
-
getEnclosingElement()
获取当前element所处闭包的类型
根据Java文件结构,易知:
VariableElement -> TypeElement TypeElement -> PackageElement
-
getEnclosedElements()
获取当前element直接包含的闭包类型集合
VariableElement -> 0 TypeElement -> 所有属性、方法、构造器 MainActivity(),textView,textView2,TAG,onCreate(android.os.Bundle),test(java.lang.String,int,double) PackageElement -> 当前包中的所有Java文件
-
getKind()
获取当前element对应的类型
FIELD、CLASS、PACKAGE、METHO等
-
getModifiers()
获取修饰符的集合
[protected]、[private, static, final]
-
getQualifiedName().toString()
TypeElement以及PackageElement中方法,用以获取其全限定名字
-
getConstantValue()
VariableElement的方法,用以获取final属性的值,即只有属性的修饰符有final时才能够获取到正确的返回值,非final的都是null;
注: ================================
注: current annotation's value is 2131427423
注: ====begin====
注: element is VariableElement
注: getConstantValue().toString() = null
注: element的getSimpleName() = textView2
注: element的asType() = android.view.View
注: getEnclosedElements() =
注: element的getKind() = FIELD
注: element的getModifiers() = [protected]
注: ====begin====
注: element is TypeElement
注: getQualifiedName() = com.stone.percentrelativelayout.MainActivity
注: typeParameters.size() = 0
注: getTypeParameters() =
注: element的getSimpleName() = MainActivity
注: element的asType() = com.stone.percentrelativelayout.MainActivity
注: getEnclosedElements() = MainActivity(),textView,textView2,TAG,onCreate(android.os.Bundle),test(java.lang.String,int,double)
注: element的getKind() = CLASS
注: element的getModifiers() = [public]
注: ====begin====
注: element is PackageElement
注: getQualifiedName() = com.stone.percentrelativelayout
注: element的getSimpleName() = percentrelativelayout
注: element的asType() = com.stone.percentrelativelayout
注: getEnclosedElements() = com.stone.percentrelativelayout.MainActivity$ViewBinder,com.stone.percentrelativelayout.MainActivity,com.stone.percentrelativelayout.PercentRelativeLayout,com.stone.percentrelativelayout.TestConstraintActivity,com.stone.percentrelativelayout.TestConstraintLayout,com.stone.percentrelativelayout.TestRelativeActivity,com.stone.percentrelativelayout.TestRelativeLayout,com.stone.percentrelativelayout.R,com.stone.percentrelativelayout.BuildConfig
注: element的getKind() = PACKAGE
注: element的getModifiers() = []
注: ====begin====
注: element is null
注: =====end=======
注: =====end=======
注: =====end=======
注: =================================
网友评论