When I reformat code with Eclipse, it turns method headers like this:
public void myMethod(String param) {
into method headers like this:
public void myMethod(
String param) {
When I was brought on here I'd never used Eclipse before, and I imported project settings provided by someone else. I have seen that on small new projects I've worked on Eclipse does not do this, so it must be in the settings I've imported. But I've gone through every panel I can find, as well as every hidden file I can find in the workspace, and I can't figure out what is causing this.
How do I turn it off? I don't want a newline before parameters in my method signatures, and I can't imagine why anyone would!
Have a look at Window>Preferences>Java>Code Style>Formatter.
There you can configure almost everything. Your case is found at
Line Wrapping>Method Declarations>Parameters.
In my version of Eclipse, I found the option under Window->Preferences->Java->Code Style->Formatter, then clicked the Edit.. button.
In the new window, go to the Line Wrapping tab and find Method Declarations. You want to change the Line wrapping policy. The Force split check box seems to do the same.
Go into preferences: Java -> Code Style -> Formatter
Restore Defaults or edit what's there.
Additionally, Code Style -> Code Templates will allow you to define generate code formatting.
Note that this is for Eclipse Workspace as a whole, the same Preferences can be accessed under the project preferences if you want to get more fine grained at a per project level.
In eclipse you can define your code formatting use Code Style ,
for MAC System :--> Eclipse --> Preference -- > java--> code Style
for Window System :--> Window->Preferences->Java->Code Style->Formatter
The best way to change your format is to go to Window-> Preferences-> Java-> Code Style-> Formatter. Inside the formatter window, eclipse has a couple of built in styles, but the best way is create a new profile of your own by pressing on New. You can change the format as you please on the edit tab
You can change parentheses and curly braces positioning along with other stuff.
Related
Hi I'm new to IntelliJ IDEA and got here and there usability issues, because I'm coming from Eclipse.
When I rename a variable and want to mark the second part of it by hitting Ctrl+Shift+Right, the cursor moves to the next word which is outside of the border for renaming and when I type the new name and click Enter, the rename isn't executed for the other usages of the variable. Is there a setting where it's possible to change the behavior of Ctrl+Shift+Left/Right so that the caret moves right after the last character of the variable name?
Second question
When I'm moving the cursor through a variable name with Ctrl+Left/Right the next stop in Eclipse was always before the next upper case letter. Is in Idea also a setting to activate this? This would be very helpful when renaming variables.
What you exactly need is [I have jIdea 12.1]:
Go to settings [Ctrl+Alt+S]
Choose [Editor -> General -> Smartkeys]
Check the [Use "CamelHumps" Words] button
Вуаля!
Ctrl+Alt+S and select Keymap from settings, you can change what you want it to there.
But I would suggest using the autocomplete/intellitext features of IntelliJ and the refactoring tool, without manually navigating through variable names - they normally get it right first time.
well I've seen in Tips & Tricks of Eclipse that it's possible to get a variable name generated by eclipse by clicking Ctrl + Space. However I'm getting empty suggestions. Fors instance I'm typing this and click ctrl + space:
private Color
And I am supposed to get some name suggestions on it? All I'm getting is an empty list of suggestions. So what's turned off? Any idea?
Thanks in advance.
This is what I want to achieve:
I believe you are trying to get variable name e.g. color after private Color where Color is you class i.e. private Color color. I see that working in my eclipse.
To verify your settings, go to below settings and verify as they look good to you.
Windows -> Preferences -> Java -> Editor ->Content Assist
and
Windows -> Preferences -> Java -> Editor ->Content Assist -> Advanced
This is the default behavior after entering a Java type and a space, and then pressing CTRL+Space to activate auto-complete. For example, if you enter:
private Color
then activate auto-complete it will suggest some variable names for you.
An easier way than having to press CTRL+Space all the time is to change the characters which automatically activate auto-complete. I find it very useful to have all characters which could possible be variable names to activate auto-complete. Try having ._abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ as Auto activation triggers for Java found in Preferences -> Java -> Editor -> Content Assist:
This way you can achieve how Visual Studio handles auto-complete.
Goto Window -> preferences -> java -> Editor -> content Assist ->Advances -> Select all the check boxes. DONE :)
private? It looks like you're creating something new.. eclipse cannot suggest in this case.
Autocomplete is for existing variables/functions/classes/etc.
I tried them one after the other and found out that the correct one is:
Windows -> Preferences -> Java -> Editor ->Content Assist -> Advanced: check Word Proposals
In Eclipse, it can get a variable name that you already made.
For example,
int awesomeVariable;
awesomeVariable = 50;
int superVariable;
superVariable =
If I press Ctrl + Space after that =, it would generate some things that it could fill in. For example, it might suggest awesomeVariable. Basically, it doesn't generate a name for you, it just auto-completes with things you have already created.
Ctrl + Space is maybe shortcuts of IM, so it is covered, I suggest you change the shortcuts of this function, for example: Alt + /,
if you don't know how to change shortcuts, please see the following steps:
click Ctrl + Alt + L twice,
find "Content Assist",
change Binding value to you like shortcuts(cannot same the other shortcuts),
click Apply button.
Thanks for everyones time and help. :)
I finally found it and the answer to this was that in my case the "java.awt.Color" wasn't imported and eclipse doesn't work on this one if it's not imported.
So it does suggest the name for you if your file had imported the class already, but if it hadn't it won't work.
I guess it makes the whole function pretty useless, but unfortunately that's how eclipse works. :/
it just suggesting you can also declare the variable by that name..it just helping you because it was a tool write..nothing to worry about that..you can give your own name as you like kk..
import Color Class to your class: import java.awt.Color;
I'm writting a GUI program.
It has several JPanels that conatin other components. It would be really nice if my code would look like this:
parent component code
child component code
grandchild component code
instead of this:
parent component code
child component code
grandchild component code
It would make the code far more readable. Is(Are) there some character(s) I can put in my code that Java will ignore, but Eclipse would detect it as a part of code that has to have additional indentation?
I know I can do all this manually, but I often set indentation automatically (ctrl+a, ctrl+i). That way I don't have to worry about indentation directly, I can make Eclipse manage it for me. However, that also nullifies any "custom" changes I made myself.
Adding {} does the trick, but it also influences on the way java reads the code, so that doesn't really work.
Maybe there are some plug-ins available for this?
Something that would detect lines like e.g.
//{
and
//}
and then indent code that is enclosed in them?
Select a block of text with the proper opening and closing braces, and then pressing Ctrl+Shift+F will format the selected block of text.
Morevoer, in eclipse you can go to Window -> Preferences -> Java -> Code Style -> Formatter. Here you can create a new formatter profile and assign a lot of your custom formatting rules.
Screenshot for easy reference
I'm trying to add a line break with the Find function in eclipse - What I want to do is put a line after each method in all my classes [I liked them all close together but now its hard to read through]. so I figure theres 2 ways to do this.
1. Find all with "public" and change to "\npublic", \n being the new line in a string to give you the idea of what I mean.
2. A convenient eclipse shortcut that separates all the methods in a class with an empty line.
Any ideas on how to achieve this? I'll be happy as long as it works and I don't have to go through every method in the project myself and push enter .-.
For #2, you can set the Eclipse auto-formatter to do so for you.
Look under the Preferences panel; in the left side (tree), select Java Code Style (click the arrow to expand the section), then Formatter. You can then decide to use a single formatting style for all of your projects, or check the box to apply a special set of formatting rules to just the current project. Some of the options include where to locate whitespace and newlines.
You can also use the “Save Actions” panel to re-apply the same formatting rules every time you save your files. Personally, I use (and team members as well) this method, to ensure that the formatting for the files is always consistent. By mechanically reformatting in this way, changes to the file will always show up “properly” in Subversion/Git — I don't accidentally have whitespace-only changes being introduced into files showing up as “false positive” changes.
Check box 'Regular Expressions' and use '\R' for Linebreak in the 'Replace with' box in eclipse
configure the auto-formatter its a bit of work for the first time but its worth, when ever you get ugly formatted code you can fix this in seconds ..
i am having trouble with custom quick-fixes, which i want to provide in my Eclipse plug-in, and i'm hoping for someone more experienced than me in Eclipse PDE to have some hints for me on this issue.
As i have understood, i can provide custom so-called "quick fixes" (or "resolutions", in Eclipse inside terminology), by extending the extension point org.eclipse.ui.ide.markerResolution for a specific marker id, such as for example some default Eclipse marker, org.eclipse.core.resources.problemmarker.
This works for me for the default marker types and for custom marker types, BUT:
The QuickFixes, which my IMarkerResolutionGenerator provides, are only accessible from the "Problems"-View, not from the Editor, in which my markers show up.
What i have: I create markers in the default text editor, which causes (1) an icon with the markers tooltip message to show up on the left editor ruler at the line, which the marker is assigned to, (2) a marker on the right side of the editor, (3) some underlined characters in the editor, and (4) an entry in the "Problems"-view.
What i want: Just like in Java IDE support, i want to press Strg+1, or Context-Menu->Quick Fix, or to click at the error icon on the left-side-ruler, to see the available quick-fixes and to select one.
However: Only in the Problems-View am i able to get the Quick-Fixes, by pressing Strg+1 or from the context menu.
Is this the normal behaviour, and do i have to access another extension point, or the specific editors features, to hook my quick fixes into them? I haven't found anything much detailed about it, except that everybody seems to be pretty happy with this only extension point that i have mentioned above. What am i missing?
For completion, here is my extension point definition:
<extension point="org.eclipse.ui.ide.markerResolution">
<markerResolutionGenerator
class="com.markers.test.MarkerResolutionGenerator"
markerType="org.eclipse.core.resources.problemmarker">
</markerResolutionGenerator>
</extension>
I have the same problem and I'm not sure, if this is the right way, but at least it works:
If you want to see your quick fixes in the source viewer you have to set an QuickAssistAssistant for it. In your class implementing SourceViewerConfiguration override getQuickAssistAssistant. You can instantiate org.eclipse.jface.text.quickassist.QuickAssistAssistant, but you have to set a QuickAssistProcessor, so implement the org.eclipse.jface.text.quickassist.IQuickAssistProcessor interface, especially computeQuickAssistProposals to return your quick fix proposals.
public IQuickAssistAssistant getQuickAssistAssistant(ISourceViewer sourceViewer) {
IQuickAssistAssistant quickAssist = new QuickAssistAssistant();
quickAssist.setQuickAssistProcessor(new MyQuickAssistProcessor());
quickAssist.setInformationControlCreator(getInformationControlCreator(sourceViewer));
return quickAssist;
}
Also have a look at the code in the last post here, it is a bit messy, but you will get it. And look at this code here for an example implementation of ICompletionProposal, which you will have to return in your QuickAssistProcessor.
If you simply add one line to the marker extension point:
<super type="org.eclipse.core.resources.textmarker"/>
and add attributes to the marker
marker.setAttribute(IMarker.CHAR_START, ...);
marker.setAttribute(IMarker.CHAR_END, ...);
You will be able get this:
But I still can't found how to change marker icon (to variant with bulb) a show possible quick fix also after click on the annotation icon.