This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Eclipse Scala IDE - Type search via UI vs. programatically

1 reply
Joachim Hofer
Joined: 2010-03-14,
User offline. Last seen 42 years 45 weeks ago.

I'm trying to jump to a Scala source file programmatically in my Eclipse
plugin, given the class name.

My first naive attempt just uses the JDT SearchEngine (because
Ctrl-Shift-T works with the Scala IDE plugin).

So the code looks like this (this works for Java classes):

val searchPattern = SearchPattern.createPattern(
"jmhofer.ecobertura.SomeScalaClass", IJavaSearchConstants.TYPE,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH)

def find(callback: IJavaElement => Unit) = {
val searchEngine = new SearchEngine
searchEngine.search(searchPattern, Array[SearchParticipant]
(SearchEngine.getDefaultSearchParticipant()),
searchScope, new SearchHandler(callback), null)
}

However, when calling find(), I receive a ClassCastException:

java.lang.ClassCastException:
scala.tools.eclipse.javaelements.ScalaClassElement cannot be cast to
org.eclipse.jdt.internal.core.BinaryType
at
org.eclipse.jdt.internal.core.search.matching.PossibleMatch.getSourceFileName(PossibleMatch.java:137)
at
org.eclipse.jdt.internal.core.search.matching.PossibleMatch.getQualifiedName(PossibleMatch.java:113)
at
org.eclipse.jdt.internal.core.search.matching.PossibleMatch.(PossibleMatch.java:43)
at
org.eclipse.jdt.internal.core.search.matching.MatchLocator.locateMatches(MatchLocator.java:1204)
at
org.eclipse.jdt.internal.core.search.JavaSearchParticipant.locateMatches(JavaSearchParticipant.java:94)
at
org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:223)
at
org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:507)
at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:551)
at ecobertura.ui.util.JavaElementFinder.find(JavaElementFinder.scala:45)

I'm using the Beta plugin. - I don't think that it's a Scala IDE bug,
though.

Is it simply not possible to use the JDT SearchEngine for this? Or am I
doing something wrong?

Any help would be appreciated a lot.

Thanks,
Joachim Hofer

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Eclipse Scala IDE - Type search via UI vs. programatically

On Fri, Apr 16, 2010 at 11:27 PM, Joachim Hofer
wrote:
> I'm trying to jump to a Scala source file programmatically in my Eclipse
> plugin, given the class name.

This would be a perfect question to ask in the shiny new scala-ide-dev
mailing list :-)

http://groups.google.com/group/scala-ide-dev

Cheers,

Miles

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland