Does Intellij have an auto replace feature like Toad? - intellij-idea

Does Intellij have an auto replace feature like Toad?
keyboard : ss + spacebar ==> select * from

IntelliJ has live templates.
For example enter the following code and place the cursor inside the curly braces:
public class MyClass {
// put cursor under this line
}
Now type psvm and hit TAB, the following will appear
public class MyClass {
// put cursor under this line
public static void main(String[] args) {
}
}
There are many live templates. The one in this example means "public static void main" (psvm) - you can research them all yourself. Note that many depend on context.
IntelliJ documentation: Live Templates

Related

How to remove Startup/Configuration tab from Intellij Plugin extending RunConfigurationBase

I am creating a custom IntelliJ plugin (following the IntelliJ tutorial) that implements a custom Run Configuration. My plugin will "run" the contents the open file in the editor on a remote server and display the result in IntelliJ (sort of a script playground). I used the IntelliJ GUI Designer to create the form and it shows up in the Edit Run Configuration, however it shows up under 2 tabs (Configuration and Startup/Configuration) .. neither of which I explicitly define, I assume they come from my extending of RunConfigurationBase?.
public class RunConfigurationImpl extends RunConfigurationBase {
public RunConfigurationImpl(Project project, ConfigurationFactory factory, String name) {
super(project, factory, name);
}
#NotNull
#Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new SettingsEditorImpl();
}
#Nullable
#Override
public SettingsEditor<ConfigurationPerRunnerSettings> getRunnerSettingsEditor(ProgramRunner runner) {
return null;
}
#Override
public void checkConfiguration() throws RuntimeConfigurationException {
}
#Nullable
#Override
public RunProfileState getState(#NotNull Executor executor, #NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
return null;
}
}
The first tab is fine (Configuration) ..
However I do not want to list the same fields again on the Startup/Connection tab, in fact, I'm happy to just do away with this tab -- or really, I don't care which tab I get rid off, I just
want the fields to show once.
Any pointers on how to get rid of this tab?
See com.intellij.execution.configurations.RunConfiguration#getRunnerSettingsEditor It returns null by default so let it stay null, don’t override it.
This is a consolidation of Vassiliy's answer and ensuing comments.
In order to remove the Startup/Connection tab in the custom Run Configuration UI, ensure that null is being returned from the methods getRunnerSettingsEditor() custom the classes that extends com.intellij.execution.configurations.RunConfiguration and com.intellij.execution.runners.ProgramRunner
By default the API abstract classes return null for these methods, so make sure you are not overriding them.

intellij how to auto completion a class in string literal

I have defined a method like below:
public void mehtod(String clazz) {
...
}
clazz parameter is a FQDN name as: com.example.Hello, and I want intellij to autocomplete when i type "com.example.Hello".
Do I need to make some custom config in Intellij?
You can use "Class Name Completion" for this.
Ctrl-Option-Space on Mac, Ctrl-Alt-SPace on Windows
I agree with "JB Nizet", though: Use Hello.class.getName() is more reliable

IntelliJ: custom code generation templates

How can I define custom code generation like Getters/Setters in IntelliJ. I took a look on their docs but they don't specify where I can do this. The code I would like IntelliJ to generate for me is like below:
public class Person {
private String name;
private String username;
//I want IntelliJ to propose me to generate this after Alt+Insert
public Person withName(String name){
setName(name);
return this;
}
//and this
public Person withUsername(String username){
setUsername(username);
return this;
}
}
Thanks a lot
When you press alt+insert you can click Getter and Setter. There are Getter template and Setter template drop-downs that you can select. Click the ... and you can create new templates.
It appears you're trying to follow the builder pattern. IntelliJ already has a setter template for this called "Builder". You can select it from the setter drop-down and you should be good.

Binding keys using org.eclipse.ui.binding

I am trying to introduce a shortcut key(Ctrl+Shift+f) to our customized editor to format the content.
I've implememented the following changes.
Added changes to plugin xml by adding key extension with definition Id/schema/context.
Implemented Action by extending TextEditorAction class as below.
#Override
public void run() {
this.doOperation(ISourceViewer.FORMAT);
}
Implemented one Formatter class by implementing IContentFormatter.
Passed the above Formatter class to our cutsomized sourceVIewConfiguration (extends SourceViewerConfiguration) class by overriding getContentFormatter.
overrided createActions() API inside our customized editor class which extends TextEditor.
For some reason my shortcut key is not working. I put a debug point inside my action class and noticed the controller is not going there when i press on the shortcut key.
I also noticed that the newly created key is not displayed under preferences -> keys list.
Can somebody provide pointers or example to resolve the issue.
plugin.xml entries:
<key
commandId="com.language.javascripteditor.XJSFormatAction"
schemeId="myScheme"
sequence="M1+M2+z"/>
<scheme
id="myScheme"
name="myScheme">
</scheme>
Formatter class:
public class JavaScriptEditorFormatter implements IContentFormatter {
#Override
public void format(IDocument document, IRegion region) {
try {
String content =document.get(region.getOffset(), region.getLength());
String formatted = new JSBeautifier().js_beautify(content,null);
document.replace(region.getOffset(), region.getLength(), formatted);
} catch (BadLocationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
#Override
public IFormattingStrategy getFormattingStrategy(String contentType) {
throw new UnsupportedOperationException();
}
}
Added a new property file for customized schema with the name plugin_customization.ini and with the content as below
org.eclipse.ui/KEY_CONFIGURATION_ID=myScheme
Command section inside plugin.xml
<command
defaultHandler="com.cisco.nm.workflowbuilder.language.javascripteditor.XJSFormatAction"
id="com.language.javascripteditor.XJSFormatAction"
name="%action.label.format.xjs">
</command>
Instead of a handler I have written an Action class. Please let me know if this approach does not work
1.Added contributor class to extension of the existing editor.
2.Created command with an id for format.eg: com.javascript.text.format
3.written Action class with format method
#Override
public void run() {
this.doOperation(ISourceViewer.FORMAT);
}
4. plugin xml entry
<key
commandId="com.javascript.text.format"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+M2+F"/>
5. Overriden the createActions() .Inside this method instantiated the Action class and setActionDefinitionId.

Android Studio / IntelliJ Anonymous Class Formatting

I was wondering if it is possible to change the auto-formatting in Android Studio in such a way that braces for anonymous classes are placed on the same line while still putting braces for regular classes, methods and blocks on a new line.
Currently, IntelliJ is giving me this result:
class TestClass
{
public void test()
{
FooBar foo = new FooBar(new Runnable() // I want the brace here...
{ // ...not here.
#Override
public void run()
{
//
}
});
}
}
However, I would like the code to be formatted like this:
class TestClass
{
public void test()
{
FooBar foo = new FooBar(new Runnable() { // <- Same Line
#Override
public void run()
{
//
}
});
}
}
Everything is fine, except the one detail that I cannot get the brace to be formatted like in the second example. Is this not possible or did I just overlook the setting?
I've wanted this for a long time now as well, but unfortunately it is not possible in Intellij.
The closest you can come is setting Wrapping and Braces/Braces Placement/In class declaration to "Next line if wrapped" or "End of line" (what I use). This of course modifies the way the brace is wrapped for not only anonymous inner classes (the desired result), but also for top level and inner classes; however, methods/if/else/for/while/do-while/try/catch/finally/switch etc are unaffected.
I really wish IntelliJ would add a Wrapping and Braces/Braces Placement/In anonymous class declaration option like Eclipse has.