Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#213 Add support for Java 7

Unstable_(example)
closed
nobody
None
5
2014-08-14
2011-09-02
No

This patch adds the support for Java 7 to Checkstyle's ANTLR grammar.
It comes with 1 unit test for each new Java 7 language feature.

This patch should be backwards-compatible: AST for files which do not use Java 7 features should be left unchanged.

Impact by Java 7 language feature:

1) String in switch: None, the grammar already supported this.

2) Simplified variable arguments: None, the grammar should not be impacted by this feature.

3) Binary integer literals and underscores in numerical literals: The tokens value in the AST will be identical as the one written in the source code.

4) Diamond Generics: In presence of a diamond, the AST looks like:

+--TYPE_ARGUMENTS
|
+--GENERIC_START
+--GENERIC_END

5) try-with-resources: In presence of a try-with-resources, the AST looks like:

+--try
|
+--LPAREN (new node containing the "resource")
|
+--MODIFIERS
+--TYPE
|
...
+--IDENT
+--ASSIGN
+--EXPR
|
...
+--RPAREN
+--SLIST (list of statements of the try block, just like a try/catch)
|
...
+--LITERAL_CATCH (optionnally, if there was a catch, just like a try/catch)
+… (unchanged, just like a try/catch)

6) Multi-catch and more precise rethrow: In presence of a multi-catch, the AST looks like:

+--try
|
+--SLIST (list of statements of the try block)
|
...
+--LITERAL_CATCH
|
+--LPAREN
+--PARAMETER_DEF
|
+--MODIFIERS
+--TYPE
|
+--IDENT (containing the first exception to catch, or a DOT node if it is a fully qualified type)
+--IDENT (containing the second exception to catch, or a DOT node if it is a fully qualified type)
+--...
+--IDENT (name of the exception variable)
+--RPAREN
+--SLIST (list of statements of the catch block)
|
...

Discussion

  • Oliver Burn
    Oliver Burn
    2011-09-06

    Thanks - I have applied to Hg, changeset #92074bd01604

     
  • Oliver Burn
    Oliver Burn
    2011-09-15

    Re-opening as I have found a bug in the patch. When running a test over the JDK7 source code, I found at the following error gets generated to standard out:

    java\lang\Package.java:578:59: expecting RPAREN, found ';'

    The offending lines are:

        try (FileInputStream fis = new FileInputStream(fn);
             JarInputStream jis = new JarInputStream(fis, false))
    

    It would be great Dinesh if you could look at this.

    Many thanks.

     
  • Yup, I did not knew that several resources could be opened at once in the try-with-resources construct.

    The least to say is that the JSR 334 is a mess and hard to understand.

    I'll work on it and submit an updated version of the patch.

     
  • Updated version of the patch - AST of try-with-resources updated and documented in the patch self.

     
    Attachments
  • I just submitted an updated patch which should fix the problem you reported Olivier.

    Notice that the AST for try-with-resource is now more inline with the JSL and is documented in the TokenTypes.java file provided by the patch.

     

  • Anonymous
    2013-05-02

    when will this patch be released in Checkstyles ?

     

  • Anonymous
    2013-05-23

    Does this mean it is now possible to enforce usage of diamond operator across your project? or do you need to apply this patch and manually build your own version of checkstyle?

     
  • Oliver Burn
    Oliver Burn
    2013-06-12

    This patch has been superseded by other patches.

     
  • Oliver Burn
    Oliver Burn
    2013-06-12

    • status: open --> closed
    • Group: --> Unstable_(example)