integrated-application-development / sonar-delphi

Delphi language plugin for SonarQube
GNU Lesser General Public License v3.0
92 stars 13 forks source link

Differente between 'return context' and 'return super.visit(variable, context)' #256

Closed EduardoVaz06 closed 3 months ago

EduardoVaz06 commented 3 months ago

Prerequisites

Inquiry

I don't have much experience with Java, so while I was creating custom rules, I couldn't understand 100% the difference between using 'return super.visit(variable, context)' and only 'return context'. If anyone could clarify it, i would be glad.

Cirras commented 3 months ago

Hi @EduardoVaz06,

The default visit implementation simply visits all children of the node, which is how the entire AST tree is traversed. So when you call super.visit(variable, context), that's what you're doing.

When you simply return context without calling the super method, you're doing an early-exit on that traversal and skipping visiting the children of the node.

EduardoVaz06 commented 3 months ago

Got it! Thank you!

It is actually exactly what I thought.