Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qq_34031325
engine
提交
3dd1151e
E
engine
项目概览
qq_34031325
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
3dd1151e
编写于
8月 18, 2020
作者:
D
Dan Field
提交者:
GitHub
8月 18, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make const_finder work with implemented and extended classes (#20614)
上级
bf6d7b4e
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
78 addition
and
7 deletion
+78
-7
tools/const_finder/lib/const_finder.dart
tools/const_finder/lib/const_finder.dart
+17
-7
tools/const_finder/test/const_finder_test.dart
tools/const_finder/test/const_finder_test.dart
+17
-0
tools/const_finder/test/fixtures/lib/consts.dart
tools/const_finder/test/fixtures/lib/consts.dart
+8
-0
tools/const_finder/test/fixtures/lib/target.dart
tools/const_finder/test/fixtures/lib/target.dart
+36
-0
未找到文件。
tools/const_finder/lib/const_finder.dart
浏览文件 @
3dd1151e
...
...
@@ -32,9 +32,19 @@ class _ConstVisitor extends RecursiveVisitor<void> {
final
List
<
Map
<
String
,
dynamic
>>
constantInstances
;
final
List
<
Map
<
String
,
dynamic
>>
nonConstantLocations
;
// A cache of previously evaluated classes.
static
Map
<
Class
,
bool
>
_classHeirarchyCache
=
<
Class
,
bool
>{};
bool
_matches
(
Class
node
)
{
return
node
.
enclosingLibrary
.
importUri
.
toString
()
==
classLibraryUri
&&
node
.
name
==
className
;
assert
(
node
!=
null
);
final
bool
result
=
_classHeirarchyCache
[
node
];
if
(
result
!=
null
)
{
return
result
;
}
final
bool
exactMatch
=
node
.
name
==
className
&&
node
.
enclosingLibrary
.
importUri
.
toString
()
==
classLibraryUri
;
_classHeirarchyCache
[
node
]
=
exactMatch
||
node
.
supers
.
any
((
Supertype
supertype
)
=>
_matches
(
supertype
.
classNode
));
return
_classHeirarchyCache
[
node
];
}
// Avoid visiting the same constant more than once.
...
...
tools/const_finder/test/const_finder_test.dart
浏览文件 @
3dd1151e
...
...
@@ -71,11 +71,28 @@ void _checkConsts() {
<
String
,
dynamic
>{
'stringValue'
:
'10'
,
'intValue'
:
10
,
'targetValue'
:
null
},
<
String
,
dynamic
>{
'stringValue'
:
'9'
,
'intValue'
:
9
},
<
String
,
dynamic
>{
'stringValue'
:
'7'
,
'intValue'
:
7
,
'targetValue'
:
null
},
<
String
,
dynamic
>{
'stringValue'
:
'11'
,
'intValue'
:
11
,
'targetValue'
:
null
},
<
String
,
dynamic
>{
'stringValue'
:
'12'
,
'intValue'
:
12
,
'targetValue'
:
null
},
<
String
,
dynamic
>{
'stringValue'
:
'package'
,
'intValue'
:-
1
,
'targetValue'
:
null
},
],
'nonConstantLocations'
:
<
dynamic
>[],
}),
);
final
ConstFinder
finder2
=
ConstFinder
(
kernelFilePath:
constsDill
,
classLibraryUri:
'package:const_finder_fixtures/target.dart'
,
className:
'MixedInTarget'
,
);
expect
<
String
>(
jsonEncode
(
finder2
.
findInstances
()),
jsonEncode
(<
String
,
dynamic
>{
'constantInstances'
:
<
Map
<
String
,
dynamic
>>[
<
String
,
dynamic
>{
'val'
:
'13'
},
],
'nonConstantLocations'
:
<
dynamic
>[],
}),
);
}
void
_checkNonConsts
(
)
{
...
...
tools/const_finder/test/fixtures/lib/consts.dart
浏览文件 @
3dd1151e
...
...
@@ -31,6 +31,14 @@ void main() {
final
StaticConstInitializer
staticConstMap
=
StaticConstInitializer
();
staticConstMap
.
useOne
(
1
);
const
ExtendsTarget
extendsTarget
=
ExtendsTarget
(
'11'
,
11
,
null
);
extendsTarget
.
hit
();
const
ImplementsTarget
implementsTarget
=
ImplementsTarget
(
'12'
,
12
,
null
);
implementsTarget
.
hit
();
const
MixedInTarget
mixedInTraget
=
MixedInTarget
(
'13'
);
mixedInTraget
.
hit
();
}
class
IgnoreMe
{
...
...
tools/const_finder/test/fixtures/lib/target.dart
浏览文件 @
3dd1151e
...
...
@@ -13,3 +13,39 @@ class Target {
print
(
'
$stringValue
$intValue
'
);
}
}
class
ExtendsTarget
extends
Target
{
const
ExtendsTarget
(
String
stringValue
,
int
intValue
,
Target
targetValue
)
:
super
(
stringValue
,
intValue
,
targetValue
);
}
class
ImplementsTarget
implements
Target
{
const
ImplementsTarget
(
this
.
stringValue
,
this
.
intValue
,
this
.
targetValue
);
@override
final
String
stringValue
;
@override
final
int
intValue
;
@override
final
Target
targetValue
;
@override
void
hit
()
{
print
(
'ImplementsTarget -
$stringValue
$intValue
'
);
}
}
mixin
MixableTarget
{
String
get
val
;
void
hit
()
{
print
(
val
);
}
}
class
MixedInTarget
with
MixableTarget
{
const
MixedInTarget
(
this
.
val
);
@override
final
String
val
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录