I have code contains single line comments on variables(intentionally).
/** The object mapper. */
#Autowired
private ObjectMapper objectMapper;
But when I autoformat(ctrl+alt+l) it changes the single line comment to multi-line which I don't want.
I checked with the setting of Intellij but there is no such option.
After investigation i find the solution for intellij
Setting->editor->code style->java->java doc->others (tick donot wrap one line comments)
Related
I've recently joined a codebase that no one seemed to ever run SonarLint against, and now every test class I open in IntelliJ is highlighted like a Christmas tree - all test methods are public, even though JUnit5 is used.
Tired of removing those public modifiers manually, I decided to implement an SSR template to do that for me. However, I can't seem to make it work with method parameter annotations! (which seem to be rather usual thing with JMockit)
The best I can have thus far is this:
Open Edit->Find->Replace structurally
Paste this into Search field:
#$MethodAnnotation$
public void $MethodName$(#mockit.Injectable $ParameterType$ $Parameter$) {
$statement$;
}
Choose file type: Java - Class Member
Add filter for MethodAnnotation variable: Text=org.junit.jupiter.api.Test
Add Min=0 for statement and Parameter variables
Paste this into Replace field:
#$MethodAnnotation$
void $MethodName$(#Injectable $ParameterType$ $Parameter$) {
$statement$;
}
(mind the indentation, otherwise it will be problematic!)
Select Complete match value for Search target
Find
As you can see, the annotation is hard-coded, which of course limits the applicability of this snippet seriously.
Is this a problem with IntelliJ or rather my bad knowledge of SSR? What would be a proposed solution?
I am editing a cod pragmatically through editing the AST in Eclipse CDT, put after perform the refactor using Change#perform method, I found the code to be formatted, example here I am just cast a function call to be void
//Old code
Publish(Author_id, Content);
//New code
(void) Publish(
Author_id,
Content);
As you see the method has been formatted to be in 3 lines, how to stop this action?
My code sample that do refactoring
INodeFactory factory = ast.getASTNodeFactory();
IASTNode newNode = rewriter.createLiteralNode("( void )"+selectedNode.getRawSignature());
rewriter.replace(selectedNode, newNode, null);
Change change = rewriter.rewriteAST();
change = change.perform(new NullProgressMonitor());
I believe you have two options:
Configure CDT's built-in formatter to format the code the way you like it. In this case, based on the appearance of the "New code", it looks like Line Wrapping -> Function calls -> Arguments -> Line wrapping policy is set to one of the "Wrap all elements" options. You can change it to something you like better.
Implement the org.eclipse.cdt.core.CodeFormatter extension point to provide an alternative formatter that behaves differently from the default code formatter (for example, it could do nothing).
UPDATE: I don't know where to find an example of this, but assuming you're familiar with implementing Eclipse extension points in general, here is the reference for this one. The steps would be:
Write a class that extends org.eclipse.cdt.core.formatter.CodeFormatter and implements the format() method
Ad an <extension ...> tag to your plugin's plugin.xml referencing your class
I am having problem similar to Intellij Formatter keeps moving method level annotation and method signature in one line.
My annotation and method definition is getting formatted in the same line. As these are two entities, should come in different lines.
Eg,
#Test
public void testMethod(){
..............
}
IntelliJ keeps changing above code to:
#Test public void testMethod(){
..............
}
I tried the same thing which is suggested in the above post, but problem with 'Keep when reformatting , checkbox Line breaks', is it keeps the line breaks everywhere. Lets say I have one long line
input.get(someVariableInput1, someVariableInput2, someVariableInput3, someVariableInput4,
And hit enter after this:
someVariableInput5, someVariableInput6);
And if we format it, it will format in following way:
input.get(someVariableInput1, someVariableInput2, someVariableInput3,
someVariableInput4,
someVariableInput5, someVariableInput6);
Which I don't want. Can someone please help here? Thanks in advance.
When I use the JetBrains IDEA generate the constructor for Java Class, I always get a separate line for the first parameter. For example:
public Test(//this parameter in next line.
Class<Test> clazz) {
super(clazz);
}
I think this should be some configure for the template, but I cannot find it.
How to setup IntelliJ IDEA to prevent the splitting of an anonymous class, declared on one line, into several lines during auto-reformating (CTRL+ALT+L)?
For example, to prevent the splitting of
x = foo(new Boo() {});
into two lines:
x = foo(new Boo() {
});
"File" [menu]/"Settings"/"Code Style"/"Alignment and Braces":
==> "Keep when Reformatting" Field Set:
Check: "Simple methods in one line"
Check: "Simple blocks in one line"
Stumbled on this old question when searching for the same. The option Simple classes in one line has since been added to IntelliJ.
It can be found in the settings under Editor > Code Style > Java > Wrapping and Braces, in the Keep when reformatting field set.