Eclipse Plugin Code Completion - java

I writes an Eclipse plugin that propose code completion. The mechanism itself work fine but it's the data for the completion that i can't get dynamically.
I mean that i needs to parse the java code written by the user in his project.
To resolve this problem, i have try to use reflexion. But this does not work in OSGI environment.
I also tried the Reflection Api, with it, i have successfully find the methods annotated but i failed to retrieve method parameters and their Javadoc.
So i have to find a way to retrieve, all methods with their Javadoc, annotated with some annotations.
Do you have any idea?

Related

IntelliJ DSL plugin provide completion of Java classes and methods

I'm attempting to write an IntelliJ plugin for a DSL which references Java classes and methods. The DSL is exposed in *.conf files within a Java project. A typical snippet of the DSL looks like this:
TASK taskClass=com.example.Foo taskMethod=someMethod;
I've been working through the IJ 'Simple' plugin tutorial to learn about plugins and am able to implement a fair bit of my own plugin. Currently, however, I'm stuck on trying to understand how I can provide auto-completion for the taskClass and taskMethod keywords. Having worked through the Simple tutorial all my completion shows is 'Hello'. Now I want to be able to extend my CompletionContributor to show java classes and methods that exist in the project. This doesn't seem to be addressed in the tutorial, but perhaps I'm just missing it.
What do I need, in order to do this? I would guess that there is already some cached info about all the existing java code in a project that my Contributor could leverage.
I think you are looking for the existing stub indices.
For example, to get all class names in your project, you can use
val classNames = JavaFullClassNameIndex.getInstance().getAllKeys(project)
When using indices - your own or already existing ones - it is often useful to use the Index Viewer plugin so you can have a look at which things are in which index.
To add it as a dependency of your plugin (so you don't have to install it manually each time you build your plugin) add the following to intellij block of your build.gradle.kts:
plugins.set(listOf("java", "com.jetbrains.hackathon.indices.viewer:1.19"))
It should appear as a tool window on the right.
Don't forget to remove it once you are done with debugging the indices.
I also found the PsiShortNamesCache which might be useful.

Emit real time errors and warnings from annotation processor

Currently I'm working on an annotation in Java and everything works great. My AbstractProcessor creates the new files and can emit errors and warnings when needed. What is not working are real time errors and warnings. So what do I mean with that?
Assume I annotate a non parent method with #Override. The IDE will give me a real time error that I can not override this method since it is not part of the parent class. Same also goes for deprecated methods. Whenever you try to call one of these methods you get a warning about it. Note that these errors and warnings are emitted immediately and I do not have to rebuild my project to get notified about them.
Actually my warnings and errors are only emitted when I rebuild my project so how can I implement real time errors and warnings? Not sure if that matters but I use Intellij as IDE.
It depends on your IDE.
For example, I use eclipse. After setup the annotation processor. It can show the error immediately when I save the file. Like this:
For your IDE, this page may help.

Generate code during automatic build in eclipse?

I am writing a code generator that generates additional classes for each class annotated with a certain annotation. I have other classes in my project that has to refer these generated classes. If I can somehow integrate my code generator into the automatic build process, then I figure the generated code will always stay up to date.
Is this possible? Can I do this if write a new custom builder?
EDIT (2/7):
I looked at Lombok which is doing something similar. However, it modifies the AST from an annotation processor by using undocumented internal methods in eclipse. I don't want to take that risk. Moreover, I think they never wanted to do source generation - just byte code generation.
Assuming you have annotation processing configured, you can use the annotation processing plugin for m2e.
Here's the marketplace link: https://marketplace.eclipse.org/content/m2e-apt

Java library search order

Background / example (but question is probably broader than this):
I'm trying to write a Java application that accesses a Google AppEngine server. To set up the project for this, I followed the steps outlined in the accepted answer here:
Developing a Java Application that uses an AppEngine database
I am now running into a problem where I'm trying to execute an HttpURLConnection-request in the Java client application (i.e. not in the AppEngine server code), but Google's AppEngine library seems to have replaced the Java version of this connection with its own urlFetch()-implementation. This leads to me getting the following error: "The API package 'urlfetch' or call 'Fetch()' was not found.".
Actual question:
What determines the order in which Java looks through libraries to find needed class-implementations? Is there a way to modify this order (specifically in Eclipse), so that the actual JRE-functions take precedence over a third-party-library that is also needed. Or is there maybe something special going on with the implementation of Url in the example given above, that cannot be resolved by specifying a library order?
Update:
Turns out the problem I was seeing had nothing to do with the order in which classes were loaded. The AppEngine server code explicitly calls setContentHandlerFactory(...) to register its own handler during execution rather than at library load time (see here for a fix to this specific issue). So, while my "actual question" might still stand, I haven't actually yet come across a scenario where it matters...
You might have to define a custom ClassLoader.
Also, take a look at this answer.
Inside Eclipse, you can adjust the classpath order. Right click your project, choose Properties, Java Build Path, then click the "Order and Export" tab. However, of course, this won't affect your program when running outside Eclipse.

Is it possible to use SBT in a Java project with Hibernate and AspectJ?

What would I need to configure and what would automatically work? As far as I understand using both can be a bit tricky, because both use bytecode weaving. Can I keep using the more convenient configuration syntax or do I need the "full" Scala version of it?
Currently I'm trying to use Maven, without much success.
Can you at least provide code examples to work with? What are you trying to achieve?
I have used hibernate - spring - and SpringAOP (which is substitutable for aspectj) and it works well. The same project also worked well with aspectJ - I was trying to intercept calls on specific methods calls in order to determine the exception(s) to serialize back to a GWT client.
Any example and what you intend to achieve is a good start?

Categories

Resources