scalajs-reflection


License

License

Categories

Categories

JavaScript Languages Scala
GroupId

GroupId

be.doeraene
ArtifactId

ArtifactId

scalajs-reflection_sjs0.6_2.11
Last Version

Last Version

0.1.1
Release Date

Release Date

Type

Type

jar
Description

Description

scalajs-reflection
scalajs-reflection
Project URL

Project URL

https://github.com/sjrd/scalajs-reflect
Project Organization

Project Organization

be.doeraene
Source Code Management

Source Code Management

https://github.com/sjrd/scalajs-reflect

Download scalajs-reflection_sjs0.6_2.11

How to add to project

<!-- https://jarcasting.com/artifacts/be.doeraene/scalajs-reflection_sjs0.6_2.11/ -->
<dependency>
    <groupId>be.doeraene</groupId>
    <artifactId>scalajs-reflection_sjs0.6_2.11</artifactId>
    <version>0.1.1</version>
</dependency>
// https://jarcasting.com/artifacts/be.doeraene/scalajs-reflection_sjs0.6_2.11/
implementation 'be.doeraene:scalajs-reflection_sjs0.6_2.11:0.1.1'
// https://jarcasting.com/artifacts/be.doeraene/scalajs-reflection_sjs0.6_2.11/
implementation ("be.doeraene:scalajs-reflection_sjs0.6_2.11:0.1.1")
'be.doeraene:scalajs-reflection_sjs0.6_2.11:jar:0.1.1'
<dependency org="be.doeraene" name="scalajs-reflection_sjs0.6_2.11" rev="0.1.1">
  <artifact name="scalajs-reflection_sjs0.6_2.11" type="jar" />
</dependency>
@Grapes(
@Grab(group='be.doeraene', module='scalajs-reflection_sjs0.6_2.11', version='0.1.1')
)
libraryDependencies += "be.doeraene" % "scalajs-reflection_sjs0.6_2.11" % "0.1.1"
[be.doeraene/scalajs-reflection_sjs0.6_2.11 "0.1.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.11.7
org.scala-js : scalajs-library_2.11 jar 0.6.6

test (1)

Group / Artifact Type Version
org.scala-js : scalajs-junit-test-runtime_2.11 jar 0.6.6

Project Modules

There are no modules declared in this project.

scalajs-reflection

Build Status Scala.js

scalajs-reflection is a combination of an sbt plugin and a run-time API enabling a controlled amount of run-time reflection in Scala.js projects.

Usage

Add the following line to your project/plugins.sbt file:

addSbtPlugin("be.doeraene" % "sbt-scalajs-reflection" % "0.1.1")

and the following settings to your build.sbt file:

enablePlugins(ScalaJSReflectionPlugin)

libraryDependencies += "be.doeraene" %%% "scalajs-reflection" % "0.1.1"

In addition, you need to specify what classes will be reflectible, and what reflective operations will be enabled on them. To do so, use the scalaJSReflectSelectors setting. For example, to enable Reflect.getClassForName on all subclasses of some class or trait foo.Bar, use:

scalaJSReflectSelectors ++= Seq(
  selectDescendentClasses("foo.Bar") -> reflectClassByName()
)

Each element of the Seq must be a pair of an entity selector and a reflective operation. The operation will be enabled on all classes matched by the entity selector.

Available selectors are:

  • selectSingleClass("foo.Bar"): select exclusively foo.Bar
  • selectDescendentClasses("foo.Bar"): select foo.Bar and all its descendants

Note that, to select the class of a Scala object, you need to append a $ at the end of its full name, e.g., "foo.Bar$".

Available operations are:

  • reflectClassByName(): enables Reflect.getClassForName
  • reflectEnumerateClass() enables Reflect.enumerateClasses
  • reflectDeclaredConstructors(): enables Reflect.getDeclaredConstructors
  • reflectModuleAccessor(): enables Reflect.loadModule

API

  • be.doeraene.sjsreflect.Reflect
    • Reflect.getClassForName(fqcn: String): Class[_]: find a class by its name
    • Reflect.enumerateClasses: Array[Class[_]]: an array of the specified classes
    • Reflect.getDeclaredConstructors[T](clazz: Class[T]): Array[Constructor[T]]: lists the declared constructors of the given class
    • Reflect.loadModule[T](clazz: Class[T]): T: loads the module instance of the given module class (a Scala object)
  • be.doeraene.sjsreflect.Constructor[T]
    • ctor.getParameterTypes(): Array[Class[_]]: returns the list of the parameter types of the constructor
    • ctor.newInstance(actualArgs: Any*): T: invokes the constructor with the given arguments, and returns the created instance

Versions

Version
0.1.1
0.1.0