Questions tagged [scalameta]

For meta programming in Scala using the Scalameta library

This tag is for questions relating to the Scalameta library for Scala.

66 questions
13
votes
3 answers

Scala tool to remove all unused code

I am writing a Scala plugin for an editor I use that would highlight all unused code paths (could be unused defs, vals, classes and implicits), and give the user an option to yank them out of the .scala file. How can I do this? To simplify the…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
10
votes
1 answer

Use Scala macros to generate methods

I want to generate aliases of methods using annotation macros in Scala 2.11+. I am not even sure that is even possible. If yes, how? Example - Given this below, I want the annotation macros to expand into class Socket { @alias(aliases = Seq("!",…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
7
votes
1 answer

Difference Between Scala Expressions

Up until recently it was my understanding that two Scala statements below were interchangeable. expr.op(arg1, arg2,...) expr op (arg1, arg2,...) But I've playing around with scala meta, looked at the resulting AST they…
Sledge
  • 178
  • 13
6
votes
1 answer

new-style ("inline") macros require scala.meta

I just updated to scala meta 2.0.0-M1 and with the latest scala 2.12.3 and now macros no longer compile. The only change i made was to change the meta version from 1.8.0 to 2.0.0-M1. ERROR: new-style ("inline") macros require scala.meta Does anybody…
Will
  • 151
  • 4
6
votes
1 answer

Scala recursive macro?

I was wondering whether Scala supports recursive macro expansion e.g. I am trying to write a lens library with a lensing macro that does this: case class C(d: Int) case class B(c: C) case class A(b: B) val a = A(B(C(10)) val aa = lens(a)(_.b.c.d)(_…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
5
votes
1 answer

automatically generate case object for case class

How can I have the scala compiler automatically generate the case object? // Pizza class class Pizza (val crust_type: String) // companion object object Pizza { val crustType = "crust_type" } Desired properties for case object for each…
Georg Heiler
  • 16,916
  • 36
  • 162
  • 292
5
votes
1 answer

Scala Macro: Create new classes with Option types

I want to write a macro given this: @MetaRest case class User( @get id : Int, @get @post @patch name : String, @get @post email : String, registeredOn :…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
3
votes
0 answers

Relationship between ScalaMeta, ScalaFix, and SemanticDB

I have the following information: Scalameta: has the ability to produce ASTs from a source file SemanticDB: Contains information about symbols from a parsed source file ScalaFix: is based on ScalaMeta and SemanticDB so it has the ability to access…
Gakuo
  • 845
  • 6
  • 26
3
votes
1 answer

Code generated with scalameta is not recognized by intellij

I'm trying to create a scalameta annotation, that will define a new case class inside of an existing object. my goal is to transform: object MyObj { case class A() } into: object MyObj { case class A() case class B(b: Int, bb: Int) } for…
lev
  • 3,986
  • 4
  • 33
  • 46
3
votes
0 answers

How to run the Defn generated by the scalameta

I am playing with Scalameta. this is my build.sbt lazy val commonSettings = Seq( scalaVersion := "2.12.3" ) lazy val macroProject = (project in file("MacroProject")).settings( commonSettings, name := "MacroProject", libraryDependencies…
Knows Not Much
  • 30,395
  • 60
  • 197
  • 373
3
votes
1 answer

Using code generation (like Scala Meta) to scrape boilerplate

I use Shapeless's tagged types to get nice typesafe primitives to pass through my business logic. Defining these types started with a simple: sealed trait MyTaggedStringTag type MyTaggedString = String @@ MyTaggedStringTag But I've added a good bit…
acjay
  • 34,571
  • 6
  • 57
  • 100
3
votes
1 answer

Scalameta Decl.Def not works on a trait def method

I'm use Scalameta(v1.8.0) annotation to a def declaration: trait MyTrait { @MyDeclDef def f2(): Int } The annotation class defined just return input, as this: import scala.meta._ class MyDeclDef extends scala.annotation.StaticAnnotation { …
LoranceChen
  • 2,453
  • 2
  • 22
  • 48
3
votes
1 answer

Scalameta: Identify particular annotations

I want to auto-generate REST API models in Scala using scalameta annotation macros. Specifically, given: @Resource case class User( @get id : Int, @get @post @patch name : String, @get @post email :…
pathikrit
  • 32,469
  • 37
  • 142
  • 221
2
votes
1 answer

Scalafix: resolving object apply method

I have an object with some apply method defined and then use it object Ob { def apply(i: Int) = () def apply(s: String) = () } object Use { def someMethod(i: Int) = () Ob(1) someMethod(1) } When using scalafix/scalameta, I'm unable to…
Jacob Wang
  • 4,411
  • 5
  • 29
  • 43
2
votes
2 answers

Scala conditional compilation

I'm writing a Scala program and I want it to work with two version of a big library. This big library's version 2 changes the API very slightly (only one class constructor signature has an extra parameter). // Lib v1 class APIClass(a: String,…
sscarduzio
  • 5,938
  • 5
  • 42
  • 54
1
2 3 4 5