<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Ilya's reflections</title>
	<atom:link href="http://ilyasergey.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ilyasergey.wordpress.com</link>
	<description>Why don't we look for another solution?</description>
	<lastBuildDate>Wed, 10 Jun 2009 12:27:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ilyasergey.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Ilya's reflections</title>
		<link>http://ilyasergey.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ilyasergey.wordpress.com/osd.xml" title="Ilya&#039;s reflections" />
	<atom:link rel='hub' href='http://ilyasergey.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Registering Android Dev Phone with WiFi and remote shell</title>
		<link>http://ilyasergey.wordpress.com/2009/06/10/registering-android-dev-phone-with-wifi-and-remote-shell/</link>
		<comments>http://ilyasergey.wordpress.com/2009/06/10/registering-android-dev-phone-with-wifi-and-remote-shell/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 10:08:52 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[hacks]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://ilyasergey.wordpress.com/?p=28</guid>
		<description><![CDATA[First time I switched on my Android Dev Phone I found out that first I have to register it using my existing Google account. It&#8217;s not a big deal if you have AT&#38;T SIM card with adjusted GPRS connection. The simplesе way to obtain a one is to attend Google I/O conference. But anyway, it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=28&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>First time I switched on my Android Dev Phone I found out that first I have to register it using my existing Google account. It&#8217;s not a big deal if you have AT&amp;T SIM card with adjusted GPRS connection. The simplesе way to obtain a one is to attend Google I/O conference. But anyway, it&#8217;s not my case and only I have is belgian Mobistar SIM card without any mobile internet subscription. So, there are two possible solutions for me: to go back to USA and buy AT&amp;T card or try to register this damn device by some other way.</p>
<p>As it turned out, WiFi is not turned on by default on the phone, and to switch it on there are several tricky steps to do. At first, you&#8217;d better to have some <a href="http://www.ubuntu.com/">Ubuntu Linux</a> (in my case it was version 9.04). Probably it&#8217;s possible to use other systems, but that was my case. Secondly it&#8217;s necessary to download and unzip <a href="http://developer.android.com/sdk/1.5_r2/index.html">Android SDK</a> to use management tools a little bit further. To be able to connect the phone via USB cable to PC one should create the file /etc/udev/rules.d/50-android.rules</p>
<pre class="brush: bash;">
$ sudo gedit /etc/udev/rules.d/50-android.rules
</pre>
<p>and put the following line to it:</p>
<pre class="brush: bash;">
SUBSYSTEM==&quot;usb&quot;, SYSFS{idVendor}==&quot;0bb4&quot;, MODE=&quot;0666&quot;
</pre>
<p>Then we change permissions for this file as follows:</p>
<pre class="brush: bash;">
sudo chmod a+rx /etc/udev/rules.d/50-android.rules
</pre>
<p>After extracting Android SDK archive to some directory we go to the `tools&#8217; folder and run Android debugger daemon:</p>
<pre class="brush: bash;">
./adb devices
</pre>
<p>to obtain a prompt like this</p>
<pre class="brush: bash;">
List of devices attached
HT847GZ20615	device
</pre>
<p>In my case it didn&#8217;t work from scratch (my device didn&#8217;t appear in the list), presumably, because of some problems with Ububntu 9.04, so, the solution was quite simple: to copy configuration file (not to move!). Connecting USB cable of the phone into a different port also may help.</p>
<pre class="brush: bash;">
sudo cp /etc/udev/rules.d/50-android.rules /etc/udev/rules.d/51-android.rules
</pre>
<p>After device is recognized, run remote shell from the same `tools&#8217; folder. Being connected, switch to the superuser and run Android Settings application:</p>
<pre class="brush: bash;">
$ ./adb shell
$ su
# am start -a android.intent.action.MAIN -n com.android.settings/.Settings
#
</pre>
<p>Here we are! Now you can see the screen of Settings application on your phone. It&#8217;s a deal of a couple of seconds to switch on WiFi, but in my case it wasn&#8217;t an end. the problem was that only one available wireless network demanded for web-login, so I had to login to it somehow.<br />
Quick introspection of /data/app folder of the phone filesystem let me see a Browser application. That&#8217;s possible what I need. To run a browser remotely on should run the following command:</p>
<pre class="brush: bash;">
# am start -a android.intent.action.MAIN -n com.android.browser/.BrowserActivity
</pre>
<p>After being logged into our wireless network, I&#8217;ve restarted my phone and now I was able to sign in.</p>
<p>UPD. Tried the same on Mac OS X. It&#8217;s supposed to work out of the box without any pre-configuration. Just download SDK, plug USB and have fun!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/28/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/28/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/28/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=28&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2009/06/10/registering-android-dev-phone-with-wifi-and-remote-shell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>
	</item>
		<item>
		<title>Scala plugin for IntelliJ IDEA documentation</title>
		<link>http://ilyasergey.wordpress.com/2009/02/02/scala-plugin-for-intellij-idea-documentation/</link>
		<comments>http://ilyasergey.wordpress.com/2009/02/02/scala-plugin-for-intellij-idea-documentation/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 18:51:14 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[idea]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://ilyasergey.wordpress.com/?p=25</guid>
		<description><![CDATA[Because of often misunderstandings and complaints to Scala plugin for IntelliJ IDEA (like this, for example), I&#8217;ve written exact documentation for existing features and short how-to introduction with screenshots and descriptions. All this exciting content is available at JetBrains Confluence. All comments and suggestions are highly appreciated.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=25&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Because of often misunderstandings and complaints to Scala plugin for <em>IntelliJ IDEA</em> (like <a href="http://blog.lostlake.org/index.php?/archives/90-IntelliJ-a-huge-dissapointment-for-Scala-development.html">this</a>, for example), I&#8217;ve written exact documentation for existing features and short how-to introduction with screenshots and descriptions. All this exciting content is available at <a href="http://www.jetbrains.net/confluence/display/SCA/Scala+Plugin+for+IntelliJ+IDEA">JetBrains Confluence</a>.</p>
<p>All comments and suggestions are highly appreciated.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=25&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2009/02/02/scala-plugin-for-intellij-idea-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>
	</item>
		<item>
		<title>Debugging Scala: Stepping through auxiliary classes</title>
		<link>http://ilyasergey.wordpress.com/2008/12/24/debugging-scala-stepping-through-auxiliary-classes/</link>
		<comments>http://ilyasergey.wordpress.com/2008/12/24/debugging-scala-stepping-through-auxiliary-classes/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 21:46:32 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://ilyasergey.wordpress.com/?p=14</guid>
		<description><![CDATA[Developing Groovy plugin for IntelliJ IDEA we noticed that there are a lot of cases when Groovy debugger (which is in fact, of course, Java debugger) steps in some strange classes, which customer is not aware of. The cause of this is a big amount of internal Groovy logic to perform dynamic dispatch. At the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=14&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Developing Groovy plugin for IntelliJ IDEA we noticed that there are a lot of cases when Groovy debugger (which is in fact, of course, Java debugger) steps in some strange classes, which customer is not aware of. The cause of this is a big amount of internal Groovy logic to perform dynamic dispatch.</p>
<p>At the same time we have such issue for Scala also, but almost all of auxiliary classes (like FunctionN, Iterable etc) in Scala may be used directly, so it would be naive to exclude them form debug process. Say, I&#8217;ve implemented my own Function2X inherited form scala.Function2 and I actually want to debug it during execution.</p>
<p>That&#8217;s why for next release of Scala plugin for IntelliJ we added one checkbox to debugger settings for Scala.</p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-19" title="Scala debugger options" src="http://ilyasergey.files.wordpress.com/2008/12/scala-debug22.png?w=808&#038;h=566" alt="Scala debugger options" width="808" height="566" /></p>
<p style="text-align:left;">Making this magic box marked, you exclude all classes which qualified name starts with &#8220;scala.runtime.*&#8221; from debug process. I. e. debugger will not step automatically into them. I suppose, it&#8217;s not the full set of classes which would be right to exclude, so it&#8217;s discussable questions and any suggestions are appreciated.</p>
<p style="text-align:left;">Just remind that you may also use customizable class filter for such, which is available from Java debugger settings.</p>
<p style="text-align:center;"><img class="aligncenter size-full wp-image-22" title="Java debugger class filter" src="http://ilyasergey.files.wordpress.com/2008/12/scala-debug12.png?w=1010&#038;h=707" alt="Java debugger class filter" width="1010" height="707" /></p>
<p style="text-align:left;">It seems to be a better solution for Scala, cause unlike Groovy it has no such amount of auxiliary classes. But who knows&#8230;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=14&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2008/12/24/debugging-scala-stepping-through-auxiliary-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>

		<media:content url="http://ilyasergey.files.wordpress.com/2008/12/scala-debug22.png" medium="image">
			<media:title type="html">Scala debugger options</media:title>
		</media:content>

		<media:content url="http://ilyasergey.files.wordpress.com/2008/12/scala-debug12.png" medium="image">
			<media:title type="html">Java debugger class filter</media:title>
		</media:content>
	</item>
		<item>
		<title>Partial functions in Scala</title>
		<link>http://ilyasergey.wordpress.com/2008/12/05/partial-functions-in-scala/</link>
		<comments>http://ilyasergey.wordpress.com/2008/12/05/partial-functions-in-scala/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 00:23:48 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://ilyasergey.wordpress.com/?p=11</guid>
		<description><![CDATA[It&#8217;s well-known fact that Scala provides such useful language construction as partially applied function. There is also appropriate syntactic sugar for them, namely code like def foo = {   case P1 =&#62; ...   //...   case Pn =&#62; ... } defines partially applied function foo() which does something on inputs, which match either [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=11&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s well-known fact that Scala provides such useful language construction as partially applied function. There is also appropriate syntactic sugar for them, namely code like</p>
<pre class="brush: java;">
def foo = {
  case P1 =&gt; ...
  //...
  case Pn =&gt; ...
}
</pre>
<p>defines partially applied function <em>foo()</em> which does something on inputs, which match either patterns P1,&#8230;,Pn and throws MatchError otherwise. The signature of trait PartialFunction is</p>
<pre class="brush: java;">

package scala

trait PartialFunction[-A, +B] extends AnyRef with (A =&gt; B) {
  def isDefinedAt(x: A): Boolean
  def orElse[A1 &lt;: A, B1 &gt;: B](that: PartialFunction[A1, B1]) : PartialFunction[A1, B1]
  override def andThen[C](k: B =&gt; C) : PartialFunction[A, C]
}
</pre>
<p>As it might be seen, PartialFunction extends trait Function1[-A, +B], which is represented here by notation (A=&gt;B). The principal method is <em>isDefinedAt()</em>. It checks, wheter tihs partial function matches its argument, or not.</p>
<p>So, we&#8217;re done with piece of theory.</p>
<p>The problem I faced today relates to analysis of some segment of code written in Scala. Say, we have  a declaration of function:</p>
<pre class="brush: java;">

@throws(classOf[IOException]) def readFile(f: File): Unit
</pre>
<p>During the compilation to bytecode Scala compiler will treat annotation @throws to produce signatures with specified exceptions, which would be visible in their order to Java compiler if we decide, for instance, override method <em>readFile()</em>. To pick this kind of information by method signature in Scala from appropriate CST we have to climb into subtree, corresponding @throws annotation invocation and check all conditions: this annotation is resolved to correct class, its argument exists etc. That&#8217;s why the first implementation of these checks looked like that:</p>
<pre class="brush: java;">

   private def extractExceptionType(a: ScAnnotation) = {
    val constr = a.annotationExpr.constr
    constr.typeElement.reference.map(_.bind) match {
      case Some(Some(res: ScalaResolveResult)) =&gt; res.getElement match {
        case c: PsiClass if c.getQualifiedName == &quot;scala.throws&quot; =&gt; constr.args match {
          case args: ScArgumentExprList if args != null =&gt; args.exprs match {
            case Seq(gc@(_: ScGenericCall)) =&gt; gc.referencedExpr match {
              case ref: ScReferenceExpression =&gt; ref.bind.map(_.getElement) match {
                case Some(m: PsiMethod) if m.getName == &quot;classOf&quot; =&gt; gc.typeArgs.typeArgs match {
                  case Seq(s: ScSimpleTypeElement) =&gt; s.reference.map(_.bind) match {
                    case Some(Some(res1: ScalaResolveResult)) =&gt; res1.getElement match {
                      case p: PsiClass =&gt; p.getClassType
                      case _ =&gt; null
                    }
                    case _ =&gt; null
                  }
                  case _ =&gt; null
                }
                case _ =&gt; null
              }
              case _ =&gt; null
            }
            case _ =&gt; null
          }
          case _ =&gt; null
        }
        case _ =&gt; null
      }
      case None =&gt; null
    }
  }
</pre>
<p>Looks ugly, doesn&#8217;t it? In my defence may say, that wrighting all this checks I didn&#8217;t thinks about christmas tree of nested &#8220;matches&#8221; which I got as result.</p>
<p>The first attempt to make this code a bit more good-looking was to eliminate all &#8220;secondary&#8221; branches of match statements at a stroke, wrapping them to one exception handling:</p>
<pre class="brush: java;">

  private def extractExceptionType(a: ScAnnotation) = {   
    val constr = a.annotationExpr.constr
    try {
      constr.typeElement.reference.map(_.bind) match {
        case Some(Some(res: ScalaResolveResult)) =&gt; res.getElement match {
          case c: PsiClass if c.getQualifiedName == &quot;scala.throws&quot; =&gt; constr.args match {
            case args: ScArgumentExprList if args != null =&gt; args.exprs match {
              case Seq(gc@(_: ScGenericCall)) =&gt; gc.referencedExpr match {
                case ref: ScReferenceExpression =&gt; ref.bind.map(_.getElement) match {
                  case Some(m: PsiMethod) if m.getName == &quot;classOf&quot; =&gt; gc.typeArgs.typeArgs match {
                    case Seq(s: ScSimpleTypeElement) =&gt; s.reference.map(_.bind) match {
                      case Some(Some(res1: ScalaResolveResult)) =&gt; res1.getElement match {
                        case p: PsiClass =&gt; p.getClassType
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    catch {
      case e: MatchError =&gt; null
    }
  }
</pre>
<p>Looks a bit less ugly, but I still cannot say that this wedge-like code makes me happy. At this moment you can notice, that almost all checks of our nested sequence are performed by single pattern:</p>
<pre class="brush: java;">

case P(x1,...,x_n) =&gt; fun(x1,... x_n) match {...}
</pre>
<p>In other words, every pattern matching binds new set of variables, evaluates some expression with them and passes its result to next check. So, why don&#8217;t us adjust it in continuation-passing style via list of partially applied functions? Firstly, let&#8217;s define an auxiliary function to perform our sequence of applications:</p>
<pre class="brush: java;">

def foldFuns(initial: Any)(fail: Any)(l: List[PartialFunction[Any, _]]): Any = l match {
    case h :: t =&gt; if (h.isDefinedAt(initial)) foldFuns(h(initial))(fail)(t) else fail
    case Nil =&gt; initial
  }
</pre>
<p>In other words, our high-order function <em>foldFuns() </em>takes initial element, result which will be returned in a case of failure and a list of partially applied funtions. It performs a composition of given list of functions with the one difference that in a case of unmatching argument <em>fail</em> result will be returned.</p>
<p>Finally, we rewrite our checks using <em>foldFuns()</em> function:</p>
<pre class="brush: java;">
  private def extractExceptionType(a: ScAnnotation) = {
    val constr = a.annotationExpr.constr
    val result = foldFuns(constr.typeElement.reference.map(_.bind))(null)(List(
      {case Some(Some(res: ScalaResolveResult)) =&gt; res.getElement},
      {case c: PsiClass if c.getQualifiedName == &quot;scala.throws&quot; =&gt; constr.args},
      {case args: ScArgumentExprList if args != null =&gt; args.exprs},
      {case Seq(gc@(_: ScGenericCall)) =&gt; (gc.referencedExpr, gc.typeArgs.typeArgs)},
      {case (ref: ScReferenceExpression, ta) =&gt; (ref.bind.map(_.getElement), ta)},
      {case (Some(m: PsiMethod), ta) if m.getName == &quot;classOf&quot; =&gt; ta},
      {case Seq(s: ScSimpleTypeElement) =&gt; s.reference.map(_.bind)},
      {case Some(Some(res1: ScalaResolveResult)) =&gt; res1.getElement},
      {case p: PsiClass =&gt; p.getClassType}
      ))

    result match {
      case p: PsiClassType =&gt; p
      case _ =&gt; null
    }
  }
</pre>
<p>This code is still no perfect. Mainly by the reason, that we still have to &#8220;cast&#8221; our result at the end to &#8220;correct&#8221; type. The most attentice ones could notice, that we had to jam parameter &#8220;ta&#8221; (derived initially from TypeArguments) through several calls, cause with such implementation every function has its own context.</p>
<p>As for explicit typecast at the end, we could avoid it by introducing result&#8217;s type as generic type parameter of <em>foldFuns()</em> function, but in such case we also shoud separate last member of function list as a standalone parameter. Or, may be, someone could propose more elegant solution?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=11&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2008/12/05/partial-functions-in-scala/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>
	</item>
		<item>
		<title>Tony Morris on Scala plugin for IntelliJ IDEA</title>
		<link>http://ilyasergey.wordpress.com/2008/11/07/tony-morris-on-scala-plugin-for-intellij-idea/</link>
		<comments>http://ilyasergey.wordpress.com/2008/11/07/tony-morris-on-scala-plugin-for-intellij-idea/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 21:04:47 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://ilyasergey.wordpress.com/?p=8</guid>
		<description><![CDATA[Something unbelievable. Subject<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=8&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Something unbelievable.</p>
<p><a class="alignleft" title="Subject" href="http://blog.tmorris.net/intellij-idea-80-scala-turns-the-tide/">Subject</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=8&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2008/11/07/tony-morris-on-scala-plugin-for-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>
	</item>
		<item>
		<title>Yet another one?</title>
		<link>http://ilyasergey.wordpress.com/2008/11/06/hello-world/</link>
		<comments>http://ilyasergey.wordpress.com/2008/11/06/hello-world/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 17:49:59 +0000</pubDate>
		<dc:creator>ilyasergey</dc:creator>
				<category><![CDATA[live]]></category>
		<category><![CDATA[hello]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Well, hello. It&#8217;s right question to ask, why do the world need for one more blog? Honestly speaking, I don&#8217;t know, but as it seems to me, I have some minds which I would like to share with other. The most part of them will be of technical direction and related to my investigations in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=1&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Well, hello.</p>
<p>It&#8217;s right question to ask, why do the world need for one more blog?</p>
<p>Honestly speaking, I don&#8217;t know, but as it seems to me, I have some minds which I would like to share with other. The most part of them will be of technical direction and related to my investigations in computer science, software engineering and digital signal processing.</p>
<p>So, see you soon!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ilyasergey.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ilyasergey.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ilyasergey.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilyasergey.wordpress.com&amp;blog=5429797&amp;post=1&amp;subd=ilyasergey&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilyasergey.wordpress.com/2008/11/06/hello-world/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/ac64d25e2aa28b02e93e5910ab19b08f?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96" medium="image">
			<media:title type="html">ilyasergey</media:title>
		</media:content>
	</item>
	</channel>
</rss>
