Exclude comments and strings while refactoring with Android Studio - android-studio

Rename Method re-factoring not only rename the variables but anywhere including comments (it can not be sure if string in comments is really variable name).
For example:
class ABC{
private String username;
private void X(){
String str = "username";
}
}
Now, after renaming the class member username, Android Studio will Behave like:
class ABC{
private String mUsername;
private void X(){
String str = "mUsername"; // it should be remain same as String str = "username";
}
}
Is there any way to change the Re-factoring Setting in Android Studio?

After a struggle, i got the solution.
During re-factoring/renaming the variable/member, it will display a popup. In this popup, you will see a sentence
"Press Shift+F6 to show dialog with more options"
Now if you will press "Shift+F6", a dialog will open for Re-factor-Setting.
Here, un-check "Search in comments and strings" .. Thats it..
Thanks for replies..

Taken from the link here:
Renaming of packages, classes, methods, fields, method parameters and
local variables with reference correction
The renaming functionality
allows you to rename any package, class, method or variable and
automatically finds and corrects all references to it. Before
renaming, you can preview all references in a convenient tree-view,
where you have an opportunity to select usages/references to be
renamed. For any item being refactored, it is also possible to search
for its name occurrences in strings and comments, so that the
commented code is also changed and kept up-to-date. The Rename
refactoring can be invoked from any view (Project, Source, Commander
and Structure), as well as directly from the editor.

In my version of Android Studio (2.2 RC 2) when I highlight a variable, right click and choose :
Refactor > Rename
this option pops up, then you can edit the rating text to whatever you want :
Rename code occurrences : it renames all usages of the variable named rating, throughout my project.
Rename all ocurrences : it renames the word rating (code, comments etc) throughout my project.

Related

PHPStorm: 'Go to declaration' on class names in string literals

I'm using PHPStorm EAP version PS-138.940.
I have code as follows:
Config(__NAMESPACE__."\ObjectsToIdentifiers")->oldTables = array('Modules\Old\Model\DeviceStock','Modules\Old\Model\ProductPack','Modules\Old\Model\SpareStock','Modules\Old\Model\ConsumStock');
The functionality is irrelevant in this case. Important are the entries in the array. These are fully qualified class names - the leading / is omitted, but adding it doesn't solve my problem. I want to be able to click inside one of the string literals, press Ctrl+B and be redirected to the class definition.
Note that this works in ExtJS (javascript framework) where a string literal like
"MyApp.namespace.view.MyComponent"
will take me there.
Is there any way to manually configure this or do I have to submit a feature request. If so, how can I do that?
Update 1:
I created a feature request on JetBrains Youtrack: http://youtrack.jetbrains.com/issue/WI-24262
Came across this question looking for something in Storm that would let me quickly convert "\Some\ClassName" to Some\ClassName::class like an Intention or plugin, but so far have found nothing.
i'm surprised the ::class static property hasn't been mentioned. It produces the FQN of the Class, and resolves from import aliases.
The following should be a legit rewrite that the IDE can resolve:
// Same __NAMESPACE__, so no prefix needed
Config(ObjectsToIdentifiers::class)
->oldTables = [
Modules\Old\Model\DeviceStock::class,
Modules\Old\Model\ProductPack::class,
Modules\Old\Model\SpareStock::class,
Modules\Old\Model\ConsumStock::class
];
// or, if you import the classes:
use Modules\Old\Model\DeviceStock as OldDeviceStock;
// you can refer to
OldDeviceStock::class;
Unfortunately, right now if you jump-to-definition of the alias, Storm won't take you to the actual class, but where the alias is defined. Not terribly helpful, but gets you halfway since the actual class is right there.

Visual Studio Extension highlight based on passed in code block

Trying to write a visual studio extension that will let me pass in a string and value pair and highlight the value.
I have an extension that looks for specific code and example is that it runs and might returns all if statements
If(someString == someOtherString){
return “This was something”;
}
If(someStringElse == someOtherString){
return “This was interesting”;
}
In this example my value might be the open parentheses that is part of
If(someString
I played around with the tutorial on the MSDN site but it seems to only show an all or nothing. I can get it to highlight all open parentheses and I cannot seem to limit it to only the code block I want (pass in the code blocks I want to search for)
If you're following that prototype, then you can adjust these lines here:
//Find the new spans
FindData findData = new FindData(currentWord.GetText(), currentWord.Snapshot);
findData.FindOptions = FindOptions.WholeWord | FindOptions.MatchCase;
wordSpans.AddRange(TextSearchService.FindAll(findData));
TextSearchService.FindAll is returning the list of spans in the editor that matched the text passed in. Nothing is stopping you from simply changing the spans or computing new ones before calling AddRange. Customize that logic to whatever you want. Obviously, if what you want to highlight doesn't depend upon the position of the caret, there's a fair bit of code you can delete for the determination of currentWord.

IS warning about string ID "IDS_ERROR_27555" not being found in string table

I have an Installshield2010 project that has had this warning since before my employment
ISDEV : warning -3028: The string ID "IDS_ERROR_27555" was not found in the string table. It is referenced in the table:"Error" in column:"Message".
Looking in the svn history, this row was added to Error table a few years ago - alongside a seemingly unrelated change
<row><td>27555</td><td>##IDS_ERROR_27555##</td></row>
However as the error indicates, there is no corresponding entry in the ISString table.
I'm curious how it got added. The IDS_ERROR strings look like canned strings, it seems really unlikely the person who added this to my ism did so manually.
Of course Flexera's forums are a ghost town. I did find an ism that has that string defined as
<row><td>IDS_ERROR_27555</td><td>1033</td><td>Error attempting to apply permissions to object '[2]'. System error: [3] ([4])</td><td>0</td><td/><td>1394414478</td></row>
Do any of your ism's have IDS_ERROR_27555 defined or referenced? Am very sure I can delete the string and be no worse for wear... but it bugs me to not know what happened.
I don't remember in which version we added these strings, but you can get them by importing the strings file for your language (1033.txt for English) under the Languages folder. Upgrading across versions of InstallShield should have added this string. You can add them yourself by importing the strings file in the String Editor view. Of course if you've modified other strings, you'll want to ensure that you keep your preferred version.

How to get the filename and line number of a particular JetBrains.ReSharper.Psi.IDeclaredElement?

I want to write a test framework extension for resharper. The docs for this are here: http://confluence.jetbrains.net/display/ReSharper/Test+Framework+Support
One aspect of this is indicating if a particular piece of code is part of a test. The piece of code is represented as a IDeclaredElement.
Is it possible to get the filename and line number of a piece of code represented by a particular IDeclaredElement?
Following up to the response below:
#Evgeny, thanks for the answer, I wonder if you can clarify one point for me.
Suppose the user has this test open in visual studio: https://github.com/fschwiet/DreamNJasmine/blob/master/NJasmine.Tests/SampleTest.cs
Suppose the user right clicks on line 48, the "player.Resume()" expression.
Will the IDeclaredElement tell me specifically they want to run at line 48? Or is it going to give me a IDeclaredElement corresponding to the entire class, and a filename/line number range for the entire class?
I should play with this myself, but I appreciate tapping into what you already know.
Yes.
The "IDeclaredElement" entity is the code symbol (class, method, variable, etc.). It could be loaded from assembly metadata, it could be declared in source code, it could come from source code implicitly.
You can use
var declarations = declaredElement.GetDeclarations()
to get all AST elements which declares it (this could return multiple declarations for partial class, for example)
Then, for any IDeclaration, you can use
var documentRange = declaration.GetDocumentRange()
if (documentRange.IsValid())
Console.WriteLine ("File: {0} Line:{1}",
DocumentManager.GetInstance(declaration.GetSolution()).GetProjectFile(documentRange.Document).Name,
documentRange.Document.GetCoordsByOffset(documentRange.TextRange.StartOffset).Line
);
By the way, which test framework extension are you developing?
Will the IDeclaredElement tell me specifically they want to run at
line 48?
Once more: IDeclaredElement has no positions in the file. Instead, it's declaration have them.
For every declaration (IDeclaration is a regular AST node) there is range in document which covers it. In my previous example, I used TextRange.StartOffset, though you can use TextRange.EndOffset.
If you need more prcise position in the file, please traverse AST tree, and check the coordinates in the document for specific expression/statement

Table and Column names causing problems

I have an issue when the T4 linq templates generate the classes for my MySql db using subsonic 3.
It looks like one of our table names "operator" is causing problems in the Context.cs generated class. In the following line of code in Context.cs Visual Studio sees <operator> as a c# operator and generates a compilation error of "Type expected"
public Query<operator> operators { get; set; }
Is there anyway I can work around this without having to rename my database table and column names? For example hard coding something in Settings.ttinclude to use or map different names to specific db tables and columns?
The CleanUp() function was built for this - it's in Settings.tt. You should be able to rename your class as needed.

Resources