In eclipse, can I customize the delegate methods code template? - eclipse

In Java Code Style -> Code Templates there is a "Delegate Methods" option under comments but not under code. I tried changing the "Setter body" template because I wanted to automatically create a bunch of delegated setter methods. However, it didn't work for delegates.
So can I add a Delegate Methods entry to the code part of Code Templates or do I need to do something else?
I am using Eclipse Indigo on Win 7.

To create getter and setter methods, select the field's declaration and invoke Source -> Generate Getter and Setter.
If you use a name prefix or suffix be sure to specify this in the Code Style preference page (Window > Preferences > Java > Code Style).
Another way to create getters and setters is using content assist. Set the cursor in the type body between members and press Ctrl+Space to get the proposals that create a getter or setter method stub.

You can do that but you need to develop a plugin using eclipse's refactoring API provided by the Java Development Tools (JDT) as follows:
Anyone who supports a programming language in an Eclipse-based IDE will be
asked sooner or later to offer automated refactorings - similar to what is
provided by the Java Development Tools (JDT). Since the release of Eclipse 3.1,
at least part of this task (which is by no means simple) is supported by a
language neutral API:the Language Toolkit (LTK). But how is this API used?
Look at this one for a start.

Related

superClass at eclipse IDE plugin Development

I'm developing an eclipse IDE, I faced this plugin xml point.
<option category="elf.compiler.general"
id="elf.compiler.dialect.std.cpp"
name="C++ language standard"
superClass="gnu.cpp.compiler.option.dialect.std"/>
As I understand this plugin point is driven from "gnu.cpp.compiler.option.dialect.std", right?
this class provide c++ compiler versions.
my question is how to see what this class include exactly? and how to add more option to my IDE while still using this class? (lets assume this class have A,B,C options, I want to add D option, I can define my plugin with A,B,C,D options without using dialect.std class but I want to know if I can use Superclass and add new options).
Thanks

Eclipse equivalent of Intellij Dynamic Properties

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.

Include AspectJ support to VS Code

In my current project I'm working with Java, Spring Boot and .aj files. However, the main problem about work with AspectJ is that there are not a lot of IDEs that supports this feature.
Eclipse (and i think that netbeans too) supports the AspectJ language because I've used it in the past. However, I've worked with IntelliJ and Visual Studio Code IDEs during the last years and I don't really want to come back to Eclipse (or Netbeans). :)
Also, I know that the Ultimate Version of IntelliJ has support to AspectJ. The problem is that you must have an IntelliJ license to use it.
https://www.jetbrains.com/help/idea/enabling-aspectj-support-plugins.html
I started to create a new language server for the Visual Studio Code to manage the .aj files. I'm following this guide.
https://code.visualstudio.com/docs/extensions/example-language-server
The .aj files are now correct colored and shows a valid syntax!
However, I'm getting errors in the Java code. Check this schema about the AspectJ description:
As you could see, I have a .java file called Point and I want to have some methods divided in some .aj files. When the project is compiled, I'll have just one Point.class that includes the methods clone(), compareTo(), etc.
Also, another possible use is that if my .java class implements some interface, I'm able to implements the methods in a .aj file.
Problem: I'm not able to see my Java project without errors because the .java files and the .aj files are not "synchronized", so the .java class says that needs to implements some methods although they're defined in the .aj file.
Someone could help me with tips about language server development?
Regards,
I can't help you with VS Code <> AspectJ integration, but I could recommend a work-around with your issue. If my understanding is correct, you get errors because the methods declared through inter-type declarations by your aspects are not visible to your java code.
In that case you might try to create Java 8 interfaces with default methods that declare and implement those methods. I would try to get rid of the aspects altogether and work with just interfaces with default methods, but if - for some reason unknown to me - you really need to use aspects to implement those methods, you can still leave your default methods empty and move the implementation into the aspects. This way you don't need to use inter-type declarations anymore, so VS Code integration might work better.

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.

Eclipse plug-in: Create a new file extension for a language not supported by Eclipse

I am creating an Eclipse plug-in for it to support a new language. The problem I have is with the content type/file association and its respective editor.
The language has no base in Java or XML and let's say its extension is '.xyz'
From what I understood of research online, I would need to create a new Content Type with file extension '.xyz'. But all the information I have found online has related to either associating a new extension with java (for java syntax highlighting) or creating a new type of file which can be a variant of XML, hence having a lot of details about the describer.
Basically, I am confused about the content describer, am I also to create a new describer for a new language? And what base-type would I give for a language not related to XML or JAVA at all?
Also, since I will be adding my own syntax highlighting, would I need to create my own editor or can I just open such a file in the pre-set editorArea (editors).
The package I am looking at for content types is org.eclipse.core.contenttype.contentTypes.
I realised that I never really picked an answer for this question and eventually I found some useful information on it, so I thought I would share it.
This is the information I understood and used; I apologize if there are any errors or I have misunderstood, and I am open to any corrections.
It was actually a lot simpler than I expected.
To create a new file extension, you just need to extend
org.eclipse.core.contenttype.contentTypes
If you are using the PDE, then you can just right click on the extension (once it is added in the extensions tab) and choose New... -> content-type
Here is the xml code for it,
<extension
id="com.newLanguage.XYZ.contentType"
point="org.eclipse.core.contenttype.contentTypes">
<content-type
file-extensions="xyz,xyzz"
id="com.newLanguage.XYZ.contenttypeMod"
name="XYZ File"
priority="normal">
</content-type>
</extension>
Here you can set the properties of this content-type by defining a unique id, a human-readable name and the extension. You can also give multiple extensions for this content type. For example, my XYZ language can have 2 types of extension '.xyz, and '.xyzz'.
The content describer comes in when I have one generic file-extension: '.xy' but the content or format of the file may differentiate and so I need a describer for the editor to be able to go through the content of the file and recognize the difference. This is handy for syntax highlighting where I need to know the differences.
Since I am not very good at explaining this, this link was extremely useful to me.
But all in all, this tutorial is what set me on my pace and has actually taken me far in understanding how to implement an IDE plug-in for Eclipse. I think it is a very ideal place to start, especially for someone new.
Another place that kept my work going is the Eclipse FAQs but I would specifically like to point out to section 3.5 Implementing Support for Your Own Language which has many tutorial links.
Note: this (new language support, custom syntax highlighting, ...) is the kind of feature provided with XText.
Xtext - Language Development Framework
With Xtext you can easily create your own programming languages and domain-specific languages (DSLs).
The framework supports the development of language infrastructures including compilers and interpreters as well as full blown Eclipse-based IDE integration.
Since the sources are available, you might have a lots of clues to illustrate the usage of the packages you are currently looking.