|
Scala example source code file (AnnotationInfos.scala)
The Scala AnnotationInfos.scala source code
/* NSC -- new Scala compiler
* Copyright 2007-2011 LAMP/EPFL
* @author Martin Odersky
*/
package scala.tools.nsc
package symtab
import scala.tools.nsc.transform.Reifiers
import util._
/** AnnotationInfo and its helpers */
trait AnnotationInfos extends reflect.generic.AnnotationInfos { self: SymbolTable =>
/** Arguments to classfile annotations (which are written to
* bytecode as java annotations) are either:
* <ul>
* <li>constants
* <li>arrays of constants
* <li>or nested classfile annotations
* </ul>
*/
abstract class ClassfileAnnotArg
/** Represents a compile-time Constant (Boolean, Byte, Short,
* Char, Int, Long, Float, Double, String, java.lang.Class or
* an instance of a Java enumeration value).
*/
case class LiteralAnnotArg(const: Constant)
extends ClassfileAnnotArg {
override def toString = const.escapedStringValue
}
object LiteralAnnotArg extends LiteralAnnotArgExtractor
/** Represents an array of classfile annotation arguments */
case class ArrayAnnotArg(args: Array[ClassfileAnnotArg])
extends ClassfileAnnotArg {
override def toString = args.mkString("[", ", ", "]")
}
object ArrayAnnotArg extends ArrayAnnotArgExtractor
/** A specific annotation argument that encodes an array of bytes as an array of `Long`. The type of the argument
* declared in the annotation must be `String`. This specialised class is used to encode scala signatures for
* reasons of efficiency, both in term of class-file size and in term of compiler performance. */
case class ScalaSigBytes(bytes: Array[Byte]) extends ClassfileAnnotArg {
override def toString = (bytes map { byte => (byte & 0xff).toHexString }).mkString("[ ", " ", " ]")
lazy val encodedBytes =
reflect.generic.ByteCodecs.encode(bytes)
def isLong: Boolean = (encodedBytes.length > 65535)
def sigAnnot: Type =
if (this.isLong)
definitions.ScalaLongSignatureAnnotation.tpe
else
definitions.ScalaSignatureAnnotation.tpe
}
/** Represents a nested classfile annotation */
case class NestedAnnotArg(annInfo: AnnotationInfo)
extends ClassfileAnnotArg {
// The nested annotation should not have any Scala annotation arguments
assert(annInfo.args.isEmpty, annInfo.args)
override def toString = annInfo.toString
}
object NestedAnnotArg extends NestedAnnotArgExtractor
class AnnotationInfoBase
/** <p>
* Typed information about an annotation. It can be attached to
* either a symbol or an annotated type.
* </p>
* <p>
* Annotations are written to the classfile as java annotations
* if <code>atp conforms to
Other Scala examples (source code examples)Here is a short list of links related to this Scala AnnotationInfos.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.