Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
梦境迷离
Scala Macro Tools
提交
67ee0bc3
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 搜索 >>
未验证
提交
67ee0bc3
编写于
7月 19, 2021
作者:
I
IceMimosa
提交者:
GitHub
7月 19, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
IDEA plugin - `@apply` support generic & currying (#68)
上级
e1f34eae
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
32 addition
and
9 deletion
+32
-9
.gitignore
.gitignore
+1
-1
intellij-plugin/src/main/scala/io/github/dreamylost/plugin/processor/AbsProcessor.scala
.../io/github/dreamylost/plugin/processor/AbsProcessor.scala
+26
-4
intellij-plugin/src/main/scala/io/github/dreamylost/plugin/processor/clazz/ApplyProcessor.scala
...ub/dreamylost/plugin/processor/clazz/ApplyProcessor.scala
+5
-4
未找到文件。
.gitignore
浏览文件 @
67ee0bc3
...
...
@@ -18,4 +18,4 @@ examples2-13/target/
intellij-plugin/target/
intellij-plugin/project/project/
intellij-plugin/project/target/
/.idea
/
.run
/
\ No newline at end of file
intellij-plugin/src/main/scala/io/github/dreamylost/plugin/processor/AbsProcessor.scala
浏览文件 @
67ee0bc3
...
...
@@ -19,15 +19,37 @@ abstract class AbsProcessor extends Processor {
* @return name and type
*/
protected
def
getConstructorParameters
(
clazz
:
ScClass
,
withSecond
:
Boolean
=
true
)
:
Seq
[(
String
,
String
)]
=
{
this
.
getConstructorCurryingParameters
(
clazz
,
withSecond
,
withCurrying
=
false
).
head
}
/**
* get constructor parameters with currying
*
* @return
* if `withCurrying` = true, return (name: type, name: type)(name: type)...
* else return (name: type, name: type, name: type, ...)
*/
protected
def
getConstructorCurryingParameters
(
clazz
:
ScClass
,
withSecond
:
Boolean
=
true
,
withCurrying
:
Boolean
=
true
)
:
Seq
[
Seq
[(
String
,
String
)]]
=
{
val
constructors
=
if
(
withSecond
)
{
clazz
.
constructors
.
map
(
Some
(
_
))
}
else
{
Seq
(
clazz
.
constructor
.
map
(
_
.
asInstanceOf
[
ScMethodLike
]))
}
constructors
.
flatten
.
flatMap
(
_
.
getParameterList
.
getParameters
)
.
collect
{
case
p
:
ScClassParameter
=>
p
.
name
->
p
.
`type`
().
toOption
.
map
(
_
.
toString
).
getOrElse
(
"Unit"
)
if
(
withCurrying
)
{
constructors
.
flatten
.
flatMap
{
c
=>
c
.
effectiveParameterClauses
.
map
(
_
.
effectiveParameters
.
collect
{
case
p
:
ScClassParameter
=>
p
.
name
->
p
.
`type`
().
toOption
.
map
(
_
.
toString
).
getOrElse
(
"Unit"
)
})
}
}
else
{
Seq
(
constructors
.
flatten
.
flatMap
(
_
.
getParameterList
.
getParameters
)
.
collect
{
case
p
:
ScClassParameter
=>
p
.
name
->
p
.
`type`
().
toOption
.
map
(
_
.
toString
).
getOrElse
(
"Unit"
)
}
)
}
}
}
intellij-plugin/src/main/scala/io/github/dreamylost/plugin/processor/clazz/ApplyProcessor.scala
浏览文件 @
67ee0bc3
...
...
@@ -21,10 +21,11 @@ class ApplyProcessor extends AbsProcessor {
source
match
{
case
obj
:
ScObject
=>
val
clazz
=
obj
.
fakeCompanionClassOrCompanionClass
.
asInstanceOf
[
ScClass
]
val
nameAndTypes
=
getConstructorParameters
(
clazz
,
withSecond
=
false
)
.
map
(
o
=>
s
"${o._1}: ${o._2}"
)
.
mkString
(
", "
)
Seq
(
s
"def apply($nameAndTypes): ${clazz.getName} = ???"
)
val
nameAndTypes
=
getConstructorCurryingParameters
(
clazz
,
withSecond
=
false
)
.
map
(
_
.
map
(
o
=>
s
"${o._1}: ${o._2}"
).
mkString
(
"("
,
", "
,
")"
))
.
mkString
val
genericTypes
=
clazz
.
typeParamString
Seq
(
s
"def apply$genericTypes$nameAndTypes: ${clazz.getName}$genericTypes = ???"
)
case
_
=>
Nil
}
case
_
=>
Nil
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录