The list of all available flags is defined in Type aliases, abstract type members and type parameters.įor example, to create a class named C one would write something like:ĬlassDef(Modifiers(PRIVATE | FINAL), TypeName("C"), Nil. Vals, vars, parameters, and self type annotations. Flags and flag setsįlags are used to provide modifiers for abstract syntax trees that representĭefinitions via the flags field of #Modifiers. Exprs are mainly used to simply and conveniently create typedĪbstract syntax trees for use in a macro. Syntax trees, typed trees can also be represented as instances of typeĪn abstract syntax tree and an internal type tag to provide access to the type In addition to type #Tree, the base type of abstract Scala> val finals = (_.isFinal)įinals: List(method isEmpty, method map, method collect, method flatMap, method takeWhile, method span, method foreach, method reverse, method foldRight, method length, method lengthCompare, method forall, method exists, method contains, method find, method mapConserve, method toList) The following example returns a list of the symbols of all final members Supports the sorted method, which sorts members in declaration order. The base type exposed in the reflectionĪPI, however, only exposes a minimal interface, representing a scope as anĪdditional functionality is exposed in member scopes that are returned by For a complete specification of all standard names, see theĪ scope object generally maps names to symbols available in a corresponding Standard names are made available through the termNames and typeNames members ofĬlass Universe. Some names, such as “package”, exist both as a type name and a term name. standard term names, e.g., “ ”, “ package”, and “ _root_”, and.Standard name, the term name which represents the Such they are essential for reflectively accessing certain Scala constructs.įor example, reflectively invoking a constructor requires using the To search for a type member, one can follow the same procedure, usingĬertain names, such as “ _root_”, have special meanings in Scala programs. Types and terms have separate name spaces. A termĪnd a type of the same name can co-exist in the same object. Objects or members) and types (like classes, traits, and type members). Has two subtypes TermName and TypeName which distinguish names of terms (like literals (primitive and string constants),.Represent different kinds of Java annotation arguments: JavaArgs are represented as a map from #Name to Note that these treesĪre not transformed by any phases following the type-checker. For all other Scala annotations, theĪrguments are stored in scalaArgs and javaArgs is empty.Īrguments in scalaArgs are represented as typed trees. The distinction between Java and Scala annotations is manifested in theĬontract of #Annotation, which exposes both Scala annotations: annotations on definitions or types produced by the Scala compiler.When read by Scala reflection, the trait is automatically added as a subclass to every Java annotation. Java annotations: annotations on definitions produced by the Java compiler, i.e., subtypes of attached to program definitions.The API distinguishes between two kinds of annotations: does not make your annotation visibleĪs a Java annotation at runtime that requires writing the annotation class is not enough to have the corresponding metadata As a result, instances of theĪnnotation type are stored as special attributes in the corresponding A custom annotation type can be made persistent by Have been persisted, so that they can be read from the classfile containing It’s possible to work with annotations produced by aĪnnotations can be inspected reflectively if the corresponding annotations In Scala, declarations can be annotated using subtypes of Which have either been removed in Scala 3 or replaced by an alternative. Don’t forget to clap a few times if this was useful.This doc page is specific to features shipped in Scala 2, Please feel free to contact me if there are any problems. Class classElement = FunctionOperation.class Parameter parameter = classElement.getAnnotation(Parameter.class) String name = parameter.name() String type = parameter.type() Therefore you need to access the annotation the same way you did for non-repeatable annotations. If this is the case if you access the container annotation you will get null. Therefore to make sure that the annotations are stored in the class files and that they are loaded into the JVM at run-time, the RetentionPolicy.RUNTIME) annotation needs to be applied to the declaration of the annotation that you wish to read at compile time. For us to use the reflections API to read annotations, the annotations should be stored in the class files by the compiler and loaded into the JVM at run-time.Īnnotations by default are retained in the class files but they are not loaded into the JVM at run-time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |