Issue Details (XML | Word | Printable)

Key: MJNCSS-16
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Herve Boutemy
Reporter: Roman Cerny
Votes: 22
Watchers: 12
Operations

If you were logged in you would be able to see more operations.
Maven 2.x JavaNCSS Plugin

java annotations (within a method) cannot be parsed correctly

Created: 21/Jun/07 03:34 AM   Updated: 21/May/09 08:25 AM   Resolved: 21/May/09 08:25 AM
Return to search
Component/s: None
Affects Version/s: 2.0-beta-2
Fix Version/s: 2.0

Time Tracking:
Not Specified

File Attachments: 1. Text File Java1.1.jj.diff.txt (0.2 kB)

Issue Links:
Related
 
dependent
 


 Description  « Hide

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" ...
"@" "(" ")" ";" ...
"@" "(" ")" "=" ...



Jean-Laurent de Morlhon added a comment - 21/Jun/07 04:39 AM

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).


Jean-Laurent de Morlhon made changes - 21/Jun/07 04:39 AM
Field Original Value New Value
Fix Version/s 2.0-beta-3 [ 13131 ]
Peter Franzen added a comment - 10/Apr/08 04:35 AM

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.


Peter Franzen added a comment - 10/Apr/08 04:36 AM

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


Peter Franzen made changes - 10/Apr/08 04:36 AM
Attachment Java1.1.jj.diff.txt [ 33776 ]
Simon Brandhof added a comment - 10/Apr/08 04:44 AM

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


Jean-Laurent de Morlhon made changes - 10/Apr/08 05:00 AM
Link This issue is related to MJNCSS-28 [ MJNCSS-28 ]
Peter Franzen added a comment - 10/Apr/08 06:10 AM

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.


Jean-Laurent de Morlhon made changes - 22/May/08 02:35 AM
Fix Version/s 2.0-beta-3 [ 13131 ]
Arnaud added a comment - 30/May/08 03:29 AM

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 ?


Mathias Brökelmann added a comment - 05/Jun/08 04:03 AM - 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>

Jean-Laurent de Morlhon made changes - 31/Jul/08 03:27 PM
Link This issue depends upon JAVANCSS-4 [ JAVANCSS-4 ]
Herve Boutemy added a comment - 21/May/09 08:25 AM

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


Herve Boutemy made changes - 21/May/09 08:25 AM
Assignee Jean-Laurent de Morlhon [ jeanlaurent ] Herve Boutemy [ hboutemy ]
Resolution Fixed [ 1 ]
Status Open [ 1 ] Closed [ 6 ]