What setting in Rider is responsible for what lambdas find on such a large indent?
For example i want this:
instead this:
It is in Settings -> Editor -> Code Style -> C# -> Tabs, Indent, Alignment -> Align Multiple Constructs.
Specifically for lambdas: Array, object and collection initialization, Anonymous method body must be turned off
Related
Intellij supports 'instance templates' i.e. templates usable with expression followed by a period, such as cast, new etc. So MyClass.new expands to new MyClass(I) where I is the cursor.
Now I want to create my own template, expression.orElse which expands to:
Optional.ofNullable(expression).orElse(I)
I tried looking for options in Editor > Live Templates, but couldn't find anything relevant. Is this not possible in IntelliJ IDEA, or am I missing something?
These 'instance templates' are actually called postfix completion templates in IDEA.
Starting with version 2019.2, custom postfix templates can also be created by going to Editor > General > Postfix Completion, as specified here and detailed in this blog post.
For the asked case, the values would be:
Key: orElse
Minimum language leve: 8
Applicable expression types: non void
Value:
Optional.ofNullable($EXPR$).orElse($END$)
Variables:
$EXPR$: Replaced by the target expression
$END$: Location of cursor after substitution
Enabling 'Apply to the topmost expression' disables the scope selection popup that appears on selecting the template.
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 hope to pass the string {"name":"My Settings 1"} to a var aa
I have to write it using the code var aa=" {\"name\":\"My Settings 1\"} "
Is there a simple way in Kotlin when I use Android Studio 3.0 ?
I know <![CDATA[...]]> is good for XML content
The simplest thing you can do in Kotlin is use raw strings with triple quote marks:
val a = """{"name":"My Settings 1"}"""
For a tooling solution instead of a language solution (so this works both in Kotlin and Java), you can use language injection in Android Studio or IntelliJ.
Create a string, and invoke intention actions on it with Alt + Enter. Select Inject language or reference, and then JSON.
Use Alt + Enter again, and choose Edit JSON Fragment.
Edit the raw JSON in the panel that appears on the bottom, and IntelliJ will automatically mirror its contents into the string, escaping any characters that have to be escaped.
Escaping special chars in regular Strings, like in your example, is what has to be done with Java and also Kotlin:
"{\"name\":\"My Settings 1\"}"
Kotlin offers raw Strings to evade this. In these raw Strings there's no need to escape special chars, which shows the following:
"""{"name":"My Settings 1"}"""
Raw Strings are delimited by a triple quote (""").
Read the docs here.
when I type a method call into intellij it doesn't suggest parameters, is it possible to make it suggest parameters?
for example calling
void setFoo( Foo foo );
in context
Foo foo = new Foo();
dto.setFoof(...
could then either prepopulate or suggest foo (netbeans does this).
Also parameters, like boolean could suggest, true or false.
Is it possible to make it suggest them, without additional typing?
You can press CTRL+J (Parameter Info) to get a tooltip showing an abstract of all parameters for all overloaded variants of a method (place the caret on the method). When using code completion (CTRL+Space) or SmartType (CTRL+Shift+Space) inside the method's parentheses, IntelliJ tries to intelligently propose parameter values that fit in the current context (such as true or false or a method yielding true or false for a boolean parameter).
In the Settings dialog (Settings... -> Editor -> Code Completion) you can configure the Parameter Info feature by activating an autopopup or enabling showing full signatures.
I'm toying around with fluent interfaces in the style of Martin Fowlers text, and I'm wondering if the grammar they are describing is context free or regular? I'm talking about interfaces such as this:
var car = new Car();
car.Configure().MakeCar.With.Wheels(4).And.Engine.Using.Petrol;
What I'm trying to do is to write a program which can generate them. Currently it requires an input of a context free grammar, but I seem to have some difficulty in converting this into source code application. I'm suspecting that the answer is that I can only reach for regular grammars since the state of the "stack" cannot be known since the result of each "terminal" method must be known beforehand.
What I've got now works, but it bugs out on certain grammars.
Edit: I went with regular grammars, the code is open sourced and working now if anyone's keen to toy around with it. https://github.com/Dervall/Snout
the set of options at any point are determined by the methods available on the class at that point. the class returned by that method determines the next set of methods.
so the rules for the grammar that generates the chain is a right regular grammar where the start symbols are classes, the symbols are methods, and the non-terminals are the classes returned by the methods:
class Car:
configure: Configurator
class Configurator:
with: Configurator // noise method
and: Configurator // noise method
wheels: int -> Configurator
windows: int -> WindowDetails
class WindowDetails:
transparent -> Configurator
tinted -> Configurator
ignoring the method args (int):
Car -> "configure" Configurator
Configurator -> "with" Configurator
Configurator -> "and" Configurator
Configurator -> "wheels" Configurator
Configurator -> "windows" WindowDetails
WindowDetails -> "transparent" Configurator
WindowDetails -> "tinted" Configurator
but what this fails to capture is the argument to wheels (the number of wheels). and a regular grammar can't handle that because different integer arguments might lead to different classes (eg after "(2)" do you have a Configurator or a WindowDetails?):
Configurator -> "wheels" Integer
Configurator -> "windows" Integer
Integer -> ?
so it depends what you want. the chain of methods can be described by a regular grammar. but a regular grammar cannot also describe the arguments passed to the methods. afaict.
you can handle arguments by adding the complexity of context free grammars, because then you can do something like:
Configurator -> "wheels" Integer Configurator
Configurator -> "windows" Integer WindowDetails
which has the extra info needed to continue correctly after the integer argument.
NOTE: the above assumes that method names are unique across all classes. if you have two different classes with the same method name then you are going to have problems, obviously (i hope) (and this might not so rare if you are using things like "with" and "and"....)