TypecastParenPad
Since Checkstyle 3.2
Description
Checks the policy on the padding of parentheses for typecasts. That
is, whether a space is required after a left parenthesis and before
a right parenthesis, or such spaces are forbidden.
Properties
name | description | type | default value | since |
---|---|---|---|---|
option | Specify policy on how to pad parentheses. | PadOption | nospace |
3.2 |
Examples
To configure the check:
<module name="Checker">
<module name="TreeWalker">
<module name="TypecastParenPad"/>
</module>
</module>
Example:
class Example1 {
float f1 = 3.14f;
int n = ( int ) f1; // 2 violations
double d = 1.234567;
float f2 = (float ) d; // violation 'preceded with whitespace'
float f3 = (float) d;
float f4 = ( float) d; // violation 'followed by whitespace'
}
To configure the check to require spaces:
<module name="Checker">
<module name="TreeWalker">
<module name="TypecastParenPad">
<property name="option" value="space"/>
</module>
</module>
</module>
Example:
class Example2 {
double d1 = 3.14;
int n = ( int ) d1;
int m = (int ) d1; // violation 'not followed by whitespace'
double d2 = 9.8;
int x = (int) d2; // 2 violations
int y = ( int) d2; // violation 'not preceded with whitespace'
}
Example of Usage
Violation Messages
All messages can be customized if the default message doesn't suit you. Please see the documentation to learn how to.
Package
com.puppycrawl.tools.checkstyle.checks.whitespace