Providing an intention for a type mismatch

Hello folks,

I'm writing an intention (actually, many of them) that should be applied
on type mismatch errors. These intentions use some utility methods
specific to my project. So far, I've been somewhat successful on writing
these intentions, albeit with more work than I'd expect.

At first, I thought that writing for an intention that checks for
PsiAssignmentExpression would suffice. Then I noticed assignments
performed at initialization are not a PsiAssignmentExpression, but a
PsiDeclarationStamente. Then I figured that assignments are not the only
place a type mismatch can occur, and then I wrote code to cover wrong
method parameters, looking for PsiExpressions. And oh, there are return
statements too, so I once again wrote more code to coven
PsiReturnStatements.

Since I have a lots of intentions that are actually doing the same thing,
ie, checking for expressions of a certain type ("right hand type") being
used where another type ("left hand type") is expected, at least I
refactory the lookup code to a common base class. It's core looks
something like this:


As you can guess, this is getting out of hand, and I'm still missing some
cases (like array initialization). Also, the intention is currently way
too much sensitive to the cursor position for my taste. For example:


Where where the someProperty is an Integer in vo and String in form, and |
simbolizes the cursor position. The intention is triggered on the above
example, but not on this one:


Which is quite unfortunate, since the later is usually the state of the
cursor after a method completion.

So, I'm asking for help and hints. Any good programmer comes to the
conclusion she/he is missing something if her/his code start to get as
long and repetitive as the snips above. What am I doing wrong, and what
could I do to make this task easier?

Of course, I can share the full source of what I've written so far if this
helps to figure this out. Cheers, and thanks in advance.

--
Marcus Brito <pazu@animegaiden.com.br>


Please sign in to leave a comment.