IntelliJ: add formatter:off/on comments around selected block - java

In IntelliJ IDEA (for Java code at least), it's poissble to instruct the code-formatter to ignore lines with these (see https://stackoverflow.com/a/19492318/117750):
// #formatter:off
...
// #formatter:on
What I'd like to do is automate adding these around a code block. Workflow I want:
Select a block of code.
Invoke an action (with a shortcut or a menu item etc. or with the Cmd-Shit-A).
This command needs to
add // #formatter:off on a new line before the first selected line, at the correct indentation.
add // #formatter:on on a new line after the last selected line, at the correct indentation.
From what I am reading, it is not possible to do with a Macro. Is it?
If not, do I need to write a plugin to do this? I am happy to write one, can someone give me brief high-level get-started steps on:
how to approach this action in a plugin
and pointers to get-started with plugins

You can get (close to) what you want using a Live Template. Go to Editor | Live Templates in the settings and add a new template (e.g. under the surround group) with the following text:
// #formatter:off
$SELECTION$
// #formatter:on
You can use the defined live template by selecting some text in the editor and invoking Code | Surround with Live Template... (Ctrl/Cmd+Alt+J) and selecting the live template you have created.

Related

Selenium throws StaleElementReferenceException

Testing CEF-based one-page application and have some problems. So, my application can generate an output file in many different configurations that are available to choose from dependent on each other dropdown lists.
Trying to generate files for all possible options by simulating the appropriate clicking: display list select the first possible option -> the same with list2 -> the same with list3 again -> go forward -> export file -> go back to the beginning.
for (WebElement material : materialList) {
displayMaterialList.click();
material.click();
for (WebElement size : sizeList) {
displaySizeList.click();
size.click();
for (WebElement thickness : thicknessList) {
displayThicknessList.click();
thickness.click();
//Exporting file:
nextStepButton.click()
nextStepButton.click();
exportFileButton.click();
copyPasteText("filename" + "_" + currentDataTime);
previousStepButton.click();;
}
}
}
These loops work fine without exporting file fragment embedded in the deepest loop, used them to display combinations of all possible options. But when I added file naming and exporting fragment tests project threw out
StaleElementReferenceException just after generated file, at the start of the second iteration. I think it can't find thickness.click(); but don't know why.
according to Exception Doc Selenium
Common Causes
A stale element reference exception is thrown in one of two cases, the first being more common than the second:
The element has been deleted entirely.
The element is no longer attached to the DOM.
Please check that, and if can't see the html tha you are trying to test in pretty difficult give a appropiate answer.

Stop Eclipse from cutting code lines on clean up

In Eclipse I want (for example) that code like this
public Foo bar() {
}
gets formatted to this
public Foo bar()
{
}
via the clean up function.
But to do that I have to check "Format source code" in the clean up profile.
But that also formats code like this
alert.setHeaderText("blablablablablablablablablablablablablablablabla");
to this
alert.setHeaderText(
"blablablablablablablablablablablablablablablabla");
which I absolutely do not want. Is there any possible way to stop Eclipse from cutting lines like that?
Go to Window->Preferences->Java->Code Style->Formatter. Create new formatter. Click on edit and then pick tab Line Wrapping and set Line Wrapping policy to Do not wrap.
For more clarification refer the below Link :-
http://eclipsesource.com/blogs/2013/07/09/invisible-chaos-mastering-white-spaces-in-eclipse/
You can configure the style to which code is formatted. Under
Preferences: Java -> CodeStyle -> Formatter
Then look for "Line wrapping".

How to do a specific completion action without adding some unnecessary comment ?

I have the following warning
The serializable class myClassD4 does not declare a static final
serialVersionUID field of type long
From this interesting discussion https://stackoverflow.com/a/285809/813853 I know what to do to handle this warning.
BUT my problem is kind of different, it is related to Eclipse parametrization. When I get this warning, I do right click. And choose completion action :
Add generated serial version id
the problem is that this add a comment block , something like /* ** */. That I don't want. Please, how to get rid of that ? I have looked on the configuration of Eclipse but not found it YET.
Found it :)
Window -> Preferences -> Java -> Code Style -> Code Templates -> Comments -> Fields
All I have to do is to edit the default string.
The only way that I know is to turn off comment-generation for ALL fields (=instance vairables). This is how to do it:
Windows -> Preferences -> Java -> Code Style -> Code Template .
Open Comments tab, click on Fields, click on Edit button and remove the text

IntelliJ Idea: code completion for creating method like in Eclipse

I am using Eclipse for about 5 years. Now I'm begging with IntelliJ Idea 13. I can not get used to code completion :-(
How can I create new public method?
In Eclipse i press:
pub CTRL+SPACE ENTER int CTRL+SPACE test ENTER
and get
public int test() {
}
how can I do it in Idea?
IF this scenario is important to you,
You can use IntelliJ's Live Templates
There are no built-in templates for that. You can create your own, like other answers advise. But in general, just typing the method with autopopup completion seems to require almost the same number of key presses:
pub < autopopup appears with "public" selected, hit ENTER > int test( < CTRL+SHIFT+ENTER >
You can add a 'Live Template' in IntelliJ. Go to Preferences -> Live Templates -> Select your language (if Java is not there, you can select Other), select the "+" symbol and add a new template. e.g. Abbreviation = test, and put your method in the Template text.
IntelliJ will display a message 'No applicaable contexts yet'. Define' just below the box. If you click on 'Define' you can select 'Java' in the list that shows up.
In your editor, type the template abbreviation and press the tab key.

How do I overwrite the URL in an IE address bar using RFT?

I need to execute the following steps:
1. Start an IE browser window and open a URL (Done using StartBrowser(final string URL)
2. Start a session (done by logging in)
3. Now, I want to enter a different URL in the same browser window which has the same session.
My question is related to Step 3. How can I overwrite the URL in the existing IE window.
Note: I am using a keyword driven framework written in java.
From the IBM RFT online help: You can use the loadURL() method of the browser object.
If you do not have the browser object already 'learned' into your object map, just record a click on the browser toolbar. Then you can modify that line to be Browser_htmlBrowser().loadURL("http://stackoverflow.com");
Thanks Tom. I agree that loadURL has the implementation to do what I need.
There is one more aspect that may interest others looking at this question, i.e. the way the appropriate browser object is captured. Obviously the easist way is to use the RFT record and click way, and use the appropriate recognition properties or the other way is to implement it is find the existing browseron the fly when the method is called irrespective of recognistion properties etc which may be more useful for some scenarios or frameworks, like it is done below.
RootTestObject root = getRootTestObject();
TestObject[] testobj = root.find(atDescendant(".class", "Html.HtmlBrowser"));
BrowserTestObject bto;
bto = new BrowserTestObject(testobj[0]);
bto.loadUrl(curParamOne);

Categories

Resources