Is there a reason the Eclipse content assits doesn't work in/around lambdas? In a normal case Eclipse usually does this after writing a dot:
Which works just fine like anywhere else. However just a couple of lines later I get nothing:
Both objects are of the same type. Unfortunately I use these all the time as they make everything much faster and I don't understand why it works in one lambda and not the other.
Attempting an explanation (you asked for a reason): parsing lambda expressions in Java is a technical challenge, as the Java grammar was not made for parser generators. Code completion, OTOH, inevitably depends on parsing incomplete code, i.e., heuristics must be used to continue parsing after a syntax error. These two just don't nicely cooperate. As a result in some situations your incomplete code will look like garbage to the compiler and hence content assist is not able to figure out, what would be meaningful proposals.
The applied heuristics are constantly being improved. I recommend trying your examples on a recent milestone build. If the problem still exists, you might help the team by filing a bug providing a code example, and describing your expectations and what actual behavior you observe.
Related
I'm running into an unexpected (only for me?) ScalaC behavior.
The TL;DR is that the following is a recreation of an issue I saw while trying to migrate a codebase from maven to bazel. One of the main focuses of this migration is to try to minimize the dependencies each class needs for compilation so that builds will be triggered only when needed.
Unfortunately what I saw is that given ClassIndirectlyNeedingFoo(uses)->ClassUsingFoo(uses)->Supplier the compilation of ClassIndirectlyNeedingFoo breaks if Supplier is not on the classpath.
The full details are here (https://github.com/ittaiz/scalac-troubleshooting).
If anyone knows why scalac behaves like this I'd really appreciate it.
Thanks!
BTW, Supplier is not in the source or bytecode of ClassIndirectlyNeedingFoo...
Ok so the short answer is that Why isn't totally clear to anyone (see #4). What is clear is that it's known scalac sometimes needs more dependencies than one would think and it's also clear that sometimes when this happens it's a bug.
Furthermore from a discussion with Jason Zaugg on Gitter he seems to think my above issue is just apart of a family of bugs like the one linked above.
As Seth linked in the comments the ScalaCenter has accepted a proposal (original PR) for clarifying this area.
Most related to this issue are the four proposals there:
Improvements to the user experience of stub errors, centered around the Statement: that they are an expected common case, rather than a
rare, unexpected, or fatal condition.
Reduction of the number of cases that result in stub errors... ie, allowing more usecases that currently result in a stub error to
successfully compile, and thus allowing for fewer direct dependencies.
A compiler flag to require import statements for all symbols used during compilation (including those not otherwise mentioned in the
source). For symmetry with -Ywarn-unused-imports, this option might
potentially be called -Ywarn-undeclared-imports. It would primarily
assist with making the transition from transitive to direct
dependencies, rather than helping to maintain a build that is already
using direct dependencies. (as suggested by
#posco and
#adriaanm)
An expansion of the Scala Language Specification to list all cases in which a symbol from another compilation unit must be present on the
classpath, including: 1) subclassing, 2) return types of superclasses'
public methods, 3) direct reference, 4) etc.
It was agreed to go ahead with #3 though I don't know when the work will commence.
Eugeene Burmako, who co-authored the proposal, started prototyping the solution and I've made a small change on top of that.
For now this will have to do for my problem.
we are working on a project to come up with an intermediate representation for the code in terms of something called an assignment decision diagram. So it would be very helpful if someone can tell us how you guys are compiling the code and how to access the graphs generated during compilation i.e after parsing the code for grammar.
Even help regarding accessing the code after parsing of the compiler is fine. Any help regarding how to go about doing it is also appreciated.
Currently, there is not a well defined intermediate representation of Chisel as it goes between the user source code and the specified C++ or Verilog backends.
However, I believe this is a current project amongst the Chisel devs to break apart the backend and allow access to the IR (and allow for user-defined compiler passes).
In the meantime, check out Backend.scala (particularly the elaborate() method). That's where a lot of the magic originates. I believe it is possible to jump into the Scala command line in the middle of elaboration, which will give you access to the hardware tree representation, but I'm not sure how meaningful or useful that will be for you.
During development in Eclipse, how common is it for the AST that the JDT returns to clients to be broken somehow? And in what ways are they sometimes broken?
I imagine obvious things like missing imports, but are there also cases where the code compiles, but the JDT-AST is still broken, or is this AST also the input to the actual compilers?
If the code has compile errors the AST returned by JDT's API will have 'malformed nodes'.
If the code compiles then the AST should correspond perfectly with the code. There could be bugs but this area is tested fairly well.
I have just finished the first version of a Java 6 compiler plugin, that automatically generates wrappers (proxy, adapter, delegate, call it what you like) based on an annotation.
Since I am doing mixed Java/Scala projects, I would like to be able to use the same annotation inside my Scala code, and get the same generated code (except of course in Scala). That basically means starting from scratch.
What I would like to do, and for which I haven't found an example yet, is how do I generate the code inside a Scala compiler plugin in the same way as in the Java compiler plugin. That is, I match/find where my annotation is used, get the AST for the annotated interface, and then ask the API to give me a Stream/Writer in which I output the generated Scala source code, using String manipulation.
That last part is what I could not find. So how do I tell the API to create a new Scala source file, and give me a Stream/Writer/File/Handle, so I can just write in it, and when I'm done, the Scala compiler compiles it, within the same run in which the plugin was invoked?
Why would I want to do that? Firstly, because than both plugins have the same structure, so maintenance is easy. Secondly, I want to open source it, and there is just no way to support every option that anyone would want, so I expect potential users to want to extend the generation with their own code. This will be a lot easier for them if they just have to do some printf(), instead of learning the AST API (this also applies to me).
Short answer:
It can't be done
Long answer:
You could conceivably generate your source file and push that through a parser instance within your plugin. But not in any way that's likely to be of any use to you, because you'd now have a bigger problem to contend with:
In order to grab all the type/name information for generating the delagate/proxy, you'll have to pick up the annotated type's AST after it has run through both the namer and typer phases (which are inseperable). The catch is that any attempts to call your generated code will already have failed typechecking, the compiler will have thrown an error, and any further bets are off.
Method synthesis is possible in limited cases, so long as you can somehow fool the typechecker for just long enough to get your code generated, which is the trick I pulled with my Autoproxy 'lite' plugin. Even then, you're far better off working with TreeDSL to generate code instead of pumping out raw source.
Kevin is entirely correct, but just for completeness it's worth mentioning that there is another alternative - write a compiler plugin that generates source. This is the approach that I've adopted in Borachio. It's not a very satisfactory solution, but it can be made to work.
Edit - I just reread your question and realised that you're actually asking about generating source anyway
So there is no support for this directly, but it's basically just a question of opening a file and writing the relevant "print" statements. There's no way to invoke the compiler "inside" a plugin AFAIK, but I've written an sbt plugin which hides most of the complexity of invoking the compiler twice.
How would you define "unwanted code"?
Edit:
IMHO, Any code member with 0 active calling members (checked recursively) is unwanted code. (functions, methods, properties, variables are members)
Here's my definition of unwanted code:
A code that does not execute is a dead weight. (Unless it's a [malicious] payload for your actual code, but that's another story :-))
A code that repeats multiple times is increasing the cost of the product.
A code that cannot be regression tested is increasing the cost of the product as well.
You can either remove such code or refactor it, but you don't want to keep it as it is around.
0 active calls and no possibility of use in near future. And I prefer to never comment out anything in case I need for it later since I use SVN (source control).
Like you said in the other thread, code that is not used anywhere at all is pretty much unwanted. As for how to find it I'd suggest FindBugs or CheckStyle if you were using Java, for example, since these tools check to see if a function is used anywhere and marks it as non-used if it isn't. Very nice for getting rid of unnecessary weight.
Well after shortly thinking about it I came up with these three points:
it can be code that should be refactored
it can be code that is not called any more (leftovers from earlier versions)
it can be code that does not apply to your style-guide and way-of-coding
I bet there is a lot more but, that's how I'd define unwanted code.
In java i'd mark the method or class with #Deprecated.
Any PRIVATE code member with no active calling members (checked recursively). Otherwise you do not know if your code is not used out of your scope analysis.
Some things are already posted but here's another:
Functions that almost do the same thing. (only a small variable change and therefore the whole functions is copy pasted and that variable is changed)
Usually I tell my compiler to be as annoyingly noisy as possible, that picks 60% of stuff that I need to examine. Unused functions that are months old (after checking with the VCS) usually get ousted, unless their author tells me when they'll actually be used. Stuff missing prototypes is also instantly suspect.
I think trying to implement automated house cleaning is like trying to make a USB device that guarantees that you 'safely' play Russian Roulette.
The hardest part to check are components added to the build system, few people notice those and unused kludges are left to gather moss.
Beyond that, I typically WANT the code, I just want its author to refactor it a bit and make their style the same as the rest of the project.
Another helpful tool is doxygen, which does help you (visually) see relations in the source tree.. however, if its set at not extracting static symbols / objects, its not going to be very thorough.