scala.tools.reflect.SigParser.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of org.apache.servicemix.bundles.scala-compiler
Show all versions of org.apache.servicemix.bundles.scala-compiler
This OSGi bundle wraps ${pkgArtifactId} ${pkgVersion} jar file.
/* 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 { }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy