What do these Eclipse PyDev template variables do? ('next_class_or_method', 'prev_class_or_method') - eclipse

I'm customizing some code templates for PyDev (Eclipse). Inside the Edit Template dialog, which can be found at:
Preferences => PyDev => Editor => Templates => {select_a_template} => Edit => Insert Variable
..there are a number of built-in variables. Most of them make sense, but there are 2 that don't, namely: ${next_class_or_method} and ${prev_class_or_method}
What does that even mean in (either of) the context(s) of Eclipse Templates??
How would one go about using such a thing in a code template?
What would be even better, would be if there were some file in PyDev that could be altered to allow me to make my own "built-ins".
Does anyone out there know of these things?

Those give you the next declared class or the next declared method.
For an example that uses the ${next_class_or_method}, take a look at: http://pydev.blogspot.com.br/2011/06/overrideimplements-templates-on-pydev.html
For the previous one, I don't have an example (it's a mix of the ${current_class} and ${current_method} -- which is used on the 'super' templates, but it won't distinguish if you have a class or a method before it).

Related

Eclipse CDT eclox reference autocompletion

I just started working with doxygen and eclox (eclipse CDT, C++) and love the whole package. There's only one thing I'm really missing: whenever I try to add a \ref to a function, class or variable, I have to manually remember the (fully namespace qualified) name of what I want to refer to.
It would be AWESOME if it was possible to use the (already existing) code completion feature from eclipse to suggest the right function, class, etc.
Like so:
/**
text yadayada bla \ref std::str<ctrl + space here> -> complete to std::string so that doxygen understands the link
*/
Is that possible? I'm actually surprised that I couldn't find anything about this elsewhere. Is everybody really inserting all references manually all the time?
It becomes quite cumbersome when referring to e.g. imed::helmbus::io::subclasses::CAN_Reader
Adding a reference to this should work the same way as when I'm actually coding:
/**
\ref ime<ctrl+space> -> show list of namespaces beginning with 'ime' -> complete to 'imed::'<ctrl+space> -> show list of subnamespaces -> ... -> imed::helmbus::io::subclasses::CAN_<ctrl+space> -> complete to CAN_Reader
*/
Or is there maybe a place somehwere where I can find out how to do this? Or why it's impossible?
Thanks!

Eclipse auto completion with method parameter type name

Currently I get this result with Eclipse auto completion.
System.console().printf(format, args)
Of course, Eclipse shows the parameter types as popup, but I want the types to be displayed in front of parameter names too. Like this.
System.console().printf(String format, Object ... args) // `String`, `Object` inserted automatically.
Can I configure Eclipse to show the parameter types too?
Of course not. Eclipse auto completion only suggests valid syntax, while your demand is not valid java code.
An alternative for you might be to open the "Declaration" view or the "JavaDoc" view. Both will always show the declaration/JavaDoc of the currently selected element while you are typing. Therefore you could see the method declaration/javadoc when writing that method call.
Update
Whoever came across this old question. You can use eclipse code mining now:
parameter name hint for Eclipse

How to compare files programmatically in eclipse?

I am developing an eclipse plugin that runs code violation checker on the difference of two versions of a file. Right now I am using diff.exe to get the difference between the two files. But as diff.exe is an extrenal app, I realized that its better to use eclipse built-in compare tool to get the file difference.
So I used org.eclipse.compare and reached up to this point:
public static List<Patch> compare(String old, String recent) {
try{
IRangeComparator left = new TokenComparator(old); //what exactly to be passed in this constructor, a file path, a literal value or something else?
IRangeComparator right = new TokenComparator(recent);
RangeDifference[] diffs = RangeDifferencer.findDifferences(left, right); // This line is throwing NPE
//..
// Process RangeDifferences into Collection of Patch collection
//..
}catch(Exception e){}
//Returns a collection of file differences.
return null;
}
Now the problem is I am not sure what exactly to be passed in the constructor TokenComparator(String). The document says this constructor Creates a TokenComparator for the given string. But it is not written what exactly to be passed in this constructor, a file path, a literal value or something else? When I'm passing a file path or a string literal I am getting NullPointerException on the next line of finding differences.
java.lang.NullPointerException
at org.eclipse.compare.internal.core.LCS.isCappingDisabled(LCS.java:98)
at org.eclipse.compare.internal.core.LCS.longestCommonSubsequence(LCS.java:55)
at org.eclipse.compare.rangedifferencer.RangeComparatorLCS.longestCommonSubsequence(RangeComparatorLCS.java:186)
at org.eclipse.compare.rangedifferencer.RangeComparatorLCS.findDifferences(RangeComparatorLCS.java:31)
at org.eclipse.compare.rangedifferencer.RangeDifferencer.findDifferences(RangeDifferencer.java:98)
at org.eclipse.compare.rangedifferencer.RangeDifferencer.findDifferences(RangeDifferencer.java:82)
at org.eclipse.compare.rangedifferencer.RangeDifferencer.findDifferences(RangeDifferencer.java:67)
at com.dassault_systemes.eclipseplugin.codemonview.util.CodeMonDiff.compare(CodeMonDiff.java:48)
at com.dassault_systemes.eclipseplugin.codemonview.util.CodeMonDiff.main(CodeMonDiff.java:56)
Someone please tell what is right way to proceed.
If the question is What value the token comparators constructor takes then the answer is it takes the input string to compare. Specified in javadoc here http://help.eclipse.org/indigo/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Freference%2Fapi%2Forg%2Feclipse%2Fcompare%2Fcontentmergeviewer%2FTokenComparator.html
TokenComparator(String text)
Creates a TokenComparator for the given string.
And the null pointer yo are getting is because in function isCappingDisabled it tries to open the compare plugin which seems to be null. You seem to be missing a direct dependency to the plugin "org.eclipse.compare.core"
The org.eclipse.compare plugin was never meant to be used in standalone : many of its functionalities require a running instance of Eclipse. Furthermore, it mixes core and UI code within the same plugin, which will lead to unexpected behavior if you are not very careful about what you use and what dependencies are actually available in your environment.
You mentionned that you were developping an Eclipse plugin. However, the NPE you get indicates that you are not running your code as an Eclipse plugin, but rather as a standard Java program. In an Eclipse environment, ComparePlugin.getDefault() cannot return null : the plugin needs to be started for that call to return anything but null.... and the mere loading of the ComparePlugin class within Eclipse is enough to start it.
The answer will be a choice :
You need your code to run as a standalone Java program out of Eclipse. In such an event, you cannot use org.eclipse.compare and diff.exe is probably your best choice (or you could switch to an implementation of diff that was implemented in Java in order to be independent of the platform).
You do not need your program to work in a standalone environment, only as an Eclipse plugin. In this case, you can keep the code you're using. However, when you run your code, you have to launch it as a new "Eclipse application" instead of "Java Application". You might want to look at a tutorial on how to develop Eclipse plugins for this, This simple tutorial from Lars Vogel shows how to run a new Eclipse Application to test an Hello World plugin. You will need a similar code, with a menu entry to launch your plugin somewhere (right-click on a file then select "check violations" in your case?).

Difference between several "import" eclipse code template

In Eclipse 3.7 I've seen java code templates with several variations of the ${import} command:
${:import}
${imp:import}
${x:import}
What's the difference between them?
In the above example you have created 3 variables:
"" (ie blank)
"imp"
"x"
You can use these names to refer to the variables later on within the template. However this seems to be largely useless in the case of import statements.
To get an idea of how this might be used usefully take a look at arraymerge, which is a template shipped with Eclipse, and you will see the result variabe being used in a few places.
I suggest taking a look at the templates that ship with Eclipse and the excellent Useful Eclipse Java Code Templates question to learn a bit more.
Note: Within a template all variables must have unique names, so if you took your example above and added
${:importStatic}
You will get an error, as you have already used "" (blank) as a variable name.

Eclipse caret jumps to constructor while typing

While typing in Eclipse (Java) I often have the problem that when I begin to type accessors, the caret jumps down to the beginning of the constructor definition. So in a document like this:
private int mSomeInt;
public
in|public MyClass(){
}
I would like to manually type out the accessor (getter/setter) for mSomeInt, but when I press space after 'public' above, the caret jumps to the beginning of 'public MyClass'.
I often type complete lines to look up and find my methods jumbled with the constructor (like above).
Any help would be appreciated.
Note - this isn't only with accessors but rather any access modifiers that I define before the constructor or another method.
Edit
After unsuccessfully trying Deco's solution below, I've managed to narrow it down a little further.
The problem only happens if I have all the blocks in the file in a collapsed state (ctrl+shift+numPadDivide). I can see the problem is now that the new access modifier I type is then (quickly) collapsed into the below method. i.e. Eclipse is actually taking the first accessor modifier and collapsing everything from there, even though my intention is actually to write a new method.
The only solution I've been able to find is to only edit the source with all the 'fold' elements unfolded.
Under Window -> Preferences -> <Language> (e.g. Java) -> Editor there is a Content Assist menu item where you can configure auto completion and caret placement as well as auto-activation of it and the delay it uses.
Edit:
After your update to the original question I was able to successfully replicate this in Eclipse Indigo. When you have all of the code blocks collapsed it looks like Eclipse assumes that the code you are writing needs to be in that block (rather than as a variable declaration). I'm not sure if this is expected behaviour or not - but the only way around it I've found is to edit the code with the main block open, and then close it after the fact - or turn folding off altogether.
From what I can tell there are various folding plugins/addons that you can get for Eclipse which override the default behaviour and might function better? A quick Google search will be able to get you a list of them quickly.
I'd probably also suggest posting this as an issue on the Eclipse support site for their official answer.
Unfortunately this issue still exists for me in the latest Elcipse version (Kepler).
As the issue only occurs when the document is 'folded', the work around this is to either disable folding in the editor - or disable folding on 'Members' from the :
Preferences -> Java -> Editor -> Folding