|
Scala example source code file (SigParser.scala)
The Scala SigParser.scala source code/* NSC -- new Scala compiler * Copyright 2005-2011 LAMP/EPFL * @author Paul Phillips */ package scala.tools package reflect import java.lang.reflect.{ GenericSignatureFormatError, Method } /** The usual reflection song and dance to avoid referencing * any sun.* classes. */ class SigParser { val SunSignatureParser = "sun.reflect.generics.parser.SignatureParser" private lazy val makeMethod: Method = try Class.forName(SunSignatureParser) getMethod "make" catch { case t => null } def make() = makeMethod.invoke(null).asInstanceOf[SignatureParserInterface] private def wrap(op: => Any) = try { op ; true } catch { case _: GenericSignatureFormatError => false } def isParserAvailable = makeMethod != null def verifyClass(s: String) = isParserAvailable && wrap(make() parseClassSig s) def verifyMethod(s: String) = isParserAvailable && wrap(make() parseMethodSig s) def verifyType(s: String) = isParserAvailable && wrap(make() parseTypeSig s) type ClassSignature <: AnyRef type MethodTypeSignature <: AnyRef type TypeSignature <: AnyRef type SignatureParserInterface = { def isParserAvailable: Boolean def parseClassSig(s: String): ClassSignature def parseMethodSig(s: String): MethodTypeSignature def parseTypeSig(s: String): TypeSignature } } object SigParser extends SigParser { } Other Scala examples (source code examples)Here is a short list of links related to this Scala SigParser.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 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.