Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 363019 - [Xtend] support static fields and methods
Summary: [Xtend] support static fields and methods
Status: CLOSED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext (show other bugs)
Version: 2.1.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: M4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 363578 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-11-07 02:36 EST by Sven Efftinge CLA
Modified: 2017-10-17 09:52 EDT (History)
5 users (show)

See Also:
sven.efftinge: juno+


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sven Efftinge CLA 2011-11-07 02:36:50 EST
Some existing frameworks (Play!) require declaration of static methods, also Java requires a static main to start a process. We should allow having that in Xtend.
Comment 1 Moritz Eysholdt CLA 2011-11-11 09:00:23 EST
*** Bug 363578 has been marked as a duplicate of this bug. ***
Comment 2 Moritz Eysholdt CLA 2011-11-14 13:35:42 EST
I've pushed an initial version to 'master'. please review.
Comment 3 Caleb Holt CLA 2011-11-14 14:19:18 EST
(In reply to comment #2)
> I've pushed an initial version to 'master'. please review.

I'm guessing that things pushed to 'master' can be tested by using the nightly update site?(Well if it's nightly, that means I can test it tomorrow using the nightly??)
Comment 4 Moritz Eysholdt CLA 2011-11-14 17:30:34 EST
(In reply to comment #3)
> (In reply to comment #2)
> > I've pushed an initial version to 'master'. please review.
> 
> I'm guessing that things pushed to 'master' can be tested by using the nightly
> update site?(Well if it's nightly, that means I can test it tomorrow using the
> nightly??)

that's right, here you can see which nightly build includes which changes:
https://hudson.eclipse.org/hudson/job/Xtext-nightly-HEAD/changes
Comment 5 Sven Efftinge CLA 2011-11-15 03:16:34 EST
Looks very good. The static methods should be available as extension methods as well.
Comment 6 Moritz Eysholdt CLA 2011-11-15 11:12:28 EST
(In reply to comment #5)
> Looks very good. The static methods should be available as extension methods as
> well.

fixed.
Comment 7 Sebastian Zarnekow CLA 2011-11-15 14:29:28 EST
(In reply to comment #5)
> Looks very good. The static methods should be available as extension methods as
> well.

I think it would be more consistent if we only did this for Xtend, wouldn't it?
Comment 8 Sven Efftinge CLA 2011-11-16 01:57:12 EST
Indeed. Sorry Moritz for not pointing that out.(In reply to comment #7)
> (In reply to comment #5)
> > Looks very good. The static methods should be available as extension methods as
> > well.
> 
> I think it would be more consistent if we only did this for Xtend, wouldn't it?

Indeed. Sorry, Moritz, for not pointing that out earlier.
Comment 9 Sven Efftinge CLA 2011-11-17 03:39:43 EST
In fact (Sebastian already suggested that) if you use Junit 3, and therefore have Assert in your hierarchy you'll get all assert methods proposed as extension methods. That's not so nice.

Although it seems a bit asymmetrical I'm in favor of not having the static methods being put on the scope as extension methods. If people want to have them they can use a static extension import.
Comment 10 Sebastian Zarnekow CLA 2011-11-17 04:16:43 EST
The static methods from the very same class should be on the extension scope, shouldn't they? But we should require an explicit static extension import for the 'inherited' static methods.
Comment 11 Sven Efftinge CLA 2011-11-17 05:07:39 EST
As also the local class can be used in a static extension import, we can completely rely on this for static extensions.
Comment 12 Moritz Eysholdt CLA 2011-11-21 06:38:09 EST
I've applied the following changes to 'master':
- static methods are not implicitly available as extension methods. Instead, a "import static extension" is required.
- added tests for scoping and validation in case of referenced invisible static members.
Comment 13 Sebastian Zarnekow CLA 2011-11-21 07:10:36 EST
The contents of the scopes looks bogus to me for static contexts, e.g.

def static foo() {
	equals(new Object())
}

yields 'Couldn't resolve reference equals(..)' instead of 'Cannot refer to instance member in static context'.
Comment 14 Sven Efftinge CLA 2011-11-24 06:18:41 EST
Static dispatch methods should be possible too.

And we should have validation error if not all dispatch functions are either static or not.
Comment 15 Moritz Eysholdt CLA 2011-11-25 14:07:27 EST
(In reply to comment #13)
> The contents of the scopes looks bogus to me for static contexts, e.g.
> 
> def static foo() {
> equals(new Object())
> }
> 
> yields 'Couldn't resolve reference equals(..)' instead of 'Cannot refer to
> instance member in static context'.

fixed: http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?id=4f52951224af32b806315eaa056c35825e8feb61

(In reply to comment #14)
> Static dispatch methods should be possible too.
> 
> And we should have validation error if not all dispatch functions are either
> static or not.

fixed: http://git.eclipse.org/c/tmf/org.eclipse.xtext.git/commit/?id=dad24be43df84097c9efe3bab4194f25b7ba1b9a

all fixed went to 'master'.

When writing tests I noticed that our syntactic sugar to treat set-method-invocations as assignments 

e.g. 
---
class X { 
	def static setFoo(String x) {} 
	def meth() { foo = '' } 
}
---

doesn't work (failure during linking).

Design-wise I'd prefer to keep it this way, since good coding style suggests that static methods are pure methods. Invoking a method using assignment-syntax, however, looks like the assigned state is going to be kept somewhere, i.e. the method is not pure.

Expressed differently, foo = 1  with foo being static only makes sense if setFoo(int) sets a global singleton value.
Comment 16 Sven Efftinge CLA 2011-11-25 15:01:42 EST
That's ok for now.
Comment 17 Karsten Thoms CLA 2017-09-19 17:11:38 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 18 Karsten Thoms CLA 2017-09-19 17:23:12 EDT
Closing all bugs that were set to RESOLVED before Neon.0