I'm working on a project where I want to give feedback on Java code written by complete beginners. In other words, I need to be able to tell if the code is following conventions, not just if it's valid Java code.
I have looked into modules like pyparsing, PLY and pyPEG, and it looks like they would do the trick as far as parsing at least a large subset of Java - which would be fine. However I'm not very experienced with parsing, so I'm not sure if it's possible to use these tools to check against code conventions as well?
It depends on what type of code conventions you are talking about.
If you are talking about conventions that are reflected in the source syntax, and semantics (e.g. checking identifier conventions, no assignment to parameters, resources properly closed), these can be be checked based on a Java parse tree produced by a parser generated from a normal Java grammar.
If you are talking about conventions in the use of indentation, white-space, comments and so on, a normal Java parser ignores these, and they don't get recorded in the parse tree. Therefore you would need to analyse using a parser (or some other kind of tool) that was designed to recognize and capture that stuff.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With