提交 c483bf52 编写于 作者: 梦境迷离's avatar 梦境迷离

remove plugin from repository

上级 11b71226
......@@ -95,7 +95,4 @@ def paradise(): Def.Setting[Seq[ModuleID]] = {
case Some((2, n)) if n < 13 => Some("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
case _ => None
}).fold(Seq.empty[ModuleID])(f => Seq(compilerPlugin(f)))
}
// Only to import, and every thing in /intellij-plugin.
lazy val `intellij-plugin` = (project in file("intellij-plugin")).settings(publish / skip := true)
}
\ No newline at end of file
import org.jetbrains.sbtidea.Keys._
name := "scala-macro-tools-intellij-plugin"
organization := "org.bitlap.tools"
lazy val scala213 = "2.13.6"
scalaVersion := scala213
lazy val `intellij-plugin` = (project in file("."))
.enablePlugins(SbtIdeaPlugin)
.settings(
version := (ThisBuild / version).value,
scalaVersion := scala213,
ThisBuild / intellijPluginName := "Scala-Macro-Tools",
ThisBuild / intellijBuild := "213.5744.223", // https://confluence.jetbrains.com/display/IDEADEV/IDEA+2021.3+latest+builds
ThisBuild / intellijPlatform := IntelliJPlatform.IdeaCommunity,
Global / intellijAttachSources := true,
Compile / javacOptions ++= "--release" :: "11" :: Nil,
// Global / scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked", "-Xfatal-warnings"),
intellijPlugins ++= Seq("com.intellij.java", "com.intellij.java-i18n", "org.intellij.scala").map(_.toPlugin),
libraryDependencies ++= Seq.empty,
Compile / unmanagedResourceDirectories += baseDirectory.value / "src" / "main" / "resources",
Test / unmanagedResourceDirectories += baseDirectory.value / "src" / "test" / "resources",
patchPluginXml := pluginXmlOptions { xml =>
// xml.version = (ThisBuild / version).value
xml.version = "0.3.4"
xml.pluginDescription = IO.read(baseDirectory.value / "src" / "main" / "resources" / "patch" / "description.html")
xml.changeNotes = IO.read(baseDirectory.value / "src" / "main" / "resources" / "patch" / "change.html")
},
publish / skip := true,
)
sbt.version = 1.6.1
\ No newline at end of file
addSbtPlugin("org.jetbrains" % "sbt-ide-settings" % "1.1.0")
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.13.5")
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<idea-plugin>
<id>Scala-Macro-Tools Plugin</id>
<name>Scala-Macro-Tools</name>
<version>XXX</version>
<vendor>Scala Macro Tools</vendor>
<idea-version since-build="213.0"/>
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.modules.lang</depends>
<depends>com.intellij.modules.java</depends>
<depends>org.intellij.scala</depends>
<depends>com.intellij.properties</depends>
<description><![CDATA[ Description will be added by sbt plugin build ]]></description>
<change-notes><![CDATA[ Change notes will be filled by sbt plugin build ]]></change-notes>
<resource-bundle>messages.PluginBundle</resource-bundle>
<extensions defaultExtensionNs="com.intellij">
<applicationService serviceImplementation="org.bitlap.tools.plugin.ScalaMacroProcessorProvider" />
<!-- <lang.psiAugmentProvider implementation="org.bitlap.tools.plugin.ScalaMacroAugmentProvider"/> -->
<notificationGroup displayType="BALLOON" id="Scala-Macro-Tools Plugin" />
</extensions>
<extensions defaultExtensionNs="org.intellij.scala">
<syntheticMemberInjector implementation="org.bitlap.tools.plugin.ScalaMacroInjector"/>
</extensions>
</idea-plugin>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 404.1418472882417 454" width="808.2836945764834" height="908">
<!-- svg-source:excalidraw -->
<defs>
<style>
@font-face {
font-family: "Virgil";
src: url("https://excalidraw.com/Virgil.woff2");
}
@font-face {
font-family: "Cascadia";
src: url("https://excalidraw.com/Cascadia.woff2");
}
</style>
</defs>
<g transform="translate(10 10) rotate(0 191 217)"><text x="0" y="347" font-family="Helvetica, Segoe UI Emoji" font-size="376.6131465517241px" fill="#000000" text-anchor="start" style="white-space: pre;" direction="ltr">@</text></g><g stroke-linecap="round" transform="translate(277.4356704536201 239.36519249966955) rotate(0.22204287082016708 57.405888228265724 14.792098641394688)"><path d="M-0.7 3.08 L112.84 -1.96 L114.46 25.88 L1.17 25.91" stroke="none" stroke-width="0" fill="#ec0009"></path><path d="M2.08 -2.22 C42.79 -1.5, 91.84 -0.12, 117.52 2.7 M1.29 -0.16 C45.06 1.32, 88.17 2.55, 113.41 1.41 M112.36 1.64 C111.52 12.24, 113.95 14.65, 117.26 30.06 M113.19 -1.49 C114.91 12.05, 115.29 21.36, 115.01 30.93 M116.34 29.32 C77.04 28.67, 42.05 29.17, 1.76 29.13 M114.03 28.2 C80.96 32.9, 49.57 31.18, -1.91 27.73 M-1.41 32.12 C-0.91 15.49, -0.14 10.75, 3.83 -2.81 M1.61 28.82 C0.11 18.86, 1.15 11.04, -1.85 -1.43" stroke="#ec0009" stroke-width="1" fill="none"></path></g><g stroke-linecap="round" transform="translate(278.2913553485272 281.24147943475646) rotate(0.22204287082016708 57.405888228265724 14.792098641394688)"><path d="M-1.52 3.42 L113.54 3.68 L117.35 29.9 L-1.08 25.93" stroke="none" stroke-width="0" fill="#ec0009"></path><path d="M2.82 0.18 C29.17 5.58, 55.15 3.26, 111.46 3.24 M0.24 0.84 C32.29 -0.3, 62 -2.89, 114.77 1.93 M117.51 0.42 C115 12.28, 116.67 18.49, 112.7 27.01 M114.59 -0.28 C115.43 8.98, 113.72 14.24, 113.78 31.56 M111.11 32.46 C75.3 29.51, 40.02 29.92, -1.32 26.49 M113.41 30.03 C82.84 33.24, 50.76 31.02, 0.37 28.4 M-2.85 28.89 C2.92 16.67, -2.12 7.33, -3.71 1.17 M-0.77 29.33 C0.35 22.81, -0.21 16.47, -0.76 -0.59" stroke="#ec0009" stroke-width="1" fill="none"></path></g><g stroke-linecap="round" transform="translate(279.2731770606068 324.99163674394447) rotate(0.22204287082016708 57.405888228265724 14.792098641394716)"><path d="M-2.65 -1.82 L112.54 3.17 L115.02 31.42 L0.66 28.27" stroke="none" stroke-width="0" fill="#ec0009"></path><path d="M-3.67 2.33 C31.39 -2.2, 66.34 0.73, 113.58 0.27 M-0.76 1.71 C29.22 2.52, 60.98 0.83, 114.27 -1.83 M112.05 1.9 C113.16 11.31, 111.39 26.85, 118.36 33.47 M114.03 1.59 C114.62 5.2, 114.04 13.8, 113.13 29.35 M112.78 30.13 C74.57 29.2, 39.14 26.68, -3.97 30.75 M116.75 28.84 C76.89 32.34, 41.81 32.31, -0.92 30.32 M0.46 30.28 C-3.8 26.82, -2.93 19.88, -1.46 -0.39 M-0.93 29.82 C0.55 22.69, -1.05 15.62, -1.36 -0.82" stroke="#ec0009" stroke-width="1" fill="none"></path></g></svg>
\ No newline at end of file
### main/scala/org/jetbrains/scala/samples/actions/PopupDialogAction.scala
gettext.selected={0} selected!
selected.element.tostring=\nSelected Element: {0}
### main/scala/org/jetbrains/scala/samples/listeners/FileOpenedListener.scala
file.opened=File opened
name.getname=Name: {0}
### main/scala/org/jetbrains/scala/samples/services/ApplicationHelloService.scala
hello.this.is.asstring=Hello, this is {0}
### main/scala/org/jetbrains/scala/samples/services/ProjectHelloService.scala
hello.from.project.getname=Hello from project "{0}"!
### main/scala/org/jetbrains/scala/samples/ui/MyToolWindowFactory.scala
my.cool.tool.window=My Cool Tool Window
### resources/META-INF/plugin.xml
action.org.bitlap.tools.plugin.PopupDialogAction.text=Action Basics Plugin: Pop Dialog Action
action.org.bitlap.tools.plugin.PopupDialogAction.description=SDK action example
<![CDATA[
<ul> 0.3.4:
<ol>
<li>transfer to bitlap.org</li>
</ol>
</ul>
<ul> 0.3.0:
<ol>
<li>support @equalsAndHashCode</li>
<li>support generic @apply, @builder</li>
</ol>
</ul>
<ul> 0.2.0:
<ol>
<li>support @builder, @log, @json, @apply</li>
</ol>
</ul>
<ul> 0.1.2:
<ol>
<li>First release, support @builder, @log, @json</li>
</ol>
</ul>
]]>
\ No newline at end of file
<![CDATA[
<h1>Scala Macro Tools plugin for IntelliJ IDEA</h1>
<br/>
<a href="https://github.com/bitlap/scala-macro-tools">GitHub</a> |
<a href="https://github.com/bitlap/scala-macro-tools/issues">Issues</a>
<br/>
<br/>
<b>A plugin that implements Lombok-like functionality with Scala macros</b>
<br/>
<br/>
<b>Features</b>
<ul>
<li>@toString</li>
<li>@json</li>
<li>@builder</li>
<li>@synchronized</li>
<li>@log</li>
<li>@apply</li>
<li>@constructor</li>
</ul>
<br/>
]]>
\ No newline at end of file
package org.bitlap.tools.plugin
import com.intellij.DynamicBundle
import org.jetbrains.annotations.{ NotNull, PropertyKey }
/**
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/6/30
*/
class PluginBundle extends DynamicBundle("messages.PluginBundle")
object PluginBundle {
private val INSTANCE = new PluginBundle()
def message(@NotNull @PropertyKey(resourceBundle = "messages.PluginBundle") key:String, @NotNull params: Any*): String = {
INSTANCE.getMessage(key, params)
}
}
package org.bitlap.tools.plugin
import com.intellij.openapi.components.ServiceManager
import org.bitlap.tools.plugin.processor.ProcessType
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition
import org.jetbrains.plugins.scala.lang.psi.impl.toplevel.typedef.SyntheticMembersInjector
/**
* Desc: main injector to handle scala macro annotations.
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/4
*/
class ScalaMacroInjector extends SyntheticMembersInjector {
private lazy val provider = ServiceManager.getService(classOf[ScalaMacroProcessorProvider])
override def needsCompanionObject(source: ScTypeDefinition): Boolean = {
provider.findProcessors(source).exists(_.needCompanion)
}
override def injectFunctions(source: ScTypeDefinition): Seq[String] = inject(source, ProcessType.Method)
override def injectInners(source: ScTypeDefinition): Seq[String] = inject(source, ProcessType.Inner)
override def injectMembers(source: ScTypeDefinition): Seq[String] = inject(source, ProcessType.Field)
override def injectSupers(source: ScTypeDefinition): Seq[String] = inject(source, ProcessType.Super)
private def inject(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
provider
.findProcessors(source)
.flatMap(_.process(source, typ))
.filter(s => s != null && s.trim.nonEmpty)
}
}
object ScalaMacroInjector
package org.bitlap.tools.plugin
/**
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/6/30
*/
object ScalaMacroNames {
private val NS = "org.bitlap.tools"
val BUILDER = s"$NS.builder"
val LOG = s"$NS.log"
val APPLY = s"$NS.apply"
val CONSTRUCTOR = s"$NS.constructor"
val JSON = s"$NS.json"
val EQUALS_HASHCODE = s"$NS.equalsAndHashCode"
}
package org.bitlap.tools.plugin
import com.intellij.openapi.Disposable
import org.bitlap.tools.plugin.processor.Processor
import org.bitlap.tools.plugin.processor.clazz.{ ApplyProcessor, BuilderProcessor, ConstructorProcessor, EqualsAndHashCodeProcessor, JsonProcessor, LogProcessor }
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScObject, ScTypeDefinition }
import scala.collection.mutable
/**
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/1
*/
class ScalaMacroProcessorProvider extends Disposable {
private val processors = mutable.Map[String, Processor]()
regist(ScalaMacroNames.BUILDER, new BuilderProcessor())
regist(ScalaMacroNames.LOG, new LogProcessor())
regist(ScalaMacroNames.JSON, new JsonProcessor())
regist(ScalaMacroNames.APPLY, new ApplyProcessor())
regist(ScalaMacroNames.CONSTRUCTOR, new ConstructorProcessor())
regist(ScalaMacroNames.EQUALS_HASHCODE, new EqualsAndHashCodeProcessor())
override def dispose(): Unit = {}
def regist(name: String, p: Processor): ScalaMacroProcessorProvider = {
if (p != null) {
this.processors += name.trim -> p
}
this
}
def findProcessors(source: ScTypeDefinition): Seq[Processor] = {
processors.filter { p =>
source match {
case obj: ScObject => obj.hasAnnotation(p._1) || obj.fakeCompanionClassOrCompanionClass.hasAnnotation(p._1)
case clazz: ScClass => clazz.hasAnnotation(p._1)
case _ => source.hasAnnotation(p._1)
}
}.values.toSeq
}
}
package org.bitlap.tools.plugin.processor
import org.jetbrains.plugins.scala.lang.psi.api.base.ScMethodLike
import org.jetbrains.plugins.scala.lang.psi.api.statements.params.ScClassParameter
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScClass
/**
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/6/30
*/
abstract class AbsProcessor extends Processor {
override def needCompanion: Boolean = false
/**
* get constructor parameters
*
* @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]))
}
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")
}
)
}
}
/**
* get type param string
*
* @param returnType if it is return type
* @return
* if `returnType` is false, just return typeParamString with bound like [T <: Any, U]
* else return typeParamString without bound like [T, U]
*/
protected def getTypeParamString(clazz: ScClass, returnType: Boolean = false): String = {
if (!returnType || clazz.typeParamString.isEmpty) {
clazz.typeParamString
} else {
clazz.typeParameters.map(_.name).mkString("[", ", ", "]")
}
}
}
package org.bitlap.tools.plugin.processor
/**
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/5
*/
object ProcessType extends Enumeration {
type ProcessType = Value
val Method, Field, Inner, Super = Value
}
package org.bitlap.tools.plugin.processor
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.ScTypeDefinition
/**
* Desc: Scala annotation processor
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/6/30
*/
trait Processor {
/**
* check this annotation processor should work with companion object
*/
def needCompanion: Boolean
/**
* process generate codes with different `ProcessType`
*/
def process(source: ScTypeDefinition, typ: ProcessType): Seq[String]
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScObject, ScTypeDefinition }
/**
* Desc: Processor for annotation apply
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/8
*/
class ApplyProcessor extends AbsProcessor {
override def needCompanion: Boolean = true
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
case ProcessType.Method =>
source match {
case obj: ScObject =>
val clazz = obj.fakeCompanionClassOrCompanionClass.asInstanceOf[ScClass]
val nameAndTypes = getConstructorCurryingParameters(clazz, withSecond = false)
.map(_.map(o => s"${o._1}: ${o._2}").mkString("(", ", ", ")"))
.mkString
val genericType = getTypeParamString(clazz)
val returnGenericType = getTypeParamString(clazz, returnType = true)
Seq(s"def apply$genericType$nameAndTypes: ${clazz.getName}$returnGenericType = ???")
case _ => Nil
}
case _ => Nil
}
}
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScObject, ScTypeDefinition }
/**
* Desc: Processor for annotation builder
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/6/30
*/
class BuilderProcessor extends AbsProcessor {
private final val builderClassNameSuffix = "Builder"
override def needCompanion: Boolean = true
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
// if companion object, inject builder method
case ProcessType.Method =>
source match {
case obj: ScObject =>
obj.fakeCompanionClassOrCompanionClass match {
case clazz: ScClass =>
val genericType = getTypeParamString(clazz)
val returnGenericType = getTypeParamString(clazz, returnType = true)
Seq(s"""def builder$genericType(): ${genBuilderName(clazz.getName, returnType = true)}$returnGenericType = ???""")
case _ => Nil
}
case _ => Nil
}
// if class, inject builder class
case ProcessType.Inner =>
source match {
case obj: ScObject =>
val clazz = obj.fakeCompanionClassOrCompanionClass.asInstanceOf[ScClass]
val className = clazz.getName
// support constructor and second constructor
val nameAndTypes = getConstructorParameters(clazz.asInstanceOf[ScClass])
val genericType = getTypeParamString(clazz)
val returnGenericType = getTypeParamString(clazz, returnType = true)
val assignMethods = nameAndTypes.map(term =>
s"def ${term._1}(${term._1}: ${term._2}) = this"
)
Seq(
s"""
|class ${genBuilderName(className)}$genericType {
| def build(): $className$returnGenericType = ???
| ${assignMethods.mkString("\n")}
|}
|""".stripMargin
)
case _ => Nil
}
case _ => Nil
}
}
/**
* Gen class builder name
*
* @param className base class name
* @param returnType if function or field return type
*/
private def genBuilderName(className: String, returnType: Boolean = false): String = {
if (returnType) {
s"$className.$className$builderClassNameSuffix"
} else {
s"$className$builderClassNameSuffix"
}
}
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.ScalaMacroNames
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.jetbrains.plugins.scala.lang.psi.api.expr.ScMethodCall
import org.jetbrains.plugins.scala.lang.psi.api.statements.ScVariableDefinition
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScTypeDefinition }
import org.jetbrains.plugins.scala.lang.psi.types.ScLiteralType
/**
* Desc: Processor for annotation constructor
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/8
*/
class ConstructorProcessor extends AbsProcessor {
private val excludeFieldsName = "excludeFields"
override def needCompanion: Boolean = true
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
case ProcessType.Method =>
source match {
case clazz: ScClass =>
val consFields = getConstructorParameters(clazz, withSecond = false)
val excludeFields = clazz.annotations(ScalaMacroNames.CONSTRUCTOR).lastOption match {
case Some(an) =>
// get excludeFields function call
an.getParameterList.getAttributes.findLast(_.getAttributeName == excludeFieldsName).map(_.getDetachedValue)
.collect {
case call: ScMethodCall =>
// get call parameters
call.argumentExpressions.flatMap(_.`type`().toOption)
.collect {
case str: ScLiteralType => str.value.value.toString
}
.mkString(", ")
}.getOrElse("")
case None => ""
}
val varFields = clazz.extendsBlock.members
.collect {
// var, others: ScPatternDefinition, ScFunctionDefinition
case `var`: ScVariableDefinition => `var`
}
.flatMap { v =>
v.declaredNames.map(n => (n, v.`type`().toOption.map(_.toString).getOrElse("Unit")))
}
.filter(v => !excludeFields.contains(v._1))
val consFieldsStr = consFields.map(_._1).mkString(", ")
val allFieldsStr = (consFields ++ varFields).map(f => s"${f._1}: ${f._2}").mkString(", ")
Seq(s"def this($allFieldsStr) = this($consFieldsStr)")
case _ => Nil
}
case _ => Nil
}
}
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScTypeDefinition }
/**
* Desc: Processor for annotation equalsAndHashCode
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/22
*/
class EqualsAndHashCodeProcessor extends AbsProcessor {
override def needCompanion: Boolean = true
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
case ProcessType.Method =>
source match {
case _: ScClass =>
Seq(s"def canEqual(that: Any): Boolean = ???")
case _ => Nil
}
case _ => Nil
}
}
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScObject, ScTypeDefinition }
/**
* Desc: Processor for annotation json
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/7
*/
class JsonProcessor extends AbsProcessor {
override def needCompanion: Boolean = true
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
case ProcessType.Field =>
source match {
case obj: ScObject =>
val clazz = obj.fakeCompanionClassOrCompanionClass
Seq(s"implicit val jsonAnnotationFormat = play.api.libs.json.Json.format[${clazz.getName}]")
case _ => Nil
}
case _ => Nil
}
}
}
package org.bitlap.tools.plugin.processor.clazz
import org.bitlap.tools.plugin.ScalaMacroNames
import org.bitlap.tools.plugin.processor.ProcessType.ProcessType
import org.bitlap.tools.plugin.processor.{ AbsProcessor, ProcessType }
import org.jetbrains.plugins.scala.lang.psi.api.toplevel.typedef.{ ScClass, ScObject, ScTypeDefinition }
/**
* Desc: Processor for annotation log
*
* Mail: chk19940609@gmail.com
* Created by IceMimosa
* Date: 2021/7/6
*/
class LogProcessor extends AbsProcessor {
// default log expr
private def logExpr(log: String = "java.util.logging.Logger") = s"private final val log: $log = ???"
override def process(source: ScTypeDefinition, typ: ProcessType): Seq[String] = {
typ match {
case ProcessType.Field =>
source match {
case clazz @ (_: ScClass | _: ScObject) =>
clazz.annotations(ScalaMacroNames.LOG).lastOption.fold[Seq[String]](Nil) { an =>
{
an.annotationExpr.getText match {
case expr if expr.contains("Slf4j") => Seq(logExpr("org.slf4j.Logger"))
case expr if expr.contains("Log4j2") => Seq(logExpr("org.apache.logging.log4j.Logger"))
case _ => Seq(logExpr())
}
}
}
case _ => Nil
}
case _ => Nil
}
}
}
sbt.version = 1.6.1
\ No newline at end of file
sbt.version = 1.6.0
\ No newline at end of file
......@@ -2,8 +2,6 @@ addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.13")
addSbtPlugin("org.jetbrains" % "sbt-ide-settings" % "1.1.0")
addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.13.5")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.6.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.2")
addSbtPlugin("org.jmotor.sbt" % "sbt-protoc" % "1.0.19")
\ No newline at end of file
......@@ -27,7 +27,7 @@ import scala.reflect.macros.whitebox
trait BaseLog {
val typ: LogType
val `type`: LogType
def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree
}
......@@ -27,7 +27,7 @@ import scala.reflect.macros.whitebox
object JLogImpl extends BaseLog {
override val typ: LogType = LogType.JLog
override val `type`: LogType = LogType.JLog
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
import c.universe._
......
......@@ -27,7 +27,7 @@ import scala.reflect.macros.whitebox
object Log4J2Impl extends BaseLog {
override val typ: LogType = LogType.Log4j2
override val `type`: LogType = LogType.Log4j2
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
import c.universe._
......
......@@ -29,12 +29,12 @@ object LogType extends Enumeration {
type LogType = Value
val JLog, Log4j2, Slf4j, ScalaLoggingLazy, ScalaLoggingStrict = Value
private lazy val types = Map(
JLog -> JLogImpl,
Log4j2 -> Log4J2Impl,
Slf4j -> Slf4jImpl,
ScalaLoggingStrict -> ScalaLoggingStrictImpl,
ScalaLoggingLazy -> ScalaLoggingLazyImpl
private lazy val types: Map[LogType, BaseLog] = Map(
JLogImpl.`type` -> JLogImpl,
Log4J2Impl.`type` -> Log4J2Impl,
Slf4jImpl.`type` -> Slf4jImpl,
ScalaLoggingStrictImpl.`type` -> ScalaLoggingStrictImpl,
ScalaLoggingLazyImpl.`type` -> ScalaLoggingLazyImpl
)
def getLogImpl(logType: LogType): BaseLog = {
......
......@@ -27,7 +27,7 @@ import scala.reflect.macros.whitebox
object Slf4jImpl extends BaseLog {
override val typ: LogType = LogType.Slf4j
override val `type`: LogType = LogType.Slf4j
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
import c.universe._
......
......@@ -35,7 +35,7 @@ import scala.reflect.macros.whitebox
*/
object ScalaLoggingLazyImpl extends BaseLog {
override val typ: LogType = LogType.ScalaLoggingLazy
override val `type`: LogType = LogType.ScalaLoggingLazy
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
import c.universe._
......
......@@ -35,7 +35,7 @@ import scala.reflect.macros.whitebox
*/
object ScalaLoggingStrictImpl extends BaseLog {
override val typ: LogType = LogType.ScalaLoggingStrict
override val `type`: LogType = LogType.ScalaLoggingStrict
override def getTemplate(c: whitebox.Context)(logTransferArgument: LogTransferArgument): c.Tree = {
import c.universe._
......
......@@ -28,5 +28,5 @@ package org.bitlap
* @version 1.0
*/
package object tools {
final val PACKAGE = "org.bitlap.tools"
final val PACKAGE: String = "org.bitlap.tools"
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册