Android Studio You don't know the shortcut keys (ii)

Source: Internet
Author: User

In Android Studio you do not know the shortcut key (a) inside, mainly about some of the window operation of the shortcut keys and complementary parameters hint, this article will share some code code editing shortcut keys. ( default Keymap as above)

Automatically generate variables

Automatically generate variables

As a static type language, Java has certain type derivation ability; Do you often write:

1
2
"Teststr";
New Arraylist<string> ();

In fact, do not have to write those angry type statement, a look at know testStr, testStrings what type, and then do not be nonsense! Fortunately, idea gave us this ability. Try this shortcut and it will surprise you.

    • Mac:Cmd + Alt + V
    • Win/linux:Ctrl + Alt + V

Some children's shoes may ask: When I use ArrayList, HashMap , the habit type is declared as the List,Map interface, the automatic generation of the type declaration or concrete implementation ah, how to do? This is what the IDE has helped you think about, try it shift + tab , and he'll give you a list of types you can choose from ~

Extracting parameters automatically

Extracting parameters automatically

Sometimes when you're writing a method, you find out. Alas, this variable is best passed in as a parameter. To do something like this, you have to replace all the local variables inside this method, and add parameters to all calls to this function, which is extremely tedious! Well, with this, you can have fun:

    • Mac:Cmd + Alt + P
    • Win/linux:Ctrl + Alt + P

Of course, if you want to keep the original method, just make a different method (overload) of the parameter, you can tick the dialog box that pops up.

Automatic Extraction method

Automatic Extraction method

When writing the code will find that this method is too long, suitable for decomposition and then extract a sub-method, or refactoring to see a one thousand or two thousand function, you are not big head? In general, we copy the code that we want to extract and then write a method (and a damn method signature) and copy it in, but the process is mechanical and can be done entirely by the IDE:

    • Mac:Cmd + Alt + M
    • Win/linux:Ctrl + Alt + M

If you want to change the signature of the method, choose what you need in the dialog box.

The above mentioned three shortcut keys are actually more similar, how to remember?

  1. First, the key combinations areCmd/Ctrl + Alt
  2. Then extract the variable variable=v, the parameter parameters=p, method method=m
inline variables/Parameters/methods

Inline

Well learned the above several shortcut keys, in case of playing high, such as the extraction of too many methods, want to "get back", how to do? This operation calls him Inline.. :

    • Mac:Cmd + Alt + N
    • Win/linux:Ctrl + Alt + M

The above diagram is only a reference, in fact, not only can be used for variables, but also can be methods/parameters, the personal feel that the method of inline is more useful.

Universal Refactoring Key

Universal Refactoring Key

Statically typed languages are relatively easy to refactor, but it is common to modify a place to involve a lot of other places, and we only have one place to find these compilation errors and then fix them manually. In fact, there are a lot of work can be done automatically, such as deleting a method, first confirm that there is no one call (Alt + F7), no words to delete the method body, some words to see where the call to decide how to do.

But the refactoring operation is too much! We have no way and no need to remember, know this shortcut key can, I call him Universal refactoring key :

    • Mac:Ctrl + T
    • Win/linux:Ctrl + Alt + Shift + T

In the Win/linux can consider this shortcut key to change the key, a press four keys I am very difficult to do AH.

This refactoring menu each function can try it on its own, after the use of not good for you to hit me.

Renaming

Renaming

Well introduced so many seemingly very high-end gadgets, to a majority of people know it. Sometimes you find that there is a problem with the name of the variable, or the culture of the team-mates/their words misspelled the wrong thing to do? You need to rename all the variables that are used in this variable, small case!

Shortcut keys:shift + F6

OK, this period of sharing is here. If you have not read the previous article can be a step:
Android Studio You don't know the shortcut keys (a)

Android Studio You don't know the shortcut keys (ii)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.