In eclipse by typing "main" and pressing Ctrl+Space you can generate main method, and there are lots of other shortcuts like this.
Is there anything like this in intellij-idea? and how can I assign them?
Depending upon your key configuration, you can type ⌘J for the Templates.
Also see: What are the most useful Intellij IDEA keyboard shortcuts?
Yes, just type sout and press tab button the main method with complete signature will be generated for you.
By default configuration shortcut for public static void main(String args[]) is:
psvm + TAB
psvm stands for Public Static Void Main
Related
Anyone knows any useful Netbeans shortcuts? in eclipse for example, i used to type sysout and press CTRL+Space, anyone knows any equivalent shortcuts? Thanks in advance ;D
What you are looking for is called Code Templates. You can find them under Tools / Options / Editor / Code Templates. There you find a (quite extensive) list of code templates that already comes out of the box but you can also define your own.
If you type in NetBeans for example psvm and press than the tab-key NetBeans will generate
public static void main(String[] args) {
}
for you.
I'm working on an Eclipse plugin to help people manage their project.
Is there a way to list all the classes with the main method under a project by Java code?
I think the best practise is to use only keyboard.
Create new java class with Ctrl+n
on dialog box, enter its (class) name
use (left)Alt+v to easily tick checkbox for - public static void main(String[] args)
then press [enter] Finish and voila class is ready
I am developing an interpreter for a visual programming language that I am implementing using Eclipse, EMF and GEF. I am currently creating an interpreter for the diagrams.
To execute a diagram, I decided to implement a launcher configuration. When the configuration is executed I want to read the EMF model from the active editor and interpret it. The problem I have is that the active editor can only be accessed from the UI thread, and I don't want the interpreter to execute in the UI tread since it may be a long process. This is the code that works but should not be used:
#Override
public void launch(ILaunchConfiguration configuration, String mode, ILaunch launch, IProgressMonitor monitor)
throws CoreException {
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
IEditorPart activeEditor = workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor();
OPMGraphicalEditor editor = (OPMGraphicalEditor) activeEditor;
OPMObjectProcessDiagram opd = editor.getOPD();
Interpreter.INSTANCE.interpret(opd);
}
});
}
I'm sure there is a proper way to do this, but I haven't found it. The examples for launch configurations that I found in the internet use external programs, but I am (currently) implementing my interpreter as part of the workbench.
Thanks for the help.
You can use the above code with a ...getDisplay().syncExec(...) instead and then store the pointer to the editor into some enclosing object.
If you're launching your configuration from the editor directly (right-click, run as..) then you can just use an ILaunchShortcut and overwrite its void launch(IEditorPart editor, String mode) method to access the editor where the file is launched from.
I want to develope plug-ins in eclipse,the function of the plug-ins is when right-click menu the button opens a perspective.I find the class which is "openPerspectiveMenu" has not been used,please tell me the alternative.
thank you!
The way to open a perspective programmatically is to call:
IWorkbench.showPerspective(String perspectiveId,
IWorkbenchWindow window)
throws WorkbenchException
Javadoc here.
See http://wiki.eclipse.org/FAQ_How_do_I_show_a_given_perspective%3F for details.
In NetBeans I can set up a bunch of templates such that typing psvm tab expands to
public static void main(String[] args) {
}
I see that Eclipse also has templates, but they are triggered in a different way - Ctrl-Space. But I don't see a way that you can have the template automatically triggered -instead, a popup appears and you pick which of the code completions to execute. Is there a way to make Eclipse pick the template that matches automatically, without showing that popup? In Netbeans it's a lot less intrusive to insert these code snippets, and I'm hoping it's possible to do the same in Eclipse. Any experts know for sure?
In Eclipse push Enter after typing the template name. The popup comes up quickly but you can STILL type.
Say your template name is: tr
type: tr[PUSH:ENTER] template will complete without the popup, or even if the popup comes up push enter to finish and make it go away.
Also do not name your templates the same name as a PHP keyword as the keyword is listed first
i.e
template name: function
typing: function
popup will come and list
function
function - Template
and you'll have to select the second one
if you named it: func then type func[enter] it'll autocomplete
I call my templates _m (for the main method), _o for System.out.println, etc. This way I only press the underscore, a letter, ctrl-space, and enter. I completely ignore the popup, since I know there's nothing there except for the one template I want. This way I get it separated.
You can assign a keybinding to templates on the Key preference page. Would this help as it reduces the set shown for a keybinding to templates only?
Also, do you realise typing main cntrl+space does the same as your example?