Maven 2.x JavaNCSS Plugin

java annotations (within a method) cannot be parsed correctly

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0-beta-2
  • Fix Version/s: 2.0
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

the following code segment cannot be parsed correctly:

public int myMethod()
{
int i = 1;

@SuppressWarnings("unused")
int notUsedVariable = 2;

return i;
}

leads to following error:

Encountered "@ SuppressWarnings ( \"unused\" ) int notUsedVariable =" at line xxx, column yyy.

Was expecting one of:
"assert" ...
"boolean" ...
"byte" ...
"char" ...
"double" ...
"enum" ...
"final" ...
"float" ...
"int" ...
"long" ...
"short" ...
...
"public" ...
"static" ...
"protected" ...
"private" ...
"abstract" ...
"synchronized" ...
"native" ...
"transient" ...
"volatile" ...
"strictfp" ...
"@" "enum" ...
"@" "." ...
"@" "(" ...
"@" "(" ")" ...
"@" "(" "@" ...
"@" "(" "{" ...
"@" "(" "+" ...
"@" "(" "-" ...
"@" "(" "++" ...
"@" "(" "--" ...
"@" "(" "~" ...
"@" "(" "!" ...
"@" "(" "(" ...
"@" "(" ...
"@" "(" ...
"@" "(" ...
"@" "(" "." ...
"@" "(" "[" ...
"@" "(" "(" ...
"@" "(" "++" ...
"@" "(" "--" ...
"@" "(" "*" ...
"@" "(" "/" ...
"@" "(" "%" ...
"@" "(" "+" ...
"@" "(" "-" ...
"@" "(" "<<" ...
"@" "(" ">>" ...
"@" "(" ">>>" ...
"@" "(" "<" ...
"@" "(" ">" ...
"@" "(" "<=" ...
"@" "(" ">=" ...
"@" "(" "instanceof" ...
"@" "(" "==" ...
"@" "(" "!=" ...
"@" "(" "&" ...
"@" "(" "^" ...
"@" "(" "|" ...
"@" "(" "&&" ...
"@" "(" "||" ...
"@" "(" "?" ...
"@" "(" ")" "public" ...
"@" "(" ")" "static" ...
"@" "(" ")" "protected" ...
"@" "(" ")" "private" ...
"@" "(" ")" "final" ...
"@" "(" ")" "abstract" ...
"@" "(" ")" "synchronized" ...
"@" "(" ")" "native" ...
"@" "(" ")" "transient" ...
"@" "(" ")" "volatile" ...
"@" "(" ")" "strictfp" ...
"@" "(" ")" "@" ...
"@" "(" ")" "boolean" ...
"@" "(" ")" "char" ...
"@" "(" ")" "byte" ...
"@" "(" ")" "short" ...
"@" "(" ")" "int" ...
"@" "(" ")" "long" ...
"@" "(" ")" "float" ...
"@" "(" ")" "double" ...
"@" "(" ")" "enum" ...
"@" "(" ")" "." ...
"@" "(" ")" "<" ...
"@" "(" ")" "[" ...
"@" "(" ")" "enum" ...
"@" "(" ")" ";" ...
"@" "(" ")" "=" ...

Issue Links

Activity

Hide
Jean-Laurent de Morlhon added a comment -

Thanks for the report.
Unfortunatly, as of today, we can't do much since the problem lies within javancss core library, beside sending a bug report to the original author of javancss : http://www.kclee.de/clemens/java/javancss/
Btw we are using the latest available version of it (28.49).

Show
Jean-Laurent de Morlhon added a comment - Thanks for the report. Unfortunatly, as of today, we can't do much since the problem lies within javancss core library, beside sending a bug report to the original author of javancss : http://www.kclee.de/clemens/java/javancss/ Btw we are using the latest available version of it (28.49).
Hide
Peter Franzen added a comment -

I stumbled upon this bug report while searching the Web for a solution to the problem with JavaNCSS and
annotations inside a method. When I didn't find any solution out there, I tried modifying the JavaCC grammar
used by JavaNCSS found in the file Java1.1.jj. Haven't done much testing yet, but these modifications solved
my problem, which was similar to the example in the description.

I don't use the Maven plugin, but run JavaNCSS as a standalone tool as part of my build process.
However, perhaps my modifications will work for the Maven plugin, or at least be a starting point
for resolving this issue.

I've attached a diff between the version of Java1.1.jj found in the JavaNCSS 28.49 distribution
and my modifications.

Show
Peter Franzen added a comment - I stumbled upon this bug report while searching the Web for a solution to the problem with JavaNCSS and annotations inside a method. When I didn't find any solution out there, I tried modifying the JavaCC grammar used by JavaNCSS found in the file Java1.1.jj. Haven't done much testing yet, but these modifications solved my problem, which was similar to the example in the description. I don't use the Maven plugin, but run JavaNCSS as a standalone tool as part of my build process. However, perhaps my modifications will work for the Maven plugin, or at least be a starting point for resolving this issue. I've attached a diff between the version of Java1.1.jj found in the JavaNCSS 28.49 distribution and my modifications.
Hide
Peter Franzen added a comment -

Diff to apply to Java1.1.jj in the JavaNCSS 28.49 distribution

Show
Peter Franzen added a comment - Diff to apply to Java1.1.jj in the JavaNCSS 28.49 distribution
Hide
Simon Brandhof added a comment -

Peter, did you try the 29.50 version of JavaNCSS released two days ago ? It also fixes Java5 parser bugs.

Show
Simon Brandhof added a comment - Peter, did you try the 29.50 version of JavaNCSS released two days ago ? It also fixes Java5 parser bugs.
Hide
Peter Franzen added a comment -

Hmmm, I checked for a new version a few days ago before deciding to have a go at it myself....oh, well.

It looks like version 29.50 fixes the problem, although there is no difference between the grammar
files in the 28.49 and 29.50 distributions as far as I can tell.

I also discovered that my proposed fix is a bit too liberal, it accepts constructs of the type

private void myMethod()

{ java.util.List<String> s; @SuppressWarnings("unchecked") s = getList(); }

which I don't think is allowed after having studied JLS a bit more thoroughly. If the first
part of the diff is removed, i.e.

2210a2211,2212
> |
> Annotation()

the above construct no longer parses.

Show
Peter Franzen added a comment - Hmmm, I checked for a new version a few days ago before deciding to have a go at it myself....oh, well. It looks like version 29.50 fixes the problem, although there is no difference between the grammar files in the 28.49 and 29.50 distributions as far as I can tell. I also discovered that my proposed fix is a bit too liberal, it accepts constructs of the type private void myMethod() { java.util.List<String> s; @SuppressWarnings("unchecked") s = getList(); } which I don't think is allowed after having studied JLS a bit more thoroughly. If the first part of the diff is removed, i.e. 2210a2211,2212 > | > Annotation() the above construct no longer parses.
Hide
Arnaud added a comment -

Like i see the "Fix Version/s: 2.0-beta-3 "

I tri the 2.0-beta-3-Snapchot but it doen't work...

it is normaly ?

Show
Arnaud added a comment - Like i see the "Fix Version/s: 2.0-beta-3 " I tri the 2.0-beta-3-Snapchot but it doen't work... it is normaly ?
Hide
Mathias Brökelmann added a comment - - edited

this issue is actually fixed in JavaNCSS Version 29.50

I was able to override the dependency from plugin pom:

<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javancss-maven-plugin</artifactId>
                <version>2.0-beta-2</version>
                <dependencies>
                    <dependency>
                        <groupId>javancss</groupId>
                        <artifactId>javancss</artifactId>
                        <version>29.50</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javancss-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
</project>
Show
Mathias Brökelmann added a comment - - edited this issue is actually fixed in JavaNCSS Version 29.50 I was able to override the dependency from plugin pom:
<project>
    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javancss-maven-plugin</artifactId>
                <version>2.0-beta-2</version>
                <dependencies>
                    <dependency>
                        <groupId>javancss</groupId>
                        <artifactId>javancss</artifactId>
                        <version>29.50</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>javancss-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </reporting>
</project>
Hide
Herve Boutemy added a comment -

good workaround, Mathias

in addition, actual javancss-maven-plugin trunk has been upgraded to JavaNCSS 30.51, which supports such annotations
And I added an IT test in r9756 to confirm everything is ok now

Show
Herve Boutemy added a comment - good workaround, Mathias in addition, actual javancss-maven-plugin trunk has been upgraded to JavaNCSS 30.51, which supports such annotations And I added an IT test in r9756 to confirm everything is ok now

People

Vote (22)
Watch (12)

Dates

  • Created:
    Updated:
    Resolved: