- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Eclipse Scala IDE - Type search via UI vs. programatically
Fri, 2010-04-16, 22:26
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
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