How would I obtain a Scala type (i.e. a org.scalaide.core.internal.jdt.model.ScalaElement) by qualified name using the Scala IDE programmatically? In the JDT, there are the IJavaProject#findType(String, ...) methods. I looked into IScalaProject and couldn't find anything. I also couldn't find a way to obtain just a ScalaCompilationUnit, maybe just with a workspace path.
So am I just overlooking something and there are ways to get these items?
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/c1622984-050d-493c-ad58-fd446920448c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the quick response. But how can IJavaProject#findType(String, ...) return an IJavaElement for a Scala file? It probably just looks at .java files, and it cannot parse .scala files.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/104ae8c4-e9cb-4bab-a5ad-7ecfca40755b%40googlegroups.com.
I am not sure this is working. I created a JUnit plugin test that creates a Scala project and a Scala class within it. Then it uses org.eclipse.jdt.core.IJavaProject#findType(String, IProgressMonitor) to retrieve that Scala class, but nothing is returned. I also called org.eclipse.jdt.core.ICompilationUnit#getAllTypes() on a Scala compilation unit I created in a similar JUnit plugin test, and I get back an empty array.
Is there any way to do these two things, i.e. find a Scala class by qualified name and get all Scala types within a compilation unit?
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/aaffde43-1543-4d2f-8f8b-a4a579d2ed71%40googlegroups.com.
What do you want to do with the type, once you find it?
The correct way to do it is to use the Scala presentation compiler. The Java equivalent is there for interoperability with Java, and might not always work (it’s pretty hard to map everything correctly to Java elements). I’d do something like this to find a Scala symbol for a given name:
scalaProject.presentationCompiler { compiler =>
compiler.rootMirror.getClassByName(newTypeName(fullName))
}
Be prepared to handle errors, though (if the type name is not found). You can have a look at the JUnit4TestClassesCollector
for the way it looks for JUnit annotations.
What you get back is a symbol (as in scala reflection). You can map this one to a JDT element using scalaProject.presentationCompiler.getJavaElement
.
iulian
How would I obtain a Scala type (i.e. a org.scalaide.core.internal.jdt.model.ScalaElement) by qualified name using the Scala IDE programmatically? In the JDT, there are the IJavaProject#findType(String, ...) methods. I looked into IScalaProject and couldn't find anything. I also couldn't find a way to obtain just a ScalaCompilationUnit, maybe just with a workspace path.So am I just overlooking something and there are ways to get these items?
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/c1622984-050d-493c-ad58-fd446920448c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Once I have the type, I want to display it in a class or sequence diagram. Hence I am mostly interested in features, relationships, etc. of existing Scala types. Finding a type by qualified name is needed to open a diagram from a file, while compilation units need to be handled when one is dropped onto a diagram. I don't really need any JDT mapping, but the JDT has a fairly comprehensive API that I already know.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/35234dd7-feac-4e98-8854-60b24eb686c0%40googlegroups.com.
Thanks, I will have to work with the AST for some things anyway.But what about binary types, how are they represented in the Scala IDE? Is there something comparable to org.eclipse.jdt.core.IClassFile in the Scala IDE or can an AST be built from byte code? Or is it possible to get attached source code and parse that?
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/721297c7-baa3-420a-bd2a-19ae3ba16762%40googlegroups.com.
Thanks for all the help, I have a better understanding now. Unfortunately the Traverser is not very useful to me because I cannot reliably detect the parent of the current Tree element.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/e97572ee-f742-4795-8cbf-110af855c290%40googlegroups.com.
On Fri, Mar 27, 2015 at 7:14 PM, Felix Mayer <fljm...@gmail.com> wrote:
I mean class scala.reflect.api.Trees.Traverser. But never mind, I think can I can do what I need my limiting the downward traversal. I was just used to the Eclipse JDT AST visitor, which notifies you when you are done visiting an element.
Most of the times you don’t need the immediate parent, but the enclosing definition. I don’t know if that’s the case for you, but if that’s so, you can use currentOwner
. That’s maintained by the framework, and it points to the innermost enclosing definition (as a Symbol
, not a tree). If you need other context you’ll need to maintain it yourself during traversal, but it shouldn’t be too hard.
iulian
Thanks for your time.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/ecd36849-4d04-418f-a673-c517be71bfdb%40googlegroups.com.
java.lang.AssertionError: assertion failed: Race condition detected: You are running a presentation compiler method outside the PC thread.[phase: <no phase>] Please file a ticket with the current stack trace at https://www.assembla.com/spaces/scala-ide/support/tickets
at scala.tools.nsc.interactive.Global.assertCorrectThread(Global.scala:535)
at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1486)
at scala.reflect.internal.Types$TypeRef.thisInfo(Types.scala:2194)
at scala.reflect.internal.Types$TypeRef.baseClasses(Types.scala:2199)
at scala.reflect.internal.tpe.FindMembers$FindMemberBase.<init>(FindMembers.scala:17)
at scala.reflect.internal.tpe.FindMembers$FindMember.<init>(FindMembers.scala:219)
at scala.reflect.internal.Types$Type.scala$reflect$internal$Types$Type$$findMemberInternal$1(Types.scala:1014)
at scala.reflect.internal.Types$Type.findMember(Types.scala:1016)
at scala.reflect.internal.Types$Type.memberBasedOnName(Types.scala:631)
at scala.reflect.internal.Types$Type.member(Types.scala:600)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:48)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:45)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:45)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:45)
at scala.reflect.internal.Mirrors$RootsBase.getModuleOrClass(Mirrors.scala:66)
at scala.reflect.internal.Mirrors$RootsBase.getClassByName(Mirrors.scala:102)
at com.objectaid.uml.scala.ScalaElementFactory$$anonfun$1.apply(ScalaElementFactory.scala:252)
at com.objectaid.uml.scala.ScalaElementFactory$$anonfun$1.apply(ScalaElementFactory.scala:251)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy$$anonfun$internal$1.apply(PresentationCompilerProxy.scala:105)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy$$anonfun$internal$1.apply(PresentationCompilerProxy.scala:104)
at scala.Option.flatMap(Option.scala:171)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.internal(PresentationCompilerProxy.scala:104)
at org.scalaide.core.internal.compiler.PresentationCompilerProxy.apply(PresentationCompilerProxy.scala:62)
at com.objectaid.uml.scala.ScalaElementFactory.find(ScalaElementFactory.scala:251)
at com.objectaid.uml.scala.ScalaElementFactoryIT.testFind(ScalaElementFactoryIT.java:68)
When I use your suggestion to find a Scala symbol for a given name, I get the exception below. Should I do as the message says?
com.objectaid.uml.scala.ScalaElementFactory$$anonfun$1.apply(ScalaElementFactory.scala:252)
You are not allowed to access most methods of
symbols (in your case Symbol.info) outside of the presentation
compiler. Wrap the above line (or the code of block that contains
it) in --
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/8268ac8b-c042-45c6-9a07-4578ab47d6a4%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/551B804F.3030703%40antoras.de.
Here is something I don't understand with a ClassSymbol I got from the presentation compiler:
I looked up 'scala.collection.Seq', which should be either a trait or its companion object. The returned ClassSymbol has isTrait() == false, isConcreteClass() == true, isModuleClass() == false and the companionSymbol() is object Seq. So if I got the expected trait Seq, why does the ClassSymbol not say it's a trait?
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/46830b64-2625-4bb5-acb2-e03b4d99e883%40googlegroups.com.
I have a JUnit Plug-in test that creates a Scala project with the appropriate classpath and natures within a running Eclipse instance. The presentation compiler comes from that project. Then I call compiler.rootMirror.getClassByName(compiler.newTypeName("scala.collection.Seq")) and ClassSymbol#isTrait() == false.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/938e6572-a85d-411b-8355-2d93553e3da9%40googlegroups.com.
I have attached an Eclipse project with a launch file that works on my Mac. Your mileage with the launch file may vary depending on the environment. The launch configuration needs to have plenty of heap (this one has -Xmx2048M) and the bundle org.eclipse.equinox.weaving.aspectj must have Auto-Start true. The test expects isTrait() == true and fails.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/5af67b52-b4a2-4243-840d-2e53d5938551%40googlegroups.com.
How would a Github project help to reproduce the issue?
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/2e407739-ab9c-45c3-be99-5ab020482aa3%40googlegroups.com.
How would a Github project help to reproduce the issue?
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/2e407739-ab9c-45c3-be99-5ab020482aa3%40googlegroups.com.
Okay, but this way it's very little code you had to look at. And I can't really share the entire project.
After I added an 'initialize()' into compiler.asyncExec() (as this needs to happen in the compiler thread), the test succeeded.So thanks once again!
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/e2a70e9e-ac8e-42ed-a13f-2531d5f6b86a%40googlegroups.com.
I have been looking at nested types, and I am getting the impression that I cannot get nested ClassSymbols from a ClassSymbol. Is this correct? I can see that the TreeTraverser in the ScalaStructureBuilder uses Trees instead of Symbols. My issue is that I only expect Trees to be available from source code, but I would like to detect nesting relationships for binary code as well.
--
You received this message because you are subscribed to the Google Groups "Scala IDE User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-ide-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scala-ide-user/fb2d4848-337c-4403-82e6-d42acf996bff%40googlegroups.com.