Bug 357260 - Can't use @EventListener when the function is a member of a local variable
Summary: Can't use @EventListener when the function is a member of a local variable
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: EDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-09 12:26 EDT by Matt Heitz CLA
Modified: 2017-02-23 14:16 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Matt Heitz CLA 2011-09-09 12:26:37 EDT
I'm opening this bug so we don't lose track of a problem I found while implementing @EventListener.  I can't fix it right now.

Code generated from the program and handler below will not compile.  The problem is in the Delegate we create during generation of the line "b.zit = elh.x;".  The variable elh is a local variable that's not final, and we're using it within an inner class.  That's not allowed in Java.


--- File #1 ELHandler.egl

package x;

handler ELHandler
	function x( e ActionEvent in )
		SysLib.writeStdout( "[Handler] The button was clicked!" );
	end
end

--- File #2 EL.egl

package x;

program EL
	
	function main()
		b Button = new Button( "Click me" );
		b.zit = x;

		f Frame = new Frame( "Hi!" );
		f.addx( b );
		f.pack();
		f.setLocationByPlatform( true );
		f.setVisible( true );
		
		for ( i int from 5 to 1 decrement by 1 )
			SysLib.writeStdout( "..." :: i :: "..." );
			SysLib.wait( 1 );
		end

		elh ELHandler;
		b.zit = elh.x;
		for ( i int from 5 to 1 decrement by 1 )
			SysLib.writeStdout( "..." :: i :: "..." );
			SysLib.wait( 1 );
		end
	end
	
	function x( e ActionEvent in )
		SysLib.writeStdout( "[Program] The button was clicked!" );
	end
end

delegate act( e ActionEvent in ) end

externalType Button type JavaObject { packageName = "java.awt" }
	constructor( name String in );
	zit act { @EventListener{ addMethod = "addActionListener", listenerType = "java.awt.event.ActionListener", method = "actionPerformed" } };
end

externalType ActionEvent type JavaObject { packageName = "java.awt.event" }
end

externalType Frame type JavaObject { packageName = "java.awt" }
	constructor( name String in );
	function pack();
	function setVisible(b boolean in);
	function addx( b Button in ) { externalName = "add" };
	function setLocationByPlatform(b boolean in);
end