Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Eclipse custom errors
Eclipse custom errors [message #514969] Wed, 17 February 2010 11:26 Go to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
Hello all,

Im working on a plugin for eclipse, and i want to be able to make custom errors for, for example, annotations that are misplaced.

So basically i want to see the error in the problem view in eclipse, now ive been looking around on how to do that, and i have found out i need at least the IProblem interface for creating the errors. The thing i need is how do i check my code for wrong annotations so i can create the appropriate error? Ive been looking into the eclipse compiler but i cant seem to find out how it works.

Anybody have some proper information about how the eclipse compiler works and how i can use it to detect my own custom errors?

Thanks in advance,
Michiel
Re: Eclipse custom errors [message #514995 is a reply to message #514969] Wed, 17 February 2010 13:00 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
berkhofmichiel2@hotmail.com wrote:
> Hello all,
> Im working on a plugin for eclipse, and i want to be able to make
> custom errors for, for example, annotations that are misplaced.
Are you talking about Java here?

Dani
> So basically i want to see the error in the problem view in eclipse,
> now ive been looking around on how to do that, and i have found out i
> need at least the IProblem interface for creating the errors. The
> thing i need is how do i check my code for wrong annotations so i can
> create the appropriate error? Ive been looking into the eclipse
> compiler but i cant seem to find out how it works.
> Anybody have some proper information about how the eclipse compiler
> works and how i can use it to detect my own custom errors?
>
> Thanks in advance,
> Michiel
Re: Eclipse custom errors [message #515023 is a reply to message #514995] Wed, 17 February 2010 14:08 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
uuh yeah im talking about java, i just need to know which classes i can use for checking code on the fly and how to add my own code checks to them. Like say if an annotation can only be placed on a getter and not on a setter, there should appear a warning or error message when this annotation is set to a setter.

Like code quality checkers do, just put error/warning messages in the problem view of eclipse, only i dont know if they use custom errors and warnings or the build in static ones in IProblem interface. I want to make custom ones.


[Edit] Uh one more thing, im looking into eclipse.jdt.core to try and find it out, but im not sure if im looking in the right spot

Greetz

[Updated on: Wed, 17 February 2010 14:12]

Report message to a moderator

Re: Eclipse custom errors [message #515031 is a reply to message #515023] Wed, 17 February 2010 14:18 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
berkhofmichiel2@hotmail.com wrote:
> uuh yeah im talking about java, i just need to know which classes i
> can use for checking code on the fly and how to add my own code checks
> to them.
> Like code quality checkers do, just put error/warning messages in the
> problem view of eclipse, only i dont know if they use custom errors
> and warnings or the build in static ones in IProblem interface.
I depends how much info you need. You can either register your own
builder or org.eclipse.jdt.core.compilationParticipant (extension point).

Dani
>
> Greetz
Re: Eclipse custom errors [message #515050 is a reply to message #515031] Wed, 17 February 2010 15:08 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
Hi Dani,

thanks for the answer, ive looked into the CompilationParticipant but i still dont quite get the entire picture. I guess i need to use the reconcile function and put the problems to the ReconcileContext. The problems i can put in there are CategorizedProblems this implements the IProblem interface i talked on earlier. But, the IProblem should be generated by the compiler, how do i make those things custom? I read some about Markers, that might be of help, but i still dont get the whole picture Smile

Is it even possible to create my own problems using this thing or can i only change existing problems?

May be you can clarify some things for me?

Greetz and already thanks in advance!

[Updated on: Wed, 17 February 2010 15:09]

Report message to a moderator

Re: Eclipse custom errors [message #515057 is a reply to message #515050] Wed, 17 February 2010 15:23 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
berkhofmichiel2@hotmail.com wrote:
> Hi Dani,
> thanks for the answer, ive looked into the CompilationParticipant but
> i still dont quite get the entire picture. I guess i need to use the
> reconcile function and put the problems to the ReconcileContext. The
> problems i can put in there are CategorizedProblems this implements
> the IProblem interface i talked on earlier. But, the IProblem should
> be generated by the compiler,
Why? I thought you want to add those.

Dani
> how do i make those things custom? I read some about Markers, that
> might be of help, but i still dont get the whole picture :)
>
> May be you can clarify some things for me?
> Greetz and already thanks in advance!
Re: Eclipse custom errors [message #515062 is a reply to message #515057] Wed, 17 February 2010 15:44 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member

Yeah thats what i want, but i found this note saying:

"Note: the compiler produces IProblems internally, which are turned into markers by the JavaBuilder so as to persist problem descriptions. This explains why there is no API allowing to reach IProblem detected when compiling"


So i guessed IProblems are only generated by the compiler. If this is not the case, then i would like to know how to create one myself, because you dont know anything about for example the line number on which the problem occured? Or is this the link to the Markers you should make? I still dont really see how i can for example create a marker that matches against for example some annotation that is placed on a setter instead of a getter.

Greetz
Re: Eclipse custom errors [message #515074 is a reply to message #515062] Wed, 17 February 2010 15:58 Go to previous messageGo to next message
Dani Megert is currently offline Dani Megert
Messages: 3801
Registered: July 2009
Senior Member
berkhofmichiel2@hotmail.com wrote:
>
> Yeah thats what i want, but i found this note saying:
>
> "Note: the compiler produces IProblems internally, which are turned
> into markers by the JavaBuilder so as to persist problem descriptions.
> This explains why there is no API allowing to reach IProblem detected
> when compiling"
>
> So i guessed IProblems are only generated by the compiler.
And the participants which are considered being part of the compilation
process ;-)

> If this is not the case, then i would like to know how to create one
> myself, because you dont know anything about for example the line
> number on which the problem occured?
Well, I guess your logic has to find out which line it is ;-)

Dani
> Or is this the link to the Markers you should make? I still dont
> really see how i can for example create a marker that matches against
> for example some annotation that is placed on a setter instead of a
> getter.
>
> Greetz
Re: Eclipse custom errors [message #515075 is a reply to message #514969] Wed, 17 February 2010 16:18 Go to previous messageGo to next message
David M. Karr is currently offline David M. Karr
Messages: 352
Registered: July 2009
Senior Member
This is an appropriate use of the PMD framework. What is not commonly known if you haven't explored all of its features is that it provides an API that presents an abstract syntax tree view of the code it's analyzing. This allows you to write your own validation rules in Java, or simple ones in XPath. Once you've written the PMD rule for what you want to test for, and a piece of code violates that rule, you can make it show as an error or warning in Eclipse.
Re: Eclipse custom errors [message #515078 is a reply to message #515075] Wed, 17 February 2010 16:26 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
I rather dont use PMD but create it all myself, so PMD aint an option here.

I rather wanna know how to make the IProblem work with the Marker class in java, at least thats i think i need to know, but im not totally sure Smile
Re: Eclipse custom errors [message #515217 is a reply to message #514969] Thu, 18 February 2010 08:46 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
Bump, still dont have the answer, lemme try and explain it once more Smile

What i want is to make my own custom problems, get them detected by the compiler and show them in the problems view. Now the custom errors can be anything like a misplaced annotation (I have some that throw runtime errors when misplaced, but code gets compiled).

I somehow need the compiler to check for these custom errors, thing is i dont know how to:

a: Create the general errors (Thats in setting the message and stuff, the icon).

b: How to analyze the code finding the errors and fill in things like line number, filename and stuff.

Does anybody have a simple example of how to do this?

I have done some research but i just cant tie the ends together, or im looking in the wrong spot. As you can read in my previous posts.

Ive checked some open source code analyzers but that didnt quite work, most of the code is hidden in jars.

Greetz

[Updated on: Thu, 18 February 2010 08:47]

Report message to a moderator

Re: Eclipse custom errors [message #515915 is a reply to message #515217] Mon, 22 February 2010 08:47 Go to previous messageGo to next message
No real name is currently offline No real name
Messages: 18
Registered: February 2010
Junior Member
Still having this problem...

Im now trying to make my own builder, and scan files in a project manually to detect any mistakes made, and then put a marker... But i dont really know if im doing it the right way.

Could somebody provide me with some input on this plz?
Re: Eclipse custom errors [message #904341 is a reply to message #515915] Tue, 28 August 2012 09:23 Go to previous message
Mat Mathiew is currently offline Mat Mathiew
Messages: 29
Registered: July 2012
Junior Member
Maybe this can be useful :

http://www.eclipse.org/articles/article.php?file=Article-Forms33/index.html
Previous Topic:Programmatically activating a trim item
Next Topic:Scrapbook page - Code assist not working...
Goto Forum:
  


Current Time: Thu Sep 18 15:48:55 GMT 2014

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

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