Howto write a Check for Tabspace present in Whitespace of Code
A source code analyzer
Brought to you by:
adangel,
juansotuyo
We were thinking of removing our usage requirement of Checkstyle tool and bring all those as custom rules in PMD which aren't already there.
Having a hard time figuring out Tabspace presence in code as can't see it's occurence from AST (if possible let know).
How can one do it? Is it possible by overriding some baseclass stuff, at least?
I don't think, it is possible with PMD right now, to check for tabs in files. This is a whitespace character, that is ignored by the lexer already, so you won't find it in the AST anymore.
Checkstyle implements this by directly looking into the file without parsing it, see the FileTabCharacterCheck. The indentation checks are mapping the AST nodes to the source lines - each checkstyle check has access to the raw content of the source file.
With PMD, you could do the same: RuleContext gives you the current file that is checked. You can open this file and check each line for tab characters.
If you need to map the lines to AST nodes, you can use Node.getBeginLine() to get the begin line, end line, and the columns, if needed.
If you just want to check for tab characters, you could write a minimal java rule: