How can we skip generated code from Sirius

Please provide

  • Operating system: Windows 11
  • IDE name and version Eclipse 2412
  • SonarQube for Eclipse plugin version: 10.10.0
  • Programming language you’re coding in: Java
  • Is connected mode used:
    • SonarQube Cloud, SonarQube Server, or SonarQube Community Build? (if one of the latter two, which version?): No

And a thorough description of the problem / question:
We have a lot of generated code (we use a lot of Eclipse EMF) and we would like to exclude such generated code from Sirius analysis.

All such code has this javadoc with @generated:

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
*/
@Override
public Object eInvoke(int operationID, EList<?> arguments) throws InvocationTargetException {
	switch (operationID) {
...
}

It should be noted that having a suffix like: @generated NOT tells it that the code has been customized, and thus we would want Sonar to apply to such code.

Is there a facility where a custom regex or something can be applied ? We can’t force it to add a //NOSONAR to every such method.

Thanks
Alain

Hey there.

Generated code should be automatically marked as such, but that typically relies on @Generated actually being marked on the method (like @Override), not in the Javadoc. Do you know why it’s in the Javadoc in this case?

Hi Colin,

In this case the @generated is in the javadoc itself. Here is an example (taken from here)

So it is a bit different.

Alain

Thanks.

From what I gather this is pretty specific to Eclipse EMF (the javadoc-based @Generated annotation). I’m not sure that’s something we want to build into the analyzer (I’m happy to send along the feedback).

With SonarQube, it is possible to Ignore Blocks Within Files, and – say, start ignoring code when you see a @generated tag, and stop when you get to @generated NOT. Is that something that could work for you?

You could share this configuration across the team by configuring it in a SonarQube project and using Connected Mode.

This would, however, rely on a perfect ordering of the code (all added code at the top, as shown in the screenshot you shared).

Colin,

Unfortunately that wouldn’t work. We have no real control on the order of the code and even if we did that would very brittle.

I would really have hoped for an API or a way to use a regex that receives the full method including its javadoc and return a boolean to indicate go/no-go. We have done this in one of our code analysis project a long time ago.

Alain