|Re: Custom validation of Java Language [message #709274 is a reply to message #709211]
||Wed, 03 August 2011 17:56
Registered: July 2009
What do you mean by "at design time"?|
If you mean "at compile time" (so, as the programmer writes the code),
that is a almost impossible task.
Of course you might check that in a call like
the argument is lowercase. This one is very straight forward and can be
done with xText. You "simply" have to write a grammar for Java and a
validator for it. But don't start working before you read the rest of my
post. There are some problems. Consider the following example:
//a lot of code
How should that be checked? You need some kind of constant propagation
that finds the value of arg at compile time. You might also think about:
If, in that example, the RandomStringGenerator generates a random String
at runtime, you cannot check whether it consits of lower case letters
only at compile time. There is simply no way to do it, because you can
not get the value of arg at compile time. It's the same if your string
is a User input, read from a file or something like that.
In my eyes the most common way is to start "myMethod" with testing if
the string is lower case and throw an IllegalArgumentException
otherwise. Of course that's a runtime check.
Another possibility: Have a look at findBugs. It should be possible to
use a technic similiar to their NullPointer- Dereferencing check to find
things like that. But I don't think it is worth the time, a runtime
check will be okay.
On 03.08.2011 18:32, Gabriel wrote:
> Maybe it's an Eclipse beginner question (well, this is my first post)
> Let's say I have a Java method that accept Strings but for some reason i
> want to check at design time that the argument is all lowercase, giving
> a warning to the user if not.
> Looking around i found some examples of xtext
> But seems to be oriented at Domain Specific Language.
> Is there an easy way to do it for regular Java projects?
> Thanks in advance
> PS: I don't know if this is the correct forum for this question.
Powered by FUDForum
. Page generated in 0.02711 seconds