I have some custom (logic-)validators for Eclipse, but all are facing the same Problem:
The actual implementation of some logic can take place in any of the parent classes.
So, whenever a resource in question changes, I can went up the inheritance tree to see if the required code takes place in any of the parent classes - if not, i'm placing a marker into the validated file itself.
This marker ofc. gets verified, whenever changes to the resource in question are made. But how can i trigger a revalidation if one of the parent classes changes?
Is it possible to place some kind of "validator-callback" into other files, which will trigger an validation of the given file?
i.e. Three Classes: A extends B
, B extends C
- Now, the validator notes on A
, that neither A
nor B
nor C
is extending X
- which is required for A
due to annotations. (Logic-Contract)
Now the Error-Marker in A
should be re-evaluated as soon as B
or C
are modified. (Currently i'm using a delta-builder which ofc. just will invoke validation whenever A
changes...)
In a nutshell: I want to place a "marker", that gets re-validated whenever one out of X resources change.
After I had some time to play around, I finally found a 99% solution to this issue.
Good news: It is possible.
Bad news: It is DIY. I was not able to find any useful method to achieve what I want.
The following post should outline the solution regarding my problem. There might be better, more efficent or easier solutions, but unfortunately the documentation around the validation framework of eclipse is very thin - so i'd like to share my solution - take it, improve it - or ignore it :)
First, you should understand the actual problem I tried to solve. Therefore I'm providing short snippets, without going into too much detail of the validator or my code-lineout:
In my project, I'm using Hibernate - and therefore a lot of classes annotated with
@Entity
. When using Hibernate along withLazyLoading
one needs to (manually) ensure, thatPersistentBags
are initialized when accessed.In our application, there is a method called
initializeCollection(Collection c)
in the classLazyEntity
, which handles everything around it.This leads to a logic contract my validator should validate:
class
annotated with@Entity
, AND this class is usingFetchType.LAZY
on any of its collections, there musst be two contraints met:LazyEntity
.getter
of thecollection
in question needs to callinitializeCollection()
before returning thecollection
.I'll focus on point
B
, because this is, where the validation problem kicks in: How to revalidate an actual Entity, when it's ancestor changes?I modified the actual validation method, to have two
IFiles
as Attributes:The delta-builder as well as the incremental builder are invoking this method like this:
Now - in a first step - the validator itself is taking care to validate the
actualFile
and bubbling up the inheritence tree to validate any parent file as well. If the validator hits the top-most-parent, without finding the required extension, an additional marker is placed.The placement of the markers is happening with the following method. In case the file, where the marker should be placed differs from the file on which eclipse has invoked the validation, the
IMarker.USER_EDITABLE
Attribute is used to store a path to the file, on which the validation has been invoked (in order to retrigger validation):Now, the validation errors are set: Each actual class contains its Errors - and in case the validation fails in the inheritance tree, the parent contains a marker as well:
(
AdminUser extends TestUser
in this Example)When the validator gets triggered on the "parent" file due to changes, it graps all markers, and checks, if the marker provides the callback Attribute. If so, the validator invokes the validation of the resource instead of just validating the parent:
Finally, a change to the root file in the inheritance tree causes the leaf file to be revalidated:
initializeCollection
-Method properly, there is no error at all :)The only trade off so far is: IF the parent-file is valid - and gets modified to invalid - it will not re-trigger the validation of the leaf, because there is no error-marker containing any callback information.
The error then will appear the first time a full-build is performed. - For the moment, I can live with that.
Logic in a nutshell
callback link
as marker attribute.callback link
inside the existing marker, which in trun will be case1
and recreate all markers if applicable.