MethodSymbol but while reading the documentation,
I was not really able to understand how to apply it to my case of traversing the AST
to match for a particular method name.
Any advice?
Thank you for any help
m
--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
val excSymb = typeOf[scala.type].member(newTermName("Exception")).allOverriddenSymbols
throws a type mismatch error:[error] found : scala.type [error] required: AnyRef [error] Note that scala extends Any, not AnyRef. [error] Such types can participate in value classes, but instances [error] cannot appear in singleton types or in reference comparisons.
Accessing it through the context gives even more errors.
I've googled around but wasn't able to figure out how to get a list of
all overriden symbols forException.
Any advice?
Thank you
You received this message because you are subscribed to a topic in the Google Groups "scala-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-user/o0gm-KM-Wu0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to scala-user+...@googlegroups.com.
Sure, just wanted to suggest that to you. You can take a symbol, figure out its baseClasses and then check whether the result contains the symbol of Exception.On 23 June 2013 06:36, Marvin Hansen <marvin...@gmail.com> wrote:That's very interesting.Thank you for the important detail, I just realized I've asked the wrong way.
Essentially, what I was looking for was a compact way to traverse all kind of exceptions using just one pattern.
Instead of searching for each and every possible exception, I was just looking for a way to get them all.but as you say, there is no way to do that at the moment. That's okay.
So I though grabbing all subtypes of the shared supertype Exception would be a good starting point
On the other hand, can I match if a symbol contains supertype Exception?That would solve the issue the other way around, which would be equally valid.
I don't have to solve that at the moment so I thing its best to leave it for later.Thank you anyway, that was incredible useful for me.marvinOn 23 June 2013 16:21, Eugene Burmako <eugene....@epfl.ch> wrote:baseClass is supposed to return all supertypes of Exception, not all subtypes (btw there's no way of doing the latter in the reflection API):
scala> typeOf[Exception].typeSymbol.asClass.baseClasses
res0: List[reflect.runtime.universe.Symbol] = List(class Exception, class Throwable, trait Serializable, class Object, class Any)
On 23 June 2013 04:27, Marvin Hansen <marvin...@gmail.com> wrote:
Thanks for any advicedoes not return anything. Is type symbol the right path to go?Well,your right, that makes sense. However, trying to get the sub-types of excections like so:
val excSymb = typeOf[Exception].typeSymbol.asClass.baseClasses
//
expr.tree.find {
subtree => excSymb contains subtree.symbol
} match {
case Some(subtree) => c.error(subtree.pos, "Error: Exceptions are disabled" )
case None => ()
}marvin
override def traverse(tree: Tree) {case Block(statements,_) =>
tree match {
println(statements.toString()) // This confirms that branches are skipped
checkExceptions(statements)
case _ =>
}
super.traverse(tree)
}
}
NoException.traverse(expr.tree)