Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 364687

Summary: [Xtend] Add create method quickfix
Product: [Tools] Xtend Reporter: Steve Ash <stevemash>
Component: CoreAssignee: Holger Schill <Holger.Schill>
Status: CLOSED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: Holger.Schill, sven.efftinge
Version: 2.2.0Flags: sven.efftinge: juno+
Target Milestone: M7   
Hardware: PC   
OS: Windows 7   
Whiteboard:

Description Steve Ash CLA 2011-11-24 03:54:06 EST
Build Identifier: 

Currently the xtend editor doesn't support the "create method" refactoring as the java editor does.

For example, assume I'm creating a class like:

1 class ZombieScout {
2    
3   def scout() {
4      val zombiesFound = isZombiesHere();
5      if (zombiesFound) {
6         startShooting();
7      }
8   }
9}

So as I'm typing (at my highest business-ey level of abstraction) and I get to
line #4 no method names isZombiesHere exists.  In the java editor, I almost
without thinking just hit ctrl+1 and it offers me a quick-fix of "create method
isZombiesHere()" which I hit enter, and then it invokes the template allowing
me to fill in the param types and names and return types or accept the
defaults.  Same would be true of line #6 as well.  Then once I have my high
level scout() method, I go flesh out the private helper isZombiesHere() and
startShooting() methods.

This is a pretty big deal for me because I just do it all the time, but maybe
that's not very typical.

This was on the list of top 15 refactorings as discussed on Bug 364678

Reproducible: Always
Comment 1 Holger Schill CLA 2012-04-23 05:54:11 EDT
After having a look at JDT I see that templateProposals are used there. Is this also a way to go for us or should we keep it simple and suggest the most common signature for a function.

Next is that JDT inferres the returnType of a possible mothod by looking at the context of the call. I think we could do this too.

Any opinions?
Comment 2 Sven Efftinge CLA 2012-04-23 10:59:05 EDT
Having templates is very cool and desirable. 
But if that is much more work, it's a good idea to start with a working but simpler version first.
Comment 3 Holger Schill CLA 2012-04-25 11:21:26 EDT
Now we have a quickfix to add a method or a field. Depending on the context both can be valid. 
There is quickfix to create a field when there are no parameters in the FeatureCall.

pushed first shot to master. Please review.

Thought about adding quickfixes for following szenario:

class Type {

def foo(OtherType it){
   ->  bar
}

}

bar could be a method or field in Type ot OtherType.

To achieve this we could not use the infrastructure that is currently there because it relies on documentChanges and we do not have a document for OtherType. The XtextResource could handle replacements by offset but this implies much more effort. I have no feeling if we should spent the time for such a szenario.
Any opinion?
Comment 4 Holger Schill CLA 2012-04-26 05:35:16 EDT
Removed usage of TypeProvider in LinkingDiagnosticMessageProvider
Comment 5 Holger Schill CLA 2012-04-26 10:45:41 EDT
Added support to create local vars if expectedType is not null.
The same constraint it there for field creation now.
New function will take care that typeParameters are declared correctly.

Regarding the errormessage Sebastian is currently working on a common solution so that we will have an other bug to enhance the errormessage after Sebastian finished his work. https://bugs.eclipse.org/bugs/show_bug.cgi?id=377775

pushed to master.

Mark this as fixed.
Comment 6 Eclipse Webmaster CLA 2017-10-31 11:04:54 EDT
Requested via bug 522520.

-M.
Comment 7 Eclipse Webmaster CLA 2017-10-31 11:16:16 EDT
Requested via bug 522520.

-M.