Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Scala Macro Tools
提交
07e15e9c
S
Scala Macro Tools
项目概览
梦境迷离
/
Scala Macro Tools
上一次同步 1 年多
通知
8
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Scala Macro Tools
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
07e15e9c
编写于
8月 04, 2021
作者:
梦境迷离
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor
上级
7bef18a3
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
29 addition
and
17 deletion
+29
-17
src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala
.../io/github/dreamylost/macros/AbstractMacroProcessor.scala
+17
-5
src/main/scala/io/github/dreamylost/macros/constructorMacro.scala
.../scala/io/github/dreamylost/macros/constructorMacro.scala
+1
-1
src/main/scala/io/github/dreamylost/macros/equalsAndHashCodeMacro.scala
.../io/github/dreamylost/macros/equalsAndHashCodeMacro.scala
+1
-1
src/main/scala/io/github/dreamylost/macros/jacksonEnumMacro.scala
.../scala/io/github/dreamylost/macros/jacksonEnumMacro.scala
+3
-3
src/main/scala/io/github/dreamylost/macros/synchronizedMacro.scala
...scala/io/github/dreamylost/macros/synchronizedMacro.scala
+6
-6
src/main/scala/io/github/dreamylost/macros/toStringMacro.scala
...ain/scala/io/github/dreamylost/macros/toStringMacro.scala
+1
-1
未找到文件。
src/main/scala/io/github/dreamylost/macros/AbstractMacroProcessor.scala
浏览文件 @
07e15e9c
...
...
@@ -373,7 +373,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
rhs
:
Tree
)
{
// def typeName: TypeName = symbol.name.toTypeName // unused
def
typeName
:
TypeName
=
symbol
.
name
.
toTypeName
def
symbol
:
c.universe.Symbol
=
paramType
.
typeSymbol
}
...
...
@@ -384,7 +384,7 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
* @param params The list of params retrieved from the class
* @return An Sequence of tuples where each tuple encodes the string name and string type of a field
*/
def
accessors
(
params
:
Seq
[
ValDef
])
:
Seq
[
Accessor
]
=
{
def
accessors
(
params
:
Seq
[
Tree
])
:
Seq
[
Accessor
]
=
{
params
.
map
{
case
ValDef
(
mods
,
name
:
TermName
,
tpt
:
Tree
,
rhs
)
=>
{
Accessor
(
mods
,
name
,
c
.
typecheck
(
tq
"$tpt"
,
c
.
TYPEmode
).
tpe
,
rhs
)
...
...
@@ -405,19 +405,31 @@ abstract class AbstractMacroProcessor(val c: whitebox.Context) {
/**
* Generate the specified syntax tree and assign it to the tree definition itself.
* Used only when you modify the definition of the class itself. Such as add method/add field
* Used only when you modify the definition of the class itself. Such as add method/add field
.
*
* @param classDecl
* @param classInfoAction
* @param classInfoAction
Content body added in class definition
* @return
*/
def
append
ed
Body
(
classDecl
:
ClassDef
,
classInfoAction
:
ClassDefinition
=>
Seq
[
Tree
])
:
c.universe.ClassDef
=
{
def
append
Class
Body
(
classDecl
:
ClassDef
,
classInfoAction
:
ClassDefinition
=>
Seq
[
Tree
])
:
c.universe.ClassDef
=
{
val
classInfo
=
mapToClassDeclInfo
(
classDecl
)
val
ClassDef
(
mods
,
name
,
tparams
,
impl
)
=
classDecl
val
Template
(
parents
,
self
,
body
)
=
impl
ClassDef
(
mods
,
name
,
tparams
,
Template
(
parents
,
self
,
body
++
classInfoAction
(
classInfo
)))
}
/**
* Modify the method body of the method tree.
*
* @param defDef
* @param defBodyAction Method body of final result
* @return
*/
def
mapToMethodDef
(
defDef
:
DefDef
,
defBodyAction
:
=>
Tree
)
:
c.universe.DefDef
=
{
val
DefDef
(
mods
,
name
,
tparams
,
vparamss
,
tpt
,
rhs
)
=
defDef
DefDef
(
mods
,
name
,
tparams
,
vparamss
,
tpt
,
defBodyAction
)
}
private
[
macros
]
case
class
ClassDefinition
(
className
:
TypeName
,
classParamss
:
List
[
List
[
Tree
]],
...
...
src/main/scala/io/github/dreamylost/macros/constructorMacro.scala
浏览文件 @
07e15e9c
...
...
@@ -99,7 +99,7 @@ object constructorMacro {
}
override
def
createCustomExpr
(
classDecl
:
ClassDef
,
compDeclOpt
:
Option
[
ModuleDef
]
=
None
)
:
Any
=
{
val
resTree
=
append
ed
Body
(
val
resTree
=
append
Class
Body
(
classDecl
,
classInfo
=>
Seq
(
getThisMethodWithCurrying
(
classInfo
.
classParamss
,
classInfo
.
body
)))
c
.
Expr
(
resTree
)
...
...
src/main/scala/io/github/dreamylost/macros/equalsAndHashCodeMacro.scala
浏览文件 @
07e15e9c
...
...
@@ -119,7 +119,7 @@ object equalsAndHashCodeMacro {
getInternalFieldsTermNameExcludeLocal
(
classDefinition
.
body
)
}
val
classDefinition
=
mapToClassDeclInfo
(
classDecl
)
val
res
=
append
ed
Body
(
classDecl
,
classInfo
=>
val
res
=
append
Class
Body
(
classDecl
,
classInfo
=>
getEqualsMethod
(
classDefinition
.
className
,
map
(
classInfo
),
classDefinition
.
superClasses
,
classDefinition
.
body
)
++
List
(
getHashcodeMethod
(
map
(
classInfo
),
classDefinition
.
superClasses
))
...
...
src/main/scala/io/github/dreamylost/macros/jacksonEnumMacro.scala
浏览文件 @
07e15e9c
...
...
@@ -49,7 +49,7 @@ object jacksonEnumMacro {
}
private
def
getTypeTermName
(
valDefTree
:
Tree
)
:
c.universe.TermName
=
{
val
safeValDef
=
accessors
(
Seq
(
valDefTree
.
asInstanceOf
[
ValDef
]
)).
head
val
safeValDef
=
accessors
(
Seq
(
valDefTree
)).
head
getTypeTermName
(
safeValDef
)
}
...
...
@@ -63,8 +63,8 @@ object jacksonEnumMacro {
}
private
def
replaceAnnotation
(
valDefTree
:
Tree
)
:
Tree
=
{
val
safeValDef
=
accessors
(
Seq
(
valDefTree
.
asInstanceOf
[
ValDef
]
)).
head
if
(
safeValDef
.
symbol
.
name
.
toTerm
Name
.
toString
==
"Value"
)
{
val
safeValDef
=
accessors
(
Seq
(
valDefTree
)).
head
if
(
safeValDef
.
typeName
.
decoded
Name
.
toString
==
"Value"
)
{
// duplication should be removed
val
mods
=
safeValDef
.
mods
.
mapAnnotations
(
f
=>
{
if
(!
f
.
toString
().
contains
(
"JsonScalaEnumeration"
)
&&
...
...
src/main/scala/io/github/dreamylost/macros/synchronizedMacro.scala
浏览文件 @
07e15e9c
...
...
@@ -43,18 +43,18 @@ object synchronizedMacro {
}
override
def
impl
(
annottees
:
c.universe.Expr
[
Any
]*)
:
c.universe.Expr
[
Any
]
=
{
val
resTree
=
annottees
map
(
_
.
tree
)
match
{
// Match a method, and expand.
case
_@
q
"$modrs def $tname[..$tparams](...$paramss): $tpt = $expr"
::
_
=>
if
(
extractArgumentsDetail
.
_2
!=
null
)
{
val
resTree
=
annottees
.
map
(
_
.
tree
)
match
{
case
(
defDef
:
DefDef
)
::
Nil
=>
val
body
=
if
(
extractArgumentsDetail
.
_2
!=
null
)
{
if
(
extractArgumentsDetail
.
_2
==
"this"
)
{
q
"
""def $tname[..$tparams](...$paramss): $tpt = ${This(TypeName(""))}.synchronized { $expr }""
"
q
"
${This(TypeName(""))}.synchronized { ${defDef.rhs} }
"
}
else
{
q
"
""def $tname[..$tparams](...$paramss): $tpt = ${TermName(extractArgumentsDetail._2)}.synchronized { $expr }""
"
q
"
${TermName(extractArgumentsDetail._2)}.synchronized { ${defDef.rhs} }
"
}
}
else
{
c
.
abort
(
c
.
enclosingPosition
,
"Invalid args, lockName cannot be a null!"
)
}
mapToMethodDef
(
defDef
,
body
)
case
_
=>
c
.
abort
(
c
.
enclosingPosition
,
"Invalid annotation target: not a method"
)
}
printTree
(
extractArgumentsDetail
.
_1
,
resTree
)
...
...
src/main/scala/io/github/dreamylost/macros/toStringMacro.scala
浏览文件 @
07e15e9c
...
...
@@ -73,7 +73,7 @@ object toStringMacro {
extractArgumentsDetail
.
_3
,
extractArgumentsDetail
.
_4
)
// Check the type of the class, which can only be defined on the ordinary class
val
annotateeClass
:
ClassDef
=
checkAndGetClassDef
(
annottees
:
_
*
)
val
resTree
=
append
ed
Body
(
annotateeClass
,
_
=>
Seq
(
toStringTemplateImpl
(
argument
,
annotateeClass
)))
val
resTree
=
append
Class
Body
(
annotateeClass
,
_
=>
Seq
(
toStringTemplateImpl
(
argument
,
annotateeClass
)))
val
res
=
treeReturnWithDefaultCompanionObject
(
resTree
,
annottees
:
_
*
)
printTree
(
argument
.
verbose
,
res
)
c
.
Expr
[
Any
](
res
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录