Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » [Xtend2] anonymous inner classes
[Xtend2] anonymous inner classes [message #683914] Tue, 14 June 2011 16:34 Go to next message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Hi, I'm having trouble with the syntax for an anonymous inner class in Xtend2.

Here's the java code:
      Predicate<IEObjectDescription> filter = new Predicate<IEObjectDescription>(){
    	  public boolean apply(IEObjectDescription input) {
			return false;
    	  }
      };


This is my current attempt, but it's failing on several levels:
	val filter = new Predicate<IEObjectDescription>(){
		def apply(IEObjectDescription input) {
			return false
		}
	}


I couldn't find any examples of this in the Xtend2 tutorials.

Thanks!
Re: [Xtend2] anonymous inner classes [message #683965 is a reply to message #683914] Tue, 14 June 2011 19:00 Go to previous message
Joel Denton is currently offline Joel DentonFriend
Messages: 18
Registered: May 2011
Junior Member
Never mind, I entirely missed the idea of using a closure here. Here's the java code I was initially trying to duplicate:
filteredScope = new FilteringScope(scope,
        new Predicate<IEObjectDescription>() {			
            public boolean apply(IEObjectDescription input) {
                return input.getEObjectOrProxy() instanceof Entity;
            };
        });


And here's the Xtend2 that works.
val filteredScope = new FilteringScope(scope, [input | input.EObjectOrProxy instanceof Entity])


Still getting used to closures, but very nice!
Previous Topic:Migrating Name Provider Function to Xtext 2.0
Next Topic:Deprecated referencedGenModels
Goto Forum:
  


Current Time: Sat Apr 27 03:19:24 GMT 2024

Powered by FUDForum. Page generated in 0.02861 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top