Skip to content

AST nodes for an empty script contains incorrect line & column numbers in Eclipse #252

@darxriggs

Description

@darxriggs

Issue

For the following empty script the line & column numbers are incorrect for the MethodNode and BlockStatement of the generated run method. The values are correct for the generated main method.

Issue.groovy:

package com.example

Behaviour

Actual

The AST value in Eclipse for lineNumber, lastLineNumber, columnNumber and lastColumnNumber is different than for Groovy on the commandline.

Expected

The AST value in Eclipse for lineNumber, lastLineNumber, columnNumber and lastColumnNumber is -1 (the same as for Groovy on the commandline).

Steps to reproduce

In "Groovy AST Viewer" (Eclipse)

  • open file Issue.groovy
  • open "Window -> Show View -> Groovy -> Groovy AST Viewer"
  • inside "Groovy AST Viewer" open "classes -> com.example.Issue -> methods -> org.codehaus.groovy.ast.MethodNode-run"

In Groovy Console (Eclipse and commandline)

  • run "groovyConsole" on Issue.groovy
    • in Eclipse: right mouse button on Issue.groovy -> "Run As -> Groovy Console"
    • on commandline: groovyConsole Issue.groovy
  • inside "Groovy Console" select "Script -> Inspect Ast"
  • inside "Groovy AST Browser" select "ClassNode -> Methods -> MethodNode - run"

Environment

Tested in Eclipse

  • Eclipse Mars 4.5.2 + Groovy-Eclipse 2.9.2.xx-201701010228-e45 (Groovy 2.0.8 / 2.1.9 / 2.2.2 / 2.3.11 / 2.4.7)
  • Eclipse Indigo 3.7 + Groovy-Eclipse 2.9.1.xx-201411061404-e37-RELEASE (Groovy 2.0.7 / 2.1.8 / 2.2.2 / 2.3.7)

Tested on commandline

  • Groovy 2.3.7 / 2.4.7

Details

When running groovyConsole from commandline the values in question are:

MethodNode - run

  • lineNumber: -1
  • lastLineNumber: -1
  • columnNumber: -1
  • lastColumnNumber: -1
  • code: BlockStatement
    • lineNumber: -1
    • lastLineNumber: -1
    • columnNumber: -1
    • lastColumnNumber: -1

When running groovyConsole from Eclipse and selecting "MethodNode - run" the UI throws this exception:

Exception in thread "AWT-EventQueue-0" 
java.lang.IllegalArgumentException: bad position: 20
	at javax.swing.text.JTextComponent.setCaretPosition(JTextComponent.java:1678)
	at javax.swing.text.JTextComponent$setCaretPosition$0.call(Unknown Source)
	at groovy.inspect.swingui.AstBrowser$_run_closure5.doCall(AstBrowser.groovy:218)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
	at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
	at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
	at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1024)
	at groovy.lang.Closure.call(Closure.java:414)
	at org.codehaus.groovy.runtime.ConvertedClosure.invokeCustom(ConvertedClosure.java:54)
	at org.codehaus.groovy.runtime.ConversionHandler.invoke(ConversionHandler.java:124)
	at com.sun.proxy.$Proxy10.valueChanged(Unknown Source)
	at javax.swing.JTree.fireValueChanged(JTree.java:2924)
	at javax.swing.JTree$TreeSelectionRedirector.valueChanged(JTree.java:3383)
	at javax.swing.tree.DefaultTreeSelectionModel.fireValueChanged(DefaultTreeSelectionModel.java:634)
	at javax.swing.tree.DefaultTreeSelectionModel.notifyPathChange(DefaultTreeSelectionModel.java:1092)
	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPaths(DefaultTreeSelectionModel.java:293)
	at javax.swing.tree.DefaultTreeSelectionModel.setSelectionPath(DefaultTreeSelectionModel.java:187)
	at javax.swing.JTree.setSelectionPath(JTree.java:1631)
	at javax.swing.plaf.basic.BasicTreeUI.selectPathForEvent(BasicTreeUI.java:2393)
	at javax.swing.plaf.basic.BasicTreeUI$Handler.handleSelection(BasicTreeUI.java:3609)
	at javax.swing.plaf.basic.BasicTreeUI$Handler.mousePressed(BasicTreeUI.java:3548)
	at java.awt.Component.processMouseEvent(Component.java:6513)
	at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
	at java.awt.Component.processEvent(Component.java:6281)
	at java.awt.Container.processEvent(Container.java:2229)
	at java.awt.Component.dispatchEventImpl(Component.java:4872)
	at java.awt.Container.dispatchEventImpl(Container.java:2287)
	at java.awt.Component.dispatchEvent(Component.java:4698)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
	at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4489)
	at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
	at java.awt.Container.dispatchEventImpl(Container.java:2273)
	at java.awt.Window.dispatchEventImpl(Window.java:2719)
	at java.awt.Component.dispatchEvent(Component.java:4698)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:747)
	at java.awt.EventQueue.access$300(EventQueue.java:103)
	at java.awt.EventQueue$3.run(EventQueue.java:706)
	at java.awt.EventQueue$3.run(EventQueue.java:704)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
	at java.awt.EventQueue$4.run(EventQueue.java:720)
	at java.awt.EventQueue$4.run(EventQueue.java:718)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:717)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)

That's because some AST values are not valid.

The values can be examined inside "Groovy AST Viewer":

MethodNode - run

  • lineNumber: 1
  • lastLineNumber: 1
  • columnNumber: 21
  • lastColumnNumber: 10
  • start: 20
  • end: 20
  • code: BlockStatement
    • lineNumber: 1
    • lastLineNumber: 1
    • columnNumber: 21
    • lastColumnNumber: 10
    • start: 20
    • end: 20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions