The following image pretty much illustrates the whole issue:
I have tried using // formatter:off with the appropriate settings, but to no avail. I have also tried looking for indentation rules for lambda expressions/anonymous classes, but I couldn't find those.
Any suggestion is much appreciated!
You need to close the outmost parenthesis right next to the closing bracket for the anonymous class to get the desired indentation.
Instead of:
itemClose.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
}
}
);
Remove the line/space between the last } and ); and you get:
itemClose.addActionListener(new ActionListener() {
#Override
public void actionPerformed(ActionEvent e) {
}
});
What helped for me was setting
Editor > Code Style > Java > Continuation indent to a lower value.
Uncheck the option "Use indents relative to expression start" in
Editor > Code Style > Java
IntelliJ Idea 14.1.1
Select checkbox
"File" [menu]/"Settings"/"Code Style"/"Enable formatter markers in comment"
(see field "Formatter off" and field value, for me it is "#formatter:off")
Then use // #formatter:off in your code.
Example:
// #formatter:off
Observable.create(new Observable.OnSubscribe<Path>() {
#Override
public void call(Subscriber<? super Path> subscriber) {
try (DirectoryStream<Path> stream = Files.newDirectoryStream(rootDir, filePattern)) {
for (Path path : stream) subscriber.onNext(path);
} catch (IOException e) {
System.err.println(e.getMessage());
subscriber.onError(e);
}
subscriber.onCompleted();
}
});
What did the trick for me was disabling the EditorConfig support:
File/Settings/Editor/Code Style: uncheck Enable EditorConfig support.
The new object is a call argument. Disable 'align when multiline' for 'method call arguments' will do the none indented formatting. This does also work for lambdas.
Related
When I use the IDEA, type the if/for/while, the parentheses will auto added.But CLion will not auto complete.
IDEA
CLion
How to solve this problem?
You need to use complete statement (Ctrl+Shift+Enter).
void foo() {
if|<Ctrl+Shift+Enter>
}
generates
void foo() {
if (true|<Ctrl+Shift+Enter>) {
}
}
one more complete moves you into the block:
void foo() {
if (true) {
|
}
}
It can be found in Settings/Editor/General/Smart Keys (Or just go to Help-> Find -> Smart Keys)
There you have an option to check Home, End (on blank line), Insert pair bracket, etc. Check Insert pair bracket. This should do it.
I know one can dynamically change the content of a Label by using an Event Handler, and overriding for example the onRender method, for example:
#Override
public void onRender(ILabelInstance label, IReportContext reportContext)
throws ScriptException {
label.setText("My text!!");
}
But it doesn't seem to work if the label has its Localization TextKey set.
Does anyone already tried to implement it?
Ok ... found a workaround, just remove the Text Key before setting your own text:
#Override
public void onRender(ILabelInstance label, IReportContext reportContext)
throws ScriptException {
label.setTextKey("");
label.setText("My text!!");
}
I would like to catch any throwable during a Selenium test e.g. in order to make a screenshot. The only solution I could come up with for now is to separately surround the test steps with a try and catch block in every test method as following:
#Test
public void testYouTubeVideo() throws Throwable {
try {
// My test steps go here
} catch (Throwable t) {
captureScreenshots();
throw t;
}
}
I'm sure there is a better solution for this. I would like a higher, more centralized location for this try-catch-makeScreenshot routine, so that my test would be able to include just the test steps again. Any ideas would be greatly appreciated.
You need to declare a TestRule, probably a TestWatcher or if you want to define the rules more explicitly, ExternalResource. This would look something like:
public class WatchmanTest {
#Rule
public TestRule watchman= new TestWatcher() {
#Override
protected void failed(Description d) {
// take screenshot here
}
};
#Test
public void fails() {
fail();
}
#Test
public void succeeds() {
}
}
The TestWatcher anonymous class can of course be factored out, and just referenced from the test classes.
I solved a similar problem using Spring's AOP. In summary:
Declare the selenium object as a bean
Add an aspect using
#AfterThrowing
The aspect can take the screenshot and save it to a
file with a semirandom generated name.
The aspect also rethrows the exception, with the exception message including the filename so you can look at it afterwards.
I found it more helpful to save the HTML of the page due to flakiness of grabbing screenshots.
I have made an eclipse plugin with TextViewer interface for displaying a text document but the standard find/replace stay in gray mode.
I assume you are using the TextViewer in a view rather than an editor. In this case:
Your view in which the TextViewer is used must "adapt" to org.eclipse.jface.text.IFindReplaceTarget i.e. its getAdapter() must return the target from viewer.
You need to explicitly register a handler for "org.eclipse.ui.edit.findReplace" command (which can be org.eclipse.ui.texteditorFindReplaceAction). Check out Platform Command Framework to get started.
I've used Martii Käärik's pointers for finding the answer to this question. I've got it working with the following code, which however uses an internal string identifier from TextEditor. Still, here it goes.
getAdapter() in the view must be implemented like this (viewer is an instance of TextViewer)
public Object getAdapter(Class adapter) {
if (IFindReplaceTarget.class.equals(adapter)) {
if (viewer != null) {
return viewer.getFindReplaceTarget();
}
}
return super.getAdapter(adapter);
}
In createPartControl() of your view, add this code:
FindReplaceAction findAction= new FindReplaceAction(ResourceBundle.getBundle("org.eclipse.ui.texteditor.ConstructedTextEditorMessages"), null, this);
IHandlerService handlerService= (IHandlerService) getSite().getService(IHandlerService.class);
IHandler handler= new AbstractHandler() {
public Object execute(ExecutionEvent event) throws ExecutionException {
if (viewer != null && viewer.getDocument() != null)
findAction.run();
return null;
}
};
handlerService.activateHandler("org.eclipse.ui.edit.findReplace", handler);
No XML required.
I've got a rule like this:
declaration returns [RuntimeObject obj]:
DECLARE label value { $obj = new RuntimeObject($label.text, $value.text); };
Unfortunately, it throws an exception in the RuntimeObject constructor because $label.text is null. Examining the debug output and some other things reveals that the match against "label" actually failed, but the Antlr runtime "helpfully" continues with the match for the purpose of giving a more helpful error message (http://www.antlr.org/blog/antlr3/error.handling.tml).
Okay, I can see how this would be useful for some situations, but how can I tell Antlr to stop doing that? The defaultErrorHandler=false option from v2 seems to be gone.
I don't know much about Antlr, so this may be way off base, but the section entitled "Error Handling" on this migration page looks helpful.
It suggests you can either use #rulecatch { } to disable error handling entirely, or override the mismatch() method of the BaseRecogniser with your own implementation that doesn't attempt to recover. From your problem description, the example on that page seems like it does exactly what you want.
You could also override the reportError(RecognitionException) method, to make it rethrow the exception instead of print it, like so:
#parser::members {
#Override
public void reportError(RecognitionException e) {
throw new RuntimeException(e);
}
}
However, I'm not sure you want this (or the solution by ire_and_curses), because you will only get one error per parse attempt, which you can then fix, just to find the next error. If you try to recover (ANTLR does it okay) you can get multiple errors in one try, and fix all of them.
You need to override the mismatch and recoverFromMismatchedSet methods to ensure an exception is thrown immediately (examples are for Java):
#members {
protected void mismatch(IntStream input, int ttype, BitSet follow) throws RecognitionException {
throw new MismatchedTokenException(ttype, input);
}
public Object recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException {
throw e;
}
}
then you need to change how the parser deals with those exceptions so they're not swallowed:
#rulecatch {
catch (RecognitionException e) {
throw e;
}
}
(The bodies of all the rule-matching methods in your parser will be enclosed in try blocks, with this as the catch block.)
For comparison, the default implementation of recoverFromMismatchedSet inherited from BaseRecognizer:
public Object recoverFromMismatchedSet(IntStream input, RecognitionException e, BitSet follow) throws RecognitionException {
if (mismatchIsMissingToken(input, follow)) {
reportError(e);
return getMissingSymbol(input, e, Token.INVALID_TOKEN_TYPE, follow);
}
throw e;
}
and the default rulecatch:
catch (RecognitionException re) {
reportError(re);
recover(input,re);
}