Move Method Refactoring in Eclipse, programmatically, with MoveInstanceMethodProcessor cannot find a target - refactoring

I am trying to automate refactoring tasks. While some refactoring tasks work with reusage of refactoring API (LTK and JDT-based), Move Method doesn't. Am I missing something with this code:
MoveInstanceMethodProcessor processorMM = new MoveInstanceMethodProcessor(method,null);
processorMM.setTargetName(method.getDeclaringType().toString());
IVariableBinding[] candidateTargets = processorMM.getCandidateTargets();
IVariableBinding[] targets= processorMM.getPossibleTargets();
processorMM.setTarget(targets[1]);
MoveRefactoring refactoringMM = new MoveRefactoring(processorMM);
RefactoringStatus statusMM = refactoringMM.checkAllConditions(monitor);
Change changeMM = refactoringMM.createChange(monitor);
undoChange = changeMM.perform(monitor);
These candidateTargets and targets are always empty, and no possible target can be found even if I loop through the all methods in the project. Some method can be moved manually, but my code doesn't find them.
Am I missing something? What is the proper way of getting target for Move Method refactoring?
NOTE: I want to avoid, as much as possible, writing my own code for anything that I can feel is already there.

Related

Bundleconfig (seemingly) not creating requested .js files

We have a large solution with a number of files being created by bundleconfig.cs. But for some reason the last two projects added to the solution don't seem to be getting the files creating. The pages that use them fail cause they aren't there, or not being found.
Example of project successfully getting the files created:
const string ANGULAR_APP_ROOT_EDI = "~/app/ediViewer/";
const string VIRTUAL_BUNDLE_PATH_EDI = ANGULAR_APP_ROOT_EDI + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI)
.Include(ANGULAR_APP_ROOT_EDI + "ediViewerApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI, "*.js", searchSubdirectories: true)
);
Example of one that's not:
const string ANGULAR_APP_ROOT_EDI_SC = "~/app/SupplyChain/";
const string VIRTUAL_BUNDLE_PATH_EDI_SC = ANGULAR_APP_ROOT_EDI_SC + "main.js";
bundles.Add(
new ScriptBundle(VIRTUAL_BUNDLE_PATH_EDI_SC)
.Include(ANGULAR_APP_ROOT_EDI_SC + "SupplyChainApp.js")
.IncludeDirectory(ANGULAR_APP_ROOT_EDI_SC, "*.js", searchSubdirectories: true)
);
very similar, both Angular(js) projects with similar directory structures. but the second one gets no files. I have other projects with a similar structure that are working.
I was hoping there was a way to put breakpoints in the bundleconfig file to see if if it was hitting the code, but apparently you can't, or I didn't successfully set one up.
There are a number of bundles appearing after the new one (the standard Angular libraries) that are getting created, so it doesn't appear to be stopping in the middle or anything.
The workaround was I simply added the scripts needed manually to the aspx page, but I shouldn't have to. It's happened for two new projects so far, so I'm prepared to bet it may happen for a third, so if I can find a fix it'd be useful.
Any ideas what might be happening, or how I can troubleshoot it?

How to rename all symbols using Roslyn?

I'm building a Standalone app which will load a folder with c# code, and allow the user to write Regex to select and rename namespace/types/fields/properties/methods/argument/variable/events'name, but i'm stuck at renaming source code.
I have analyzed the SyntaxTree and collected all items, and also searched/matched/renamed with regex.
I have done a plenty of codes trying to get roslyn rename "items", but i only the first "item" is renamed while all the next ones are discarded.
I am aware of Immutability of the Syntax API, and after calling Renamer I save the solution, and also re-search the document in the new solution in the next loop.
//renaming code
var newSolution = await Renamer.RenameSymbolAsync(solution, isymbol, newName, solution.Workspace.Options).ConfigureAwait(false);
this.solution = newSolution;
//re-search code
if (solution.Projects.First ().ContainsDocument(doc.Document.Id)) {
var document = project.GetDocument(doc.Document.Id);
...
}
At the end i call SyntaxTree.GetRoot().ToString (); to get the final edited code, which as mentioned above has only the first edit.
Could anyone explain me the correct way to do this or provide me a sample how this could be implemented so i can try on my own?

Language Service: ParseReason.Check never called after migrating to VS2010

I just migrated my language service from VS2008 to VS2010. Everything works fine except for one important thing: I no longer get LanguageService.ParseSource invoked for ParseReason.Check. It do get a single invoke after opening a file. But after editing code, it no longer gets invoked.
Any ideas what could be causing that?
I also migrated a language service from 2008 to 2010. Can you check if you've fallowed all of these steps?
http://msdn.microsoft.com/en-us/library/dd885475.aspx
I didn't have to do anything else, which I verified by diffing the important files in our depot before and after the change.
I don't know if you ever figured your question out, but have you tried making sure that your Source class' LastParseTime is set to 0 when creating it? I seem to recall some issues with Check not happening unless you manually set LastParseTime to 0 when creating your Source object.
Protip: If you use .NET Reflector, you can disassemble all of the base classes for the LanguageService framework and get a pretty good understanding of how it all works under the hood. The classes you'd be interested in live in Microsoft.VisualStudio.Package.LanguageService.10.0.dll, which should be installed in the GAC. I've found this to be unimaginably helpful when trying to figure out why things weren't working in my own Language Service, and being able to step through the source code in the debugger mitigates almost all the pain of working with these frameworks!
When your Source object is initialized, it starts off with a LastParseTime of Int32.MaxValue. The code that causes fires off a ParseRequest with ParseReason.Check checks the LastParseTime value to see if the time since the last change to the text is less than the time it takes to run a parse (or the CodeSenseDelay setting, whichever is greater).
The code that handles the response from ParseSource is supposed to set the LastParseTime, but as far as I can tell, it only does that if the ParseReason is Check.
You can get around this issue by setting Source.LastParseTime = 0 when you initialize your Source. This has the side-effect of setting CompletedFirstParse to true, even if the first parse hasn't finished yet.
Another way to fix this issue is to override Source.OnIdle to fire off the first call to BeginParse() This is the way I would recommend.
public override void OnIdle(bool periodic)
{
// Once first "Check" parse completes, revert to base implementation
if (this.CompletedFirstParse)
{
base.OnIdle(periodic);
}
// Same as base implementation, except we don't check lastParseTime
else if (!periodic || this.LanguageService == null || this.LanguageService.LastActiveTextView == null || (this.IsCompletorActive) || (!this.IsDirty || this.LanguageService.IsParsing))
{
this.BeginParse();
}
}

Interactively execute code while debugging in Scala

Is there a method for inserting code into a Scala application while debugging? For example, could I have something like this,
var c = 1.0
0.until(10).foreach{ i =>
if (i == 5) {
startDebuggingMagicHere()
}
}
where I could then inspect and interact with c, i, and any other variable in scope via methods and assignment.
In the Scala-IDE plugin for Eclipse, debugging is supported. Set a breakpoint in the Scala code and you will be able to do limited things. Current support is not as good as that for Java. I believe it is planned to improve by the Summer.
What you can do is:
use the "variables" view to see the current values of variables and modify values,
tell the debugger to "drop to frame" so that it starts the current method call again, using the original values from the stack,
modify code and save the file which causes the debugger to insert the new code and drop to frame, i.e. restart the method call (this does not always work - depending how much you change the code you may need to restart the app, e.g. if you change the class definition)
What you can't do is:
inspect variables from the editor,
write code in the "display" view and execute it. Both of these work with Java, but not Scala.

Programatically moving through a ListView in Qt (Ruby)

I'm making a small file-browser for my own use, in Ruby, and using Qt for the view. The idea is that it'll end up on my TV, where I can use the remote to move up and down and launch files.
Everything works fine, until I'm going to move the selection using the remote. I managed to set up a D-Bus service, so I'll just call the methods using LIRC.
The code I'm using for setting up the view looks like this:
#dm = Qt::DirModel.new
#sm = Qt::ItemSelectionModel.new(#dm)
#lv = Qt::ListView.new
#lv.model = #dm
#lv.selectionModel = #sm
cwd = #dm.index(#dir)
#lv.rootIndex = cwd
And then I'm unsure how to change the selection. Think I must have tried about every setIndex, setSelection and every method sounding similar, on the DirModel, ItemSelectionModel and ListView, without any luck. I've been googling and reading through the API without finding anything.
Ideally, I would have something like "moveSelectionDown" and "moveSelectionUp" that takes care of it, and making sure it wraps around correctly. But I can't seem to find anything.
Managed to fix it through the ItemSelectionModel every view apparently has.
moving up:
curIndex = #lv.currentIndex
#lv.selectionModel.setCurrentIndex(curIndex.sibling(curIndex.row-1, 0), Qt::ItemSelectionModel::ClearAndSelect)
or adding one to move down
I think you're forgetting that you have to create the ModelIndex through your model:
#dm.index(3, 0, None)
I'd try this method (Though I'm not really sure, this deselects the other cells.)
#lv.setCurrentIndex(#dm.index(3, 0, None))
I haven't used Ruby for ages, so I'm not exactly sure there's None.

Resources