package scala.tools
package reflect
import java.lang.reflect.{ GenericSignatureFormatError, Method }
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 { }