diff --git a/build.sbt b/build.sbt index f67d8f3897226195912bffc43af72a64e1d1c404..d80a1b4b1b25b78cbf2a8f4acead9ec54500df4e 100644 --- a/build.sbt +++ b/build.sbt @@ -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 diff --git a/intellij-plugin/build.sbt b/intellij-plugin/build.sbt deleted file mode 100644 index 5f31e95cce4bca9bb5eb5ce4405165ab33ceed58..0000000000000000000000000000000000000000 --- a/intellij-plugin/build.sbt +++ /dev/null @@ -1,32 +0,0 @@ -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, - ) diff --git a/intellij-plugin/project/build.properties b/intellij-plugin/project/build.properties deleted file mode 100644 index 50fd0c733c3563ea3a2153b4ef6ec04a43cacd51..0000000000000000000000000000000000000000 --- a/intellij-plugin/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version = 1.6.1 \ No newline at end of file diff --git a/intellij-plugin/project/plugins.sbt b/intellij-plugin/project/plugins.sbt deleted file mode 100644 index 59c96ac0f2721c3ddc9a12d299d0e1953456f166..0000000000000000000000000000000000000000 --- a/intellij-plugin/project/plugins.sbt +++ /dev/null @@ -1,2 +0,0 @@ -addSbtPlugin("org.jetbrains" % "sbt-ide-settings" % "1.1.0") -addSbtPlugin("org.jetbrains" % "sbt-idea-plugin" % "3.13.5") \ No newline at end of file diff --git a/intellij-plugin/src/main/resources/META-INF/plugin.xml b/intellij-plugin/src/main/resources/META-INF/plugin.xml deleted file mode 100644 index d723582c5cbf892a09d0c6a0a4a859451d4188cb..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/resources/META-INF/plugin.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - Scala-Macro-Tools Plugin - Scala-Macro-Tools - XXX - Scala Macro Tools - - - com.intellij.modules.platform - com.intellij.modules.lang - com.intellij.modules.java - org.intellij.scala - com.intellij.properties - - - - - messages.PluginBundle - - - - - - - - - - - - diff --git a/intellij-plugin/src/main/resources/META-INF/pluginIcon.png b/intellij-plugin/src/main/resources/META-INF/pluginIcon.png deleted file mode 100644 index 29f9ed740f0c1e1badd5bdff988edf585aca456b..0000000000000000000000000000000000000000 Binary files a/intellij-plugin/src/main/resources/META-INF/pluginIcon.png and /dev/null differ diff --git a/intellij-plugin/src/main/resources/META-INF/pluginIcon.svg b/intellij-plugin/src/main/resources/META-INF/pluginIcon.svg deleted file mode 100644 index 461cef5e503c9a511211427153a6d8dd578aec0a..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/resources/META-INF/pluginIcon.svg +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - @ \ No newline at end of file diff --git a/intellij-plugin/src/main/resources/messages/PluginBundle.properties b/intellij-plugin/src/main/resources/messages/PluginBundle.properties deleted file mode 100644 index 1322c1baa2b1faab2646cb827e874d0d03ff448e..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/resources/messages/PluginBundle.properties +++ /dev/null @@ -1,20 +0,0 @@ -### 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 diff --git a/intellij-plugin/src/main/resources/patch/change.html b/intellij-plugin/src/main/resources/patch/change.html deleted file mode 100644 index cddb3a5ca2aa5738663914d28be67fb0803711f8..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/resources/patch/change.html +++ /dev/null @@ -1,23 +0,0 @@ - 0.3.4: -
    -
  1. transfer to bitlap.org
  2. -
- - - - -]]> \ No newline at end of file diff --git a/intellij-plugin/src/main/resources/patch/description.html b/intellij-plugin/src/main/resources/patch/description.html deleted file mode 100644 index a6c927149ffb0f21e10b1602ae42338056bda2b4..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/resources/patch/description.html +++ /dev/null @@ -1,22 +0,0 @@ -Scala Macro Tools plugin for IntelliJ IDEA -
-GitHub | -Issues -
-
-A plugin that implements Lombok-like functionality with Scala macros -
-
-Features - -
-]]> \ No newline at end of file diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/PluginBundle.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/PluginBundle.scala deleted file mode 100644 index 740cfe459173030d762c16a6349c68565c434357..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/PluginBundle.scala +++ /dev/null @@ -1,19 +0,0 @@ -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) - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroInjector.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroInjector.scala deleted file mode 100644 index 4e0b7ac6b6311032652c82c5fdbbac20a6786822..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroInjector.scala +++ /dev/null @@ -1,36 +0,0 @@ -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 diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroNames.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroNames.scala deleted file mode 100644 index a4f47b9569516c9a7f28acc98a46904dd9c9b3b2..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroNames.scala +++ /dev/null @@ -1,17 +0,0 @@ -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" -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroProcessorProvider.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroProcessorProvider.scala deleted file mode 100644 index a8f4b3ce52c07557ab699e6a3854a90a16b1d265..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/ScalaMacroProcessorProvider.scala +++ /dev/null @@ -1,43 +0,0 @@ -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 - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/AbsProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/AbsProcessor.scala deleted file mode 100644 index de3789581f4e9285def223f841b02a2895d63ba9..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/AbsProcessor.scala +++ /dev/null @@ -1,71 +0,0 @@ -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("[", ", ", "]") - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/ProcessType.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/ProcessType.scala deleted file mode 100644 index baa00602886a2ce67fbf469001026b0b967cad0f..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/ProcessType.scala +++ /dev/null @@ -1,11 +0,0 @@ -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 -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/Processor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/Processor.scala deleted file mode 100644 index be0fe9e844c40eae1e75179f46b5f43f229d8c0c..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/Processor.scala +++ /dev/null @@ -1,24 +0,0 @@ -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] -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ApplyProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ApplyProcessor.scala deleted file mode 100644 index 0deef92df0a08be1f0a5f72575d8c24bcc0f08dc..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ApplyProcessor.scala +++ /dev/null @@ -1,35 +0,0 @@ -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 - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/BuilderProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/BuilderProcessor.scala deleted file mode 100644 index ad816ef359b74d64f3f56d043b6d0a64ba4c8d04..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/BuilderProcessor.scala +++ /dev/null @@ -1,76 +0,0 @@ -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" - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ConstructorProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ConstructorProcessor.scala deleted file mode 100644 index 9e37bc2ba035b215922d1ce4d45a47db117b390f..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/ConstructorProcessor.scala +++ /dev/null @@ -1,64 +0,0 @@ -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 - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/EqualsAndHashCodeProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/EqualsAndHashCodeProcessor.scala deleted file mode 100644 index 009337e0e8d7d77b88a6d5fb4194a54255464b76..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/EqualsAndHashCodeProcessor.scala +++ /dev/null @@ -1,29 +0,0 @@ -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 - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/JsonProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/JsonProcessor.scala deleted file mode 100644 index e4c88d6a5fbdb0f6f505d3fa5cde984b035e7282..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/JsonProcessor.scala +++ /dev/null @@ -1,30 +0,0 @@ -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 - } - } -} diff --git a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/LogProcessor.scala b/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/LogProcessor.scala deleted file mode 100644 index be8d7770ab995e73775c69d4757e9c104c107f12..0000000000000000000000000000000000000000 --- a/intellij-plugin/src/main/scala/org/bitlap/tools/plugin/processor/clazz/LogProcessor.scala +++ /dev/null @@ -1,39 +0,0 @@ -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 - } - } -} diff --git a/project/build.properties b/project/build.properties index 50fd0c733c3563ea3a2153b4ef6ec04a43cacd51..4593c179246aae715011c619586e6d7428b7d047 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version = 1.6.1 \ No newline at end of file +sbt.version = 1.6.0 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 794f745aec582f01cb8f7c63ac21f905e2d31580..4c37a171a46f1f30772de4eeff8625b15a9638be 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -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 diff --git a/src/main/scala/org/bitlap/tools/logs/BaseLog.scala b/src/main/scala/org/bitlap/tools/logs/BaseLog.scala index 81989a06d5db612e77a28570cc2eae0d3649778b..2b98bda62f34688307a532649a38f20085d68151 100644 --- a/src/main/scala/org/bitlap/tools/logs/BaseLog.scala +++ b/src/main/scala/org/bitlap/tools/logs/BaseLog.scala @@ -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 } diff --git a/src/main/scala/org/bitlap/tools/logs/JLogImpl.scala b/src/main/scala/org/bitlap/tools/logs/JLogImpl.scala index e8b7dae7841c9c2c7cd93751e86d9b5776d850ea..2bf60458020c6568c97fd3015f7ce6f2bce06662 100644 --- a/src/main/scala/org/bitlap/tools/logs/JLogImpl.scala +++ b/src/main/scala/org/bitlap/tools/logs/JLogImpl.scala @@ -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._ diff --git a/src/main/scala/org/bitlap/tools/logs/Log4J2Impl.scala b/src/main/scala/org/bitlap/tools/logs/Log4J2Impl.scala index 5e7d6f2f0d47460d5518b92398d5931a77a54e51..28c91f3eae2c742ff5546e4bac899700f6ad3bc7 100644 --- a/src/main/scala/org/bitlap/tools/logs/Log4J2Impl.scala +++ b/src/main/scala/org/bitlap/tools/logs/Log4J2Impl.scala @@ -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._ diff --git a/src/main/scala/org/bitlap/tools/logs/LogType.scala b/src/main/scala/org/bitlap/tools/logs/LogType.scala index 7bf0ac2b6baeeef95ac4d11fa7efa8bcef06bb1b..55b6baca383331c0f5bf29297d1ae6331464503d 100644 --- a/src/main/scala/org/bitlap/tools/logs/LogType.scala +++ b/src/main/scala/org/bitlap/tools/logs/LogType.scala @@ -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 = { diff --git a/src/main/scala/org/bitlap/tools/logs/Slf4jImpl.scala b/src/main/scala/org/bitlap/tools/logs/Slf4jImpl.scala index 2eef922b8779d5999a07a6eb47bdbcc1696ce605..8c966165f7182e7b3311b1fbe9c10623c2e37dc0 100644 --- a/src/main/scala/org/bitlap/tools/logs/Slf4jImpl.scala +++ b/src/main/scala/org/bitlap/tools/logs/Slf4jImpl.scala @@ -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._ diff --git a/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingLazyImpl.scala b/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingLazyImpl.scala index b9d05fd82bdb073919ed2cd395d6e513a43bb622..c359607c5dbe266e02986665453133e69ba0dafb 100644 --- a/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingLazyImpl.scala +++ b/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingLazyImpl.scala @@ -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._ diff --git a/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingStrictImpl.scala b/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingStrictImpl.scala index 9235214a9eb0886b52994b63f3d05922fd9a12e3..3a944184ad35ed08e873dd7b427b01a8e8a66ec9 100644 --- a/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingStrictImpl.scala +++ b/src/main/scala/org/bitlap/tools/logs/extension/ScalaLoggingStrictImpl.scala @@ -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._ diff --git a/src/main/scala/org/bitlap/tools/package.scala b/src/main/scala/org/bitlap/tools/package.scala index b970f029982ab01cbc609a28bae4128fdc56fff8..8551133b6780cfb00ce839c64e330b121d4bf5c3 100644 --- a/src/main/scala/org/bitlap/tools/package.scala +++ b/src/main/scala/org/bitlap/tools/package.scala @@ -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" }