Android Studio: Enum auto-completion of switch case - autocomplete

Is there any auto-complete shortcut or code-generation command in Android Studio that creates a stub
switch (myEnum){
}
statement containing all of the possible case statements for a defined enum as in Eclipse?

Put the caret on "switch", press Alt-Enter, select "Create missing 'switch' branches".

Enum.class
public enum
myEnum{
Item1,
Item2,
Item3,
Item4
}
EnumSwitchImplement.class
private Enum.myEnum mMyEnum;
switch(mMyEnum){
//put cursor here and press Alt + Enter
/*a box will come with option "create missing 'switch' branches"
select.*/
}
//your switch will convert to
switch(mMyEnum){
case Item1:
break;
case Item2:
break;
case Item3:
break;
case Item4:
break;
}
This works on Android Studio.
Haven't check on Eclipse. :)

Just place the mouse pointer over switch and then wait for some time. An yellow bulb will be shown as below. Click on that yellow bulb (or press ALT+Enter) and click on the option Create missing 'switch' branches option.
This will auto create the switch case-break statements as below.
Hope this helps someone.

Related

vscode quickly select and comment code block without using mouse

Hi guys suppose i want to comment the below code in vscode
files_converted.forEach( ( item , idx ) => {
zip_Directory( `${req.body.outputPath}/${item}` , `${req.body.outputPath}/${item}.zip` );
})
.then( () => {
console.log('FILES CONVERTED AND ZIPPED !')
}).catch( (err) =>
{ console.error(err)
});
Is there anyway of quickly selecting and commenting out the above code without using the mouse ? The comment style i prefer is ( /* some comment here */ ).
To select something inside curly brackets, you can use smart select. The idea is that you can select the text inside curly brackets and "expand" the selection or "shrink" it. The default keyboard shortcut on Mac is Ctrl+Shift+Cmd+Right Arrow to grow and the left arrow to shrink.
To use block comments instead of line comments you can use ... well, the "block comment" function :-P Which by default is Command+Option+/ on Mac.
for bracket selection, use this...
https://marketplace.visualstudio.com/items?itemName=dbankier.vscode-quick-select
for block comment,
use Shift+Alt+A

How to use selenium webdriver to select an option of Bootstrap select dropdown menu?

I've to select a country from dropdown of https://www.parcelhero.com but when I use the below code for it, sometimes it works sometimes not, giving error of Element not found(xpath("//*[#id='dvQuoteFrom']/div/button"))
driver.findElement(By.xpath("//*[#id='dvQuoteFrom']/div/button")).click();
Thread.sleep(4000);
WebElement txt = driver.findElement(By.xpath("html/body/div[14]/div/div/input"));
txt.sendKeys("Great Britain");
List <WebElement> InnerDropdown1 =driver.findElements(By.xpath("//*[#class='active']"));
for(WebElement option1 : InnerDropdown1)
{ System.out.println(option1.getText());
if(option1.getText().contains("Great Britain")) {
option1.click();
break;
}
}
When I used
WebElement txt = driver.findElement(By.className("bs-searchbox")); then also I got the uable to find element error.
Please help me to select a country of my choice from the country dropdown?
Try doing this. I've changed a few of your locators and tested this on the page you mentioned.
public void foo() {
driver.get("https://www.parcelhero.com/");
//This will be your dropdown button. This needs to be clicked first.
driver.findElement(By.xpath("//button[contains(#data-id,'ConsignorAddressCountryId')]")).click();
//These are your input boxes. I found 3 input boxes on the same page having the same identifiers. We dont want to rely on using index based xpath so here we'll get all instances of input boxes.
List<WebElement> elems = driver.findElements(By.xpath("//*[contains(#class,'bs-searchbox')]//input"));
for (WebElement elem : elems) {
//Here we check if the input box is visible. If I'm not mistaken, there will only be 1 visible input box at a time because you have to click on the dropdown button first.
if (elem.isDisplayed()) {
//If visible, just enter your country of choice
elem.sendKeys("American Samoa");
//Assuming you always enter exact match string for your test, you can use the org.openqa.selenium.Keys for sendKeys()
elem.sendKeys(Keys.ENTER);
break;
}
}
}

Extend CDT Plugin Hide/Show line by Regex

I would like to extend the CDT plugin for eclipse, to show/hide lines of code which are matching some regex. I don't want to "fold" via foldingStructureProviders, I really want them to be not visible while preserving line numbers. I need line numbers for later work.
Does anybody know a good extension point of the cdt c editor for that?
Example:
1: int main(){
2: call_regex();
3: return 1;
4: }
After activated "Hide Button":
1: int main(){
3: return 1;
4: }
Deactivate "Hide Button":
Example:
1: int main(){
2: call_regex();
3: return 1;
4: }
Look up Segmented and Projected modes in Eclipse Editors.
For example, the ProjectionViewer which is extended by CDT's CSourceViewer.

PL/SQL onChange event for apex plugin

I am working on a plugin for Apex 4.2, written in pl/sql. I am trying to hide/show specific features in my toolbar based on the selection of a radio button. I am already able to handle the hiding / showing of the toolbars. My problem is getting this to happen everytime I select a specific radio button. My code is below
$("#P13_GROUP").on("change", function () {
if ( $("#P13_GROUP").val("UPDATE") ) {
$("#draw_point").hide();
$("#longitude_minutes").hide();
$("#longitude_seconds").hide();
} else if ( $("#P13_GROUP").val("CREATE") ) {
$("#draw_point").show();
$("#longitude_minutes").show();
$("#longitude_seconds").show();
} else if ( $("#P13_GROUP").val("DISCARD") ) {
$("#draw_point").show();
$("#longitude_minutes").show();
$("#longitude_seconds").show();
}
})
Where P13_GROUP is a page item in Apex which represents the radio group. Radio group consists of three possible values / choices. All this is doing for me is hiding my fields. It hides my fields no matter what radio button I click. So if I clicked the radio button under 'DISCARD', my fields get hidden, when they should still show. If I click a different radio button after that, there is no change.
Any help on this topic would be greatly appreciated. Thanks in advance.
I'd do it with a switch statement:
$("#P13_GROUP").on("change", function() {
switch ($(this).val()) {
case "UPDATE":
$("#draw_point, #longitude_minutes, #longitude_seconds").hide();
break;
default:
$("#draw_point, #longitude_minutes, #longitude_seconds").show();
break;
}
});

Clicking keyboard 'Next' key using UIAutomation

I have a search field in my app and I have set the return key type of the keyboard for this field to UIReturnKeyNext. I am attempting to write a UIAutomation test that clicks the Next button on the keyboard using the following line:
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().keys().firstWithName("next");
This call is failing because the key with name 'next' is not being found. I have done a dump of all of the elements in my app using:
UIATarget.localTarget().frontMostApp().logElementTree();
This reveals that there is indeed a key in the keyboard with name 'next', but somehow my attempt to retrieve it as show above still fails. I can however retrieve other keys (like the key for the letter 'u') using this method. Is there a known issue here or am I doing something wrong?
I've tried other variations with no luck:
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().elements()["next"];
Here is a screen capture of the elements in my UIAKeyboard:
If you just want to click it, and you know the keyboard has "next" as "Return key" (defined in your nib), then you can use this:
app.keyboard().typeString("\n");
Jelle's approach worked for me. But I also found an alternative way if anybody needed it.
XCUIApplication().keyboards.buttons["return"].tap()
Where you can create XCUIApplication() as a singleton on each UI Test session. The thing about this approach is you can now distinguish between return and done and other variants and even check for their existence.
You can go extra and do something like following:
extension UIReturnKeyType {
public var title: String {
switch self {
case .next:
return "Next"
case .default:
return "return"
case .continue:
return "Continue"
case .done:
return "Done"
case .emergencyCall:
return "Emergency call"
case .go:
return "Go"
case .join:
return "Join"
case .route:
return "Route"
case .yahoo, .google, .search:
return "Search"
case .send:
return "Send"
}
}
}
extension XCUIElement {
func tap(button: UIReturnKeyType) {
XCUIApplication().keyboards.buttons[button.title].tap()
}
}
And you can use it like:
let usernameTextField = XCUIApplication().textFields["username"]
usernameTextField.typeText("username")
usernameTextField.tap(button: .next)
I dont't have an example to test, but as the "Next" button is an UIAButton, and not an UIAKey you could try :
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons()["next"];
If it doesn't work, you can also try
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons()[4];
The following works for me:
UIATarget.localTarget().frontMostApp().mainWindow().keyboard().buttons().firstWi‌​thPredicate("name contains[c] 'next'");
For me, keyboard does not fall under mainWindow() in the View Hierarchy. It is at the same level as mainWindow() when you logElementTree() from top level. So, what you want to do is:
UIATarget.localTarget().frontMostApp().keyboard().buttons()["next"];
This worked for me when I was trying to press the "Search" button on keyboard.