Java 8 Grammar: Parsing of explicit receiver parameters #3239

Closed
rnveach opened this Issue Jun 2, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@rnveach
Member

rnveach commented Jun 2, 2016

Taken from PR #3230 when working on Issue #3033 from a run on OpenJDK 8/9.

$ javac TestClass.java 
$ cat TestClass.java
public class TestClass {
    public void m4(TestClass this) {}
    private class Inner {
        public Inner(TestClass TestClass.this) {}
    }
}

$ cat TestConfig.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
          "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8"/>

    <module name="TreeWalker">
    </module>
</module>

$ java -jar checkstyle-6.19-all.jar -c TestConfig.xml TestClass.java
Starting audit...
TestClass.java:2:20: unexpected token: TestClass
TestClass.java:4:41: unexpected token: .
Audit done.

Input is compilable with java 8 javac.

JLS8 calls this a Receiver Parameter in 8.4.1.

ReceiverParameter:
{Annotation} UnannType [Identifier .] this

http://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.4.1-220

http://blog.joda.org/2015/12/explicit-receiver-parameters.html

ATTENTION: Custom Checks need to be aware of new syntax possibilities in parameters, for example of how to fix them easily please look at 40a0b5d

@romani romani changed the title from Java 8 Grammar: missing this parameter to Java 8 Grammar: Parsing of explicit receiver parameters Jun 2, 2016

@romani romani added the bug label Jun 3, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jun 7, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jun 7, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jun 8, 2016

rnveach added a commit to rnveach/checkstyle that referenced this issue Jun 10, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 12, 2016

Member

result tree will be :
public void m4(InputRegressionJava8Class1 this) {}
generate

    |--METHOD_DEF -> METHOD_DEF 
    |   |--MODIFIERS -> MODIFIERS 
    |   |   `--LITERAL_PUBLIC -> public 
    |   |--TYPE -> TYPE 
    |   |   `--LITERAL_VOID -> void 
    |   |--IDENT -> m4 
    |   |--LPAREN -> ( 
    |   |--PARAMETERS -> PARAMETERS 
    |   |   `--PARAMETER_DEF -> PARAMETER_DEF 
    |   |       |--MODIFIERS -> MODIFIERS 
    |   |       |--TYPE -> TYPE 
    |   |       |   `--IDENT -> InputRegressionJava8Class1 
    |   |       `--LITERAL_THIS -> this 
    |   |--RPAREN -> ) 
    |   `--SLIST -> { 
    |       `--RCURLY -> } 

public void m5(@Nullable InputRegressionJava8Class1 this) {}
generate

    |--METHOD_DEF -> METHOD_DEF 
    |   |--MODIFIERS -> MODIFIERS 
    |   |   `--LITERAL_PUBLIC -> public 
    |   |--TYPE -> TYPE 
    |   |   `--LITERAL_VOID -> void 
    |   |--IDENT -> m5 
    |   |--LPAREN -> ( 
    |   |--PARAMETERS -> PARAMETERS 
    |   |   `--PARAMETER_DEF -> PARAMETER_DEF 
    |   |       |--MODIFIERS -> MODIFIERS 
    |   |       |   `--ANNOTATION -> ANNOTATION 
    |   |       |       |--AT -> @ 
    |   |       |       `--IDENT -> Nullable 
    |   |       |--TYPE -> TYPE 
    |   |       |   `--IDENT -> InputRegressionJava8Class1 
    |   |       `--LITERAL_THIS -> this 
    |   |--RPAREN -> ) 
    |   `--SLIST -> { 
    |       `--RCURLY -> } 
Member

romani commented Jun 12, 2016

result tree will be :
public void m4(InputRegressionJava8Class1 this) {}
generate

    |--METHOD_DEF -> METHOD_DEF 
    |   |--MODIFIERS -> MODIFIERS 
    |   |   `--LITERAL_PUBLIC -> public 
    |   |--TYPE -> TYPE 
    |   |   `--LITERAL_VOID -> void 
    |   |--IDENT -> m4 
    |   |--LPAREN -> ( 
    |   |--PARAMETERS -> PARAMETERS 
    |   |   `--PARAMETER_DEF -> PARAMETER_DEF 
    |   |       |--MODIFIERS -> MODIFIERS 
    |   |       |--TYPE -> TYPE 
    |   |       |   `--IDENT -> InputRegressionJava8Class1 
    |   |       `--LITERAL_THIS -> this 
    |   |--RPAREN -> ) 
    |   `--SLIST -> { 
    |       `--RCURLY -> } 

public void m5(@Nullable InputRegressionJava8Class1 this) {}
generate

    |--METHOD_DEF -> METHOD_DEF 
    |   |--MODIFIERS -> MODIFIERS 
    |   |   `--LITERAL_PUBLIC -> public 
    |   |--TYPE -> TYPE 
    |   |   `--LITERAL_VOID -> void 
    |   |--IDENT -> m5 
    |   |--LPAREN -> ( 
    |   |--PARAMETERS -> PARAMETERS 
    |   |   `--PARAMETER_DEF -> PARAMETER_DEF 
    |   |       |--MODIFIERS -> MODIFIERS 
    |   |       |   `--ANNOTATION -> ANNOTATION 
    |   |       |       |--AT -> @ 
    |   |       |       `--IDENT -> Nullable 
    |   |       |--TYPE -> TYPE 
    |   |       |   `--IDENT -> InputRegressionJava8Class1 
    |   |       `--LITERAL_THIS -> this 
    |   |--RPAREN -> ) 
    |   `--SLIST -> { 
    |       `--RCURLY -> } 

romani added a commit that referenced this issue Jun 12, 2016

@romani romani added this to the 7.0 milestone Jun 12, 2016

@romani

This comment has been minimized.

Show comment
Hide comment
@romani

romani Jun 12, 2016

Member

fix is merged

Member

romani commented Jun 12, 2016

fix is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment