-1

When we creating java class there is set of validation for the class name example that the class name will not start with number or . etc. I believe that this set of validation are done with regex ,how can i find this code ,I need somehow to reuse it.

Thanks!

James Berners
  • 103
  • 2
  • 10
  • 1
    you should have a look at checkstyle: http://checkstyle.sourceforge.net/ – Marco Forberg Jun 06 '13 at 10:46
  • You can probably find it via Google. Information to compose your own regex (a class name is an identifier): http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8 – BLaZuRE Jun 06 '13 at 10:46
  • More helpful information: http://stackoverflow.com/questions/65475/valid-characters-in-a-java-class-name –  Jun 06 '13 at 10:47
  • See here: http://stackoverflow.com/questions/13979172/how-to-check-if-the-class-name-is-valid/13979466#13979466 – tcb Jun 06 '13 at 12:12

2 Answers2

1

You can find complete grammar syntaxes for Java in popular LR or LARL compiler-compiler tools, e.g. ANTLR.

If you want to create a regex one of your own, the syntax is available here: http://docs.oracle.com/javase/specs/jls/se7/html/jls-3.html#jls-3.8

And here is another post that will help: Regular expression matching fully qualified class names

Community
  • 1
  • 1
TFuto
  • 1,259
  • 13
  • 27
1

Almost every IDE will check your code to match Java naming conventions (probably you will want to turn on checks in IDE options). Also you may want to use different tools to check your code such as:

FindBugs - a very solid bug finder tool, use at least this tool.

PMD - this tool can be extended by the user (requires some skills).

CheckStyle - this tool specifically checks JavaDoc comments.

They will help you find not only errors in naming conventions but much more

Alan Moore
  • 68,531
  • 11
  • 88
  • 149
Timur Samkharadze
  • 1,551
  • 1
  • 15
  • 29