Eclipse equivalent of Intellij Dynamic Properties - eclipse

in our development team we have both Eclipse & Intellij IDEA users, with my team working mainly in Groovy.
We junior developers on this specific team, while working on an IDE with full access to all the relevant classes we need, still copy-paste the scripts into our web-ui, which internally runs them based on the specific rules and settings.
Since the script runner, afaik, injects certain variables into the environment, they are available for use in the scripts but are unavailable for the IDE to autocomplete.
In Intellij, we declare them as Dynamic Properties for each script on the IDE level, so that the IntelliSense treats these as objects of the type they are, but I am not able to find an equivalent functionality in Eclipse, nor much information about anyone with a similar situation.
For example, in the following script:
def location = locationService.findLocationById(123)
Where locationService is an object of a type which implements ILocationService. When ran on the server, location is correctly identified as of type Location, but the IDE cannot infer it, of course.
In Intellij, I can add a Dynamic Property for locationService, identifying it as of type 'ILocationService'.
Is that even possible on Eclipe?
Thanks!

If you want to add type inference suggestions to the editor so that it can provide content assist for variable expressions, there are a couple possibilities within Eclipse:
Place caret (cursor) over "location" in your script, press Ctrl+1 to open Quick Assist menu and choose Add inferencing suggestion. In the dialog, set Type to the fully-qualified type of the variable. This assist may not be offered unless you have DSLD support enabled in your workspace (Window > Preferences > Groovy > DSLD > Disable DSLD Support in your workspace must be unchecked).
Create a DSLD for your scripts that supplies the type. This is a bit more complicated but is much more flexible in handling delegate types and so forth. See https://github.com/groovy/groovy-eclipse/wiki/DSL-Descriptors (IntelliJ has GDSL which is very similar).
Cast or coerce the variable in your script. May be a little heavy handed, but certainly the easiest to implement.
I think you can provide a BaseScript annotation that could give some additional hints at what will be present in the script's Binding.

Related

Sharing common helper scripts among projects in VSCode

I have a few utility functions, snippets and scratches that I want to be able to use in every project.
Currently I have the following setup for Clojure projects and Intellij IDEA/Cursive:
I have a user profile defined in .lein, where I have source-paths pointing to
when I sync and run REPL for project in IDEA/Cursive, I check that :user profile is selected (it is the default)
Cursive shows both project files and common files (i.e. scratches folder) in project pane
I can edit and eval in REPL real project files and my local helers/scratchpads seamlessly.
Is there a way to achieve this behaviour in VSCode?
Notes:
My clojure setup in Cursive is for illustration purposes only. I would like to find a way to get similar feature in other scripting languages (i.e. python, groovy). So ideally I don't want to use leiningen for that, but rather find a generic way to add common source folder to VS code Explorer pane.
I know that with multi-root workspaces I can achieve what I want, but it must be done manually per project. It would be much better if my folder with common utils was added to every workspace automatically. Something like a default workspace template would solve this, but I couldn't find anything similar. Am I missing something?

How do I get proper syntax highlighting in Eclipse when developing a shared library of Jenkins?

I'm in the process of developing a shared library for Jenkins with scripts in vars/ and classes in src/.
I have these two stumbling blocks:
I use a Jenkins-specific method sh or echo. It is greyed out because Eclipse doesn't recognize it as a proper Groovy method. Is there a way to make these "known" to Eclipse?
I create a file vars/foo.groovy with two methods, call() and helper(). Using foo() anywhere int he program results in it being greyed out, suggesting that Eclipse doesn't know what this refers to. Is there a way to make Eclipse understand that foo() is now a legal method?
Note that inside foo.groovy, both call() and helper() are recognized as valid methods. The same holds true for a class src/clazz.groovy - using new clazz() gets recognized everywhere in the shared library as valid code and the shown doc refers to the clazz.groovy file.
All of this works fine if run on Jenkins, this is purely about syntax highlighting and, if possible, showing the Javadoc when hovering over the functions. Syntax highlighting is the main concern, though, as it is a PITA to deploy a shared library only to notice there's a typo in some function somewhere I didn't catch because it's all greyed out.
The default Groovy syntax highlighting works, this is just about methods relating directly to Jenkins and/or the shared library.
This doesn't help me as it refers to IntelliJ which is sadly not an option.
You can add individual inference suggestions using quick assist (Ctrl+1) or you can create a DSLD that gives more complete slash complex information. If your script is using methods defined by a specific type, you can use #BaseScript annotation.
If your scripts (in vars folder) are not part of project classpath, they won't be available for import or static import.

Need brief understanding on how eclipse autocomplete works

Hi I am interested in understanding how eclipse autocomplete works. I want to understand how eclipse distinguishes between local and global variables in a piece of Java code. I would also like to understand how eclipse stores method signatures for an infinite number of classes and how it associates a method to a given class. And is it possible for one person to develop an autocomplete feature for a language like JavaScript.
There is already an AutoComplete feature for Javascript. You just need to let Eclipse install the appropriate extensions.
Eclipse maintains a model of your program, including the project and all the dependencies. It's big, but it's not infinite. When you hit the dot, it figures out based on the variable type what the target type can be, and then displays the relevant methods based on its internal model.
This is easy for Java because you can usually know the static type. Much harder in other languages.
The Eclipse plug-in developer's guide discusses how different things, including the internal model and auto completion works. There are extension points to implement yiur own.

IJavaProject without Eclipse Environment in JDT

I have an exported Eclipse Java Project in my server and I want to be able to compile the project and use ASTParser with JDT.
I'm able to compile the project using BatchCompiler, however it runs on console and gives me PrintWriters instead of an array of problems and errors. Also I want to be able to use proposals in Eclipse and BatchCompiler didn't built for this purpose.
Therefore I tried to use ASTParser, it can be used with either char[] or ICompilationUnit. CompletionProposalCollector and org.eclipse.jdt.internal.compiler.Compiler.Compiler needs ICompilationUnit so I have to create an ICompilationUnit which only can be created by an IJavaProject (https://dl.dropboxusercontent.com/u/10773282/2012/eclipse_workspace.pdf) in order to be able to use these features.
It seems the only way to create IJavaProject is to use ResourcesPlugin.getWorkspace(), however it returns java.lang.IllegalStateException: Workspace is closed. on my computer and it seems the reason is that the program that I coded is not an Eclipse plug-in.
Is there any way to create IJavaProject without Eclipse environment?
From the comments, it looks like you are trying to do more than just parsing, you actually want to get some form of content assist.
I'm afraid that you're asking for too much. There is no simple way to get the power and flexibility of JDT outside of a running Eclipse instance (believe me, I've tried). There's no simple way, but if you are brave and strong willed, you can one of try following:
Run a headless Eclipse on your server that works on top of an actual workspace. This would be the easiest to implement, but would be the most resource intensive and least flexible way of doing things.
Use the jdt core jar, and create alternate implementations of the IResource hierarchy, and the parts of JFace that are used by the the parser and the CompletionEngine. This would likely be the most feature-rich way to go, but also the most brittle. I can't guarantee that this would work as you may need to create some very complex stubs for internal Eclipse non-API classes.
Avoid the CompletionEngine and the ASTParser entirely and just use the batch compiler. You would then need to provide an alternate implementation of org.eclipse.jdt.internal.compiler.env.INameEnvironment. This implementation would be able to find types, files, and compilation units in your actual project structure. You'd need to reimplement support for content assist, but this would most likely work reasonably well.
I am actually fairly interested in doing something like this (but I lack the time to do it). If you are seriously considering creating a headless JDT that can run on a server, feel free to ask for more information. I am quite familiar with JDT internals.
I've had a similar problem. Here is how to use ASTParser without Eclipse (it just needs the core JDT JAR on the classpath): http://blog.pdark.de/2010/11/05/using-eclipse-to-parse-java-code/

How to setup a new language IDE

At work we are using a proprietary language and to program we are using Notepad++ with a simple code highlight. That is really annoying so, what I want to do is to invest some time to setup a text editor or an existing IDE to support my language.
I've googled a lot and there are so many options and before starting to work I wanna ask to you what is the best choice.
What I want to do is to have, like an IDE, a syntax highlight, a window with the function list tree, with the local function variables inside the same subtree, maybe text autocomplete (if I type "pro" I would like to see the suggestion "procedure" and if I press enter it will write for me something like
procedure "name" {
--code--
}
with the cursor on "name" ready to change it.
etc etc...
Can you suggest me the right path to follow?
Is it to keep using Notepad++? With sourcecookifier? functionlist?
Or I have to change to another text editor?
Or there is some famous IDE like Eclipse, NetBeans etc that allow to easily add my own language?
PS. my language is pretty simple, I don't have complex structures, is Pascal-like. Something like that:
variable int xyz
PROCEDURE asd
BEGIN
END PROCEDURE asd
I would recommend you to stay with Notepad++ and extend it with some plugins and configuration. This would be fairly quick and easy to set up and still give a big win, even though you might not be able to get all the nice features of something like Eclipse. But since you already know the Notepad++ it wouldn't require learning an entirely new tool.
Some plugins that I have found useful
Function List
Light Explorer
XBrackets Lite
There are probably a lot more that can be useful to you.
Notepad++ also got some built in auto-completion functionality that can be enabled in the settings.
Have you evaluated Eclipse XTEXT ?
What is Xtext?
Xtext is a framework for development of programming languages and domain specific languages.
The only IDE I have used for the last few years is Eclipse. There are lots of other IDEs available, also notable and popular is Netbeans. There are many others. It's important to note that all IDEs have their fans, but I can only speak to Eclipse.
Eclipse is a platform, which means it is an application on which you can build other applications. Eclipse provides a framework which you can customize and extend to produce a working application. It takes care of the user interface, preferences storage, modularisation using OSGi, and lots of other things.
Eclipse has facilities to support what you're looking for:
Syntax highlighting in the editor.
The Outline View provides function and variable listing in a tree
Autocompletion and Suggestions (activated by hitting ctrl-space)
Code Templates to fill out files and procedures etc.
The disadvantage is that customising and extending Eclipse to do what you want isn't trivial. Having written a language debugger for Eclipse, I can tell you that leveraging Eclipse's platform helped enormously, but there's a learning curve. You'd essentially have to be coming up with a new set of plugins to provide your highlighting, outlining, autocomplete suggestions and templates (I'm not sure if template support is built into the platform or not).
So I would say, unless you can find some sort of extensible editor for Eclipse - I know Aptana is extensible for tag-based markup - you are probably as well staying with your existing tooling.
Do explore the other IDEs though - I've heard good things about IDEA as well as Netbeans. :)
Good luck!
I can recommend SynWrite editor. Good support for external languages, fully customizable. (Editor of new lexers is there)