Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Provide markers (and quick fixes) based on annotations(The goal is to have a plugin provide markers and at a later stage quick fixes based on javax.persistence annotations)
Provide markers (and quick fixes) based on annotations [message #558847] Tue, 14 September 2010 11:28 Go to next message
Eclipse UserFriend
I want to write a plugin that provides the user with error markers for classes and fields that are annotated with javax.persistence.* annotations.
The idea is to provide markers if an external DSL does not "fit" with the JPA annotations.

I now have an IncrementalProjectBuilder registered, that handles changes to java files and that visits JavaElements and looks for the annotations. It also successfully catches the annotations with the right names.

However, how can I be sure that the annotation is a javax.persistence.Entity? When I query the Java model, i get a String "Entity". Can someone recommend a strategy? I thought about looking at the imports but that seems rather tedious.

Should I try to use the jdt.apt functionality for this, or is the Java model the right place to look for information this detailed and then provide markers and quick fixes?
Re: Provide markers (and quick fixes) based on annotations [message #558997 is a reply to message #558847] Wed, 15 September 2010 05:31 Go to previous messageGo to next message
Eclipse UserFriend
Hi guys.

Concerning this question, here's a little update:

This morning I implemented the logic to look at the imports of the ICompilationUnit. It's actually not as tedious as I thought it might be and it works.
However I'm still wondering wether using the Java model for this task is the right way to go. What do you think?
Re: Provide markers (and quick fixes) based on annotations [message #559221 is a reply to message #558997] Thu, 16 September 2010 01:28 Go to previous messageGo to next message
Eclipse UserFriend
One advantage you get with using annotation processor is that you could even use it with command line. Otherwise, your approach should be fine.
Re: Provide markers (and quick fixes) based on annotations [message #559545 is a reply to message #558847] Fri, 17 September 2010 02:27 Go to previous messageGo to next message
Eclipse UserFriend
<silvio.heuberger@gmail.com> wrote in message
news:i6o4bq$ptf$1@build.eclipse.org...
>I want to write a plugin that provides the user with error markers for
>classes and fields that are annotated with javax.persistence.* annotations.
> The idea is to provide markers if an external DSL does not "fit" with the
> JPA annotations.


This sounds to me like a textbook example of an annotation processor. (In
fact you might be able to find an existing annotation processor that does
it.)
Re: Provide markers (and quick fixes) based on annotations [message #628533 is a reply to message #558847] Thu, 23 September 2010 09:03 Go to previous messageGo to next message
Eclipse UserFriend
I'm currently still exploring this with the JavaModel by Eclipse.
However, I'm having trouble to find the fully qualified type of an IField, I can get the eclosing type, but not the type of the field.

How do I get the type of a field?
Re: Provide markers (and quick fixes) based on annotations [message #628808 is a reply to message #558847] Fri, 24 September 2010 04:59 Go to previous messageGo to next message
Eclipse UserFriend
Since this is more or less me, talking to myself... Very Happy

The solution to find the IType for an IField:
String[][] resolvedTypes = type.resolveType(Signature.getSignatureSimpleName(field.getTypeSignature()));
if (resolvedTypes.length > 1) {
	System.err
		.print(new IllegalStateException("found more than one types that matches the field " + getName()
		+ " possible matches are " + Arrays.toString(resolvedTypes)));
}
IJavaProject project = (IJavaProject) type.getCompilationUnit().getParent().getParent().getParent();
return project.findType(resolvedTypes[0][0], resolvedTypes[0][1]);

Re: Provide markers (and quick fixes) based on annotations [message #632462 is a reply to message #558847] Wed, 13 October 2010 01:27 Go to previous message
Eclipse UserFriend
silvio.heuberger@gmail.com wrote:
> I want to write a plugin that provides the user with error markers for
> classes and fields that are annotated with javax.persistence.* annotations.
> The idea is to provide markers if an external DSL does not "fit" with
> the JPA annotations.
>
> I now have an IncrementalProjectBuilder registered, that handles changes
> to java files and that visits JavaElements and looks for the
> annotations. It also successfully catches the annotations with the right
> names.
>
> However, how can I be sure that the annotation is a
> javax.persistence.Entity? When I query the Java model, i get a String
> "Entity". Can someone recommend a strategy? I thought about looking at
> the imports but that seems rather tedious.
>
> Should I try to use the jdt.apt functionality for this, or is the Java
> model the right place to look for information this detailed and then
> provide markers and quick fixes?

Sorry to respond so late, I have been working on other projects. Yes, an
annotation processor is the right way to do this. This is exactly what
annotation processing was designed for.
Previous Topic:F3 does not work on exception stack trace
Next Topic:To setup eclipse ecj compiler as a java project in eclipse
Goto Forum:
  


Current Time: Tue Jul 08 14:53:06 EDT 2025

Powered by FUDForum. Page generated in 0.04556 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top