Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
沉迷打码的小凳子
glide
提交
c3328fe6
G
glide
项目概览
沉迷打码的小凳子
/
glide
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glide
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
c3328fe6
编写于
6月 18, 2018
作者:
C
Colin White
提交者:
Sam
6月 18, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Android X support to the annotation processor. (#3139)
上级
4c8a7b59
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
46 addition
and
21 deletion
+46
-21
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideGenerator.java
...om/bumptech/glide/annotation/compiler/GlideGenerator.java
+11
-5
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java
...com/bumptech/glide/annotation/compiler/ProcessorUtil.java
+23
-2
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java
...ch/glide/annotation/compiler/RequestBuilderGenerator.java
+3
-3
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestManagerGenerator.java
...ch/glide/annotation/compiler/RequestManagerGenerator.java
+4
-5
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java
...ch/glide/annotation/compiler/RequestOptionsGenerator.java
+5
-6
未找到文件。
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/GlideGenerator.java
浏览文件 @
c3328fe6
...
...
@@ -79,6 +79,9 @@ final class GlideGenerator {
private
static
final
String
VISIBLE_FOR_TESTING_QUALIFIED_NAME
=
"android.support.annotation.VisibleForTesting"
;
private
static
final
String
VISIBLE_FOR_TESTING_QUALIFIED_NAME_ANDROIDX
=
"androidx.annotation.VisibleForTesting"
;
private
static
final
String
SUPPRESS_LINT_PACKAGE_NAME
=
"android.annotation"
;
private
static
final
String
SUPPRESS_LINT_CLASS_NAME
=
...
...
@@ -174,11 +177,14 @@ final class GlideGenerator {
}
private
Builder
addReturnAnnotations
(
Builder
builder
,
ExecutableElement
methodToOverride
)
{
String
visibleForTestingTypeQualifiedName
=
processingEnv
.
getElementUtils
()
.
getTypeElement
(
VISIBLE_FOR_TESTING_QUALIFIED_NAME
)
.
toString
();
Elements
elements
=
processingEnv
.
getElementUtils
();
TypeElement
visibleForTestingTypeElement
=
elements
.
getTypeElement
(
VISIBLE_FOR_TESTING_QUALIFIED_NAME_ANDROIDX
);
if
(
visibleForTestingTypeElement
==
null
)
{
// Fall back to looking for the Support library version.
visibleForTestingTypeElement
=
elements
.
getTypeElement
(
VISIBLE_FOR_TESTING_QUALIFIED_NAME
);
}
String
visibleForTestingTypeQualifiedName
=
visibleForTestingTypeElement
.
toString
();
for
(
AnnotationMirror
mirror
:
methodToOverride
.
getAnnotationMirrors
())
{
builder
.
addAnnotation
(
AnnotationSpec
.
get
(
mirror
));
...
...
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/ProcessorUtil.java
浏览文件 @
c3328fe6
...
...
@@ -68,6 +68,12 @@ final class ProcessorUtil {
ClassName
.
get
(
"android.support.annotation"
,
"NonNull"
);
private
static
final
ClassName
JETBRAINS_NOTNULL_ANNOTATION
=
ClassName
.
get
(
"org.jetbrains.annotations"
,
"NotNull"
);
private
static
final
ClassName
ANDROIDX_NONNULL_ANNOTATION
=
ClassName
.
get
(
"androidx.annotation"
,
"NonNull"
);
private
static
final
ClassName
CHECK_RESULT_ANNOTATION
=
ClassName
.
get
(
"android.support.annotation"
,
"CheckResult"
);
private
static
final
ClassName
ANDROIDX_CHECK_RESULT_ANNOTATION
=
ClassName
.
get
(
"androidx.annotation"
,
"CheckResult"
);
private
final
ProcessingEnvironment
processingEnv
;
private
final
TypeElement
appGlideModuleType
;
...
...
@@ -439,11 +445,26 @@ final class ProcessorUtil {
}
static
ClassName
nonNull
()
{
return
NONNULL_ANNOTATION
;
try
{
Class
.
forName
(
ANDROIDX_NONNULL_ANNOTATION
.
reflectionName
());
return
ANDROIDX_NONNULL_ANNOTATION
;
}
catch
(
ClassNotFoundException
e
)
{
return
NONNULL_ANNOTATION
;
}
}
static
ClassName
checkResult
()
{
try
{
Class
.
forName
(
ANDROIDX_CHECK_RESULT_ANNOTATION
.
reflectionName
());
return
ANDROIDX_CHECK_RESULT_ANNOTATION
;
}
catch
(
ClassNotFoundException
e
)
{
return
CHECK_RESULT_ANNOTATION
;
}
}
static
List
<
ClassName
>
nonNulls
()
{
return
Arrays
.
asList
(
NONNULL_ANNOTATION
,
JETBRAINS_NOTNULL_ANNOTATION
);
return
Arrays
.
asList
(
NONNULL_ANNOTATION
,
JETBRAINS_NOTNULL_ANNOTATION
,
ANDROIDX_NONNULL_ANNOTATION
);
}
List
<
ExecutableElement
>
findInstanceMethodsReturning
(
TypeElement
clazz
,
TypeMirror
returnType
)
{
...
...
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestBuilderGenerator.java
浏览文件 @
c3328fe6
package
com.bumptech.glide.annotation.compiler
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
checkResult
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
nonNull
;
import
com.bumptech.glide.annotation.GlideExtension
;
...
...
@@ -107,9 +108,8 @@ final class RequestBuilderGenerator {
/** A set of method names to avoid overriding from RequestOptions. */
private
static
final
ImmutableSet
<
String
>
EXCLUDED_METHODS_FROM_BASE_REQUEST_OPTIONS
=
ImmutableSet
.
of
(
"clone"
,
"apply"
,
"autoLock"
,
"lock"
,
"autoClone"
);
private
static
final
ClassName
CHECK_RESULT_CLASS_NAME
=
ClassName
.
get
(
"android.support.annotation"
,
"CheckResult"
);
private
static
final
AnnotationSpec
NON_NULL
=
AnnotationSpec
.
builder
(
nonNull
()).
build
();
private
static
final
AnnotationSpec
CHECK_RESULT
=
AnnotationSpec
.
builder
(
checkResult
()).
build
();
private
final
ProcessingEnvironment
processingEnv
;
private
final
ProcessorUtil
processorUtil
;
...
...
@@ -448,7 +448,7 @@ final class RequestBuilderGenerator {
=
ParameterizedTypeName
.
get
(
generatedRequestBuilderClassName
,
ClassName
.
get
(
File
.
class
));
return
MethodSpec
.
methodBuilder
(
"getDownloadOnlyRequest"
)
.
addAnnotation
(
Override
.
class
)
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
()
)
.
addAnnotation
(
CHECK_RESULT
)
.
addAnnotation
(
NON_NULL
)
.
returns
(
generatedRequestBuilderOfFile
)
.
addModifiers
(
Modifier
.
PROTECTED
)
...
...
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestManagerGenerator.java
浏览文件 @
c3328fe6
package
com.bumptech.glide.annotation.compiler
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
checkResult
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
nonNull
;
import
com.bumptech.glide.annotation.GlideExtension
;
...
...
@@ -61,8 +62,6 @@ final class RequestManagerGenerator {
"com.bumptech.glide.manager.Lifecycle"
;
private
static
final
String
REQUEST_MANAGER_TREE_NODE_QUALIFIED_NAME
=
"com.bumptech.glide.manager.RequestManagerTreeNode"
;
private
static
final
ClassName
CHECK_RESULT_CLASS_NAME
=
ClassName
.
get
(
"android.support.annotation"
,
"CheckResult"
);
private
static
final
ClassName
CONTEXT_CLASS_NAME
=
ClassName
.
get
(
"android.content"
,
"Context"
);
...
...
@@ -164,7 +163,7 @@ final class RequestManagerGenerator {
return
MethodSpec
.
methodBuilder
(
"as"
)
.
addModifiers
(
Modifier
.
PUBLIC
)
.
addAnnotation
(
Override
.
class
)
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addAnnotation
(
nonNull
())
.
addTypeVariable
(
TypeVariableName
.
get
(
"ResourceType"
))
.
returns
(
requestBuilderOfResourceType
)
...
...
@@ -289,7 +288,7 @@ final class RequestManagerGenerator {
.
returns
(
parameterizedTypeName
)
.
addJavadoc
(
processorUtil
.
generateSeeMethodJavadoc
(
extensionMethod
))
.
addAnnotation
(
nonNull
())
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addStatement
(
"$T requestBuilder = this.as($T.class)"
,
parameterizedTypeName
,
returnTypeClassName
)
.
addStatement
(
"$T.$N(requestBuilder)"
,
...
...
@@ -311,7 +310,7 @@ final class RequestManagerGenerator {
.
returns
(
parameterizedTypeName
)
.
addJavadoc
(
processorUtil
.
generateSeeMethodJavadoc
(
extensionMethod
))
.
addAnnotation
(
nonNull
())
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addStatement
(
"return ($T) $T.$N(this.as($T.class))"
,
parameterizedTypeName
,
...
...
annotation/compiler/src/main/java/com/bumptech/glide/annotation/compiler/RequestOptionsGenerator.java
浏览文件 @
c3328fe6
package
com.bumptech.glide.annotation.compiler
;
import
static
com
.
bumptech
.
glide
.
annotation
.
GlideOption
.
OVERRIDE_EXTEND
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
checkResult
;
import
static
com
.
bumptech
.
glide
.
annotation
.
compiler
.
ProcessorUtil
.
nonNull
;
import
com.bumptech.glide.annotation.GlideExtension
;
...
...
@@ -76,8 +77,6 @@ final class RequestOptionsGenerator {
private
static
final
String
REQUEST_OPTIONS_SIMPLE_NAME
=
"RequestOptions"
;
static
final
String
REQUEST_OPTIONS_QUALIFIED_NAME
=
REQUEST_OPTIONS_PACKAGE_NAME
+
"."
+
REQUEST_OPTIONS_SIMPLE_NAME
;
private
static
final
ClassName
CHECK_RESULT_CLASS_NAME
=
ClassName
.
get
(
"android.support.annotation"
,
"CheckResult"
);
private
final
ProcessingEnvironment
processingEnvironment
;
private
final
ClassName
requestOptionsName
;
...
...
@@ -301,7 +300,7 @@ final class RequestOptionsGenerator {
builder
.
addStatement
(
code
.
toString
(),
args
.
toArray
(
new
Object
[
0
]));
builder
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addAnnotation
(
nonNull
());
List
<
MethodAndStaticVar
>
result
=
new
ArrayList
<>();
...
...
@@ -375,7 +374,7 @@ final class RequestOptionsGenerator {
builder
.
addStatement
(
code
.
toString
(),
args
.
toArray
(
new
Object
[
0
]));
builder
.
addStatement
(
"return this"
)
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addAnnotation
(
nonNull
());
List
<
MethodAndStaticVar
>
result
=
new
ArrayList
<>();
...
...
@@ -483,7 +482,7 @@ final class RequestOptionsGenerator {
}
methodSpecBuilder
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
())
.
addAnnotation
(
checkResult
())
.
addAnnotation
(
nonNull
());
return
new
MethodAndStaticVar
(
methodSpecBuilder
.
build
(),
requiredStaticField
);
...
...
@@ -569,7 +568,7 @@ final class RequestOptionsGenerator {
TypeVariableName
.
get
(
typeParameterElement
.
getSimpleName
().
toString
()));
}
methodSpecBuilder
.
addAnnotation
(
AnnotationSpec
.
builder
(
CHECK_RESULT_CLASS_NAME
).
build
());
methodSpecBuilder
.
addAnnotation
(
checkResult
());
return
new
MethodAndStaticVar
(
methodSpecBuilder
.
build
(),
requiredStaticField
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录