Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8835

AstNodeToScriptVisitor - no token needed for EmptyStatement initialization

    XMLWordPrintableJSON

Details

    Description

      Consider the following example:

      package groovy
      
      import groovy.inspect.swingui.AstNodeToScriptVisitor
      import org.codehaus.groovy.ast.expr.EmptyExpression
      import org.codehaus.groovy.ast.tools.GeneralUtils
      
      class SandBox {
      
          static void main(String[] args) {
              new SandBox().someMethod()
          }
      
          void someMethod() {
              StringWriter stringWriter = new StringWriter()
              GeneralUtils.declS(GeneralUtils.varX("someVariableName"), new EmptyExpression()).visit(new AstNodeToScriptVisitor(stringWriter))
              System.out.println("Output: "+stringWriter.getBuffer().toString().replace("\$", ""))
          }
      
      }
      

      Actual result:

      Output: java.lang.Object someVariableName = 
      

      Expected result:

      Output: java.lang.Object someVariableName
      

      When DeclarationExpression (or possibly other BinaryExpression) is initialized with EmptyExpression as "right" expression, AstNodeToScriptVisitor should not output the token ("=" in this example), as there is no corresponding expression printed after the token.

      Attachments

        Activity

          People

            paulk Paul King
            anton.pryamostanov Anton Pryamostanov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: