Showing posts with label eclipse. Show all posts
Showing posts with label eclipse. Show all posts

Thursday, March 31, 2011

Method has the same erasure bug in javac

Interesting bug in javac. Consider the two cases:
Case 1:
class Case1 {
    public String foo(Set<String> str) {
        return null;
    }

    public String foo(Set<Integer> str) {
        return null;
    }
}

Case 2:
class Case2 {
    public String foo(Set<String> str) {
        return null;
    }

    public Integer foo(Set<Integer> str) {
        return null;
    }
}

What do you think about them? Should Class1 compile? What about Class2?
In my opinion both of classes should not compile, since methods have the same erasure. In this is exactly what happens in Eclipse.
But, in IntelliJ the Class2 compiles just fine. And Maven also compiles the Class2 without problem.
So how does it happen?
It appears that Eclipse uses it own compiler, while Maven and IntelliJ use javac.
So where is the bug, in Eclipse or javac?
Here the bug that was opened in Eclipse community.
And here the bug in Sun (or should I say Oracle?)
So as you can see, both of them agree with me: the bug is in javac and not in Eclipse. Actually Sun marked it as fixed at 7(b55). Does it mean Java 7?

Tuesday, June 22, 2010

Eclipse Helios RC4 Review

Some time ago I have downloaded the JEE edition of the Eclipse Helios RC4.
And here comes a review in order to win a Helios t-shirt.
I'll start with bugs I found till now. I didn't find many. Continue with features I still miss, and try to end with some positive note about the features I liked.

Bugs

For a RC release there are really few bugs I found till now.
  • In Html Editor the div element does not get idented. Really annoying...
  • Sometimes the key bindings does not work in Package Explorer. For example, when I press F5 I expect "Refresh" to run. Sometimes it happens, sometimes it doesn't.

Missing Features

And not the features I still miss. Please notice: I'm a Java Developer. Meaning I'm talking here about features I miss mainly as a Java Developer and it may be irrelevant for the C/C++/Php and other users. So if you are not a Java Developer, you can probably skip this section.
  • Built-in Maven Support - It's 2010. Most projects I'm involved in the last 5 (five!) years, use Maven for builds, but Eclipse till today ships with Ant plugin only. Hey! Wake up! Almost nobody uses it anymore! And if even some does, there are a lot of Maven users, who need to install the Maven plugins manually. So can you do a favor and add it Maven plugin at least to the distributions for Java and JEE developers?
  • Subversion/Git support - same as Maven: most of the open source projects I know, use Subversion or Git. So may be it's time to include these plugins in the Eclipse distributions?
  • I'm really fond of the "Quick Fix" (Ctrl+1) feature of Eclipse. One suggestion that can be quite easily added to this feature: when there are not initialized final fields in the class, the following error is displayed: "The blank final field may not have been initialized". The quick fix may be to open "Generate Constructor using Fields" dialog.
  • It would be cool to collapse the generics in the fields declaration
    Instead of:
    private Map<String, Set<String>> map = new HashMap<String, Set<String>>();
    it could be:
    private Map<String, Set<String>> map = new HashMap<~>();

New Cool Features

Actually I didn't find many cool features in this release.
  • I'm really fond of "Quick Fix" (Ctrl+1) feature. One of the most annoying "bugs" that is had till now, was placing @SuppressWarnings annotation only on the method level. So now it has two options: place it on method and place it on variable.
  • Refactoring: Move Type to a New File - finally! I was missing this feature for a loooong time!
  • Java debugger has two new neat features: Breakpoints view now contains more details, like "hit count", "conditions" and so on. Variables view contains "instance count", so it is easy to check how many instances of the specific type were created.

Conclusion

I didn't find any new really cool features in this version of Eclipse. 3.5 was a great release, and this release looks like mainly bug fixes. Don't get me wrong: having a stable SDK without bugs is more important than having unstable one with a lot of features.
So nice work, guys! You are doing a great job!


If you got that far and read all this, you may be interested in the plugins I developed for Eclipse:
Tarlog plugins
Encoder Tool

Thanks for reading.

Tuesday, July 21, 2009

Eclipse: Adding Custom Code Templates Programmatically

Here comes the small tip how to add/remove the code templates programmatically.

Warning! This tip includes using the Eclipse internal API. It works fine in 3.5, but may not work in other versions!

First get access to the TemplateStore:
import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.jface.text.templates.persistence.TemplateStore;
...
public TemplateStore getCodeTemplateStore() {
return JavaPlugin.getDefault().getTemplateStore();
}


Delete template:
TemplateStore codeTemplateStore = getCodeTemplateStore();
TemplatePersistenceData templateData = codeTemplateStore.getTemplateData("template.id");
if (templateData != null) {
codeTemplateStore.delete(templateData );
}


Add new template:
String template = // template text
codeTemplateStore.add(new TemplatePersistenceData(new Template("template name", "Description", "java-members", template, true),true, "template.id"));


Save store:
codeTemplateStore.save();

Saturday, June 27, 2009

Eclipse Galileo - The first impression

During the last 5 years it became sort of tradition: I'm waiting till the end of June to download the latest release of Eclipse. The cynics usually say: "Wait for the first SP, the release is always full of bugs!" But I'm never patient enough to wait.

Usually I'm downloading the JEE bundle (the one that previously was called "wtp-all-in-one") and this is exactly what I did this time. The budnle's size for Galileo became larger: 189MB.
The Europa was 126MB and Ganymede was 163MB. Actually wtp-all-in-one 2.0.1 was 259MB, so 189MB is not that large.

Before launching Eclipse, I always take a look to eclipse.ini.
The good news: It now contains predefined memory settings, so it doesn't use the JVM defaults. And you don't need to remember how to set -Xms and -Xmx ("after -vmargs that must be the last arguments in the command line..." and so on).
Somehow it contains the double definition of launcher.XXMaxPermSize (a bug?)
In addition, I prefer setting also PermSize to 256MB and setting both -Xms and -Xmx to the same size: 512MB.
For the first run I decided to leave these settings as is.

So let's see it running... Wow, it started quite fast. If Eclipse became faster, it's really the good news. It always was somewhat slow.

The "Welcome" page. Also different. OK, links to JEE sub-projects... Here it is, the "What's New" section. Click. Click. Click. Hey! What's going on? Nothing happens! Samples? Tutorials? Workbench? Oh, finally it worked. Here comes the Workbench. And where is "What's New"?
Listen, folks, it's very disappointing that you put broken links on the "Welcome" page.

Anyway I think I can find "What's New" section myself: Help -> Help Contents. Wow! This was quick! Workbench User Guide -> What's New in 3.5. Great!

Don't be frightened. I'm not going copy here the whole "What's New" section. I'll only mention the bullets I have really liked:
1. Switching between open editors and multiple editor pages has been streamlined. Ctrl+PageDown and Ctrl+PageUp now always activate the next or previous editor tab, even in multi-page editors. To switch between pages of a multi-page editor, use Alt+PageDown and Alt+PageUp. - Cool! I really hated the previous situation, when multi-page editor makes you stuck, when you're using Ctrl+PageUp to switch between the open editors.
2. The whole "Install New Software" section has been completely changed again. I say "again", since it was completely changed just one year ago. From the first look, it's better now. I've installed CollabNet Desctop pretty smoothly.
3. Textual editors now support block (aka column or rectangular) selection mode. Quite a cool feature.
4. An Open Implementation hyperlink has been added for overridable methods, which directly opens the implementation in case there's only one, or shows all the concrete implementations for that method in the hierarchy of its declaring type, using the quick type hierarchy. By default, the hyperlink appears when you hold down the Ctrl key while hovering over an overridable method.
5. And here comes the coolest feature till now: The new toString() generator allows you to quickly generate a toString() method for your class. I was really missing this feature!
6. As usual there are compiler enhancements with new warnings. Nothing really special, but it's nice to have them. I'm still waiting for the warning about calling non-private methods from the constructors.
7. And the last enhancement, I would like to mention, is using Plug-in Spy in menus. Previously, it was possible to open a Plug-in Spy from Views and Editors only. Now its abilities were extended to menus: click Alt+Shift+f2 and select the menu.

So these were my favorite features from the "What's New" sections. In addition, I paid attention to some unmentioned (but still cool) content assist features. For example, when creating an anonymous class from the interface, the methods are generated automatically.
I believe there are many more features I didn't pay attention yet.

Let's sum up: The first impression from the Eclipse Galileo is very positive. The bugs I paid attention till now are minor and there are a lot of cool features.
In addition, I have a feeling that Eclipse Galileo is faster then the previous release. I hope it isn't just a feeling and that it IS faster.
I'll continue using Galileo and promise to report anything that is worthy mentioning in this blog. So follow up :)

Sunday, June 14, 2009

Eclipse: Fixing Copyright (Copyright Tool)

It's possible to fix (or to set) the Copyright notice in the beginning of the file.
The plugin that fixes copyrights is not included by default in the distribution, but it can be downloaded using the Eclipse update site.
It's called "Eclipse Releng Tools".

The copyright header is set using Window -> Prefernces -> Copyright Tool.
In order to set this header for the whole project, switch to the "Resources" perspective and select "Advanced Fix Copyrights".

Friday, May 1, 2009

Making Eclipse Fly

Accidentally I got to this post, and I must admit that it really works for me.
I believe that it's -Xverify:none flag that makes the difference.

Friday, August 29, 2008

Encoder 0.1.0

And here just another neat tool I have developed for my personal needs and decided to make it public. Meet the Encoder!

So what is it used for?


It is used to encode things from one format to another. The input can be either text or bytes and the same about output. The tool is easily extendable: if you need to perform some special encoding you can implement encoder yourself and plug it into the tool. I'll expand about this functionality in the later post.

Built-in Encoders


Currently the build-in encoders are:
  • To/From Base64
  • Url Encoder/Decoder
  • Inflate/Deflate (optionally uses gzip)
  • Create signature using a private key
  • Verify signature using a public key
  • Verify signature using a certificate


Running the tool


The tool can be run either as an eclipse plugin or as a standalone application. UI is implemented in SWT, which makes it cross-platform. To run the Encoder standalone, download the distribution zip and execute "javaw -jar encoder-0.1.0.jar". You'll need at least Java 5.

I guess that all for now. I'll be happy to get any feedback about the Encoder and see people using it.

Enjoy!

Sunday, July 20, 2008

Open Command Prompt or Windows Explorer in Eclipse

One of the features I miss in Eclipse is an ability to open Windows Explorer and Command Prompt (like CMD Here) on the current file or folder.
So I decided to implement it myself and here it is.
I gave it a huge name, since I hope to add there some more plugins that I miss, but currently it contains only the above features.

Enjoy!

Update: Since this post was written back in 2008, the plugin had some updates. See tarlog-plugins tagged posts.


Recommended Reading

1. Eclipse Rich Client Platform (2nd Edition)
2. Swt/Jface in Action: GUI Design with Eclipse 3.0
3. EMF: Eclipse Modeling Framework (2nd Edition)
4. Effective Java



Saturday, July 19, 2008

Plugin Spy in Eclipse

Did you ever try to implement plugin in Eclipse? If you didn't you can probably skip this post.
But if you did you know that Eclipse PDE is very nice. It provides you a lot of neat wizards that help you to start. However, you often experience a situation, when you want to write a feature that is "almost like that feature that already exists, but...". So what you're lacking is the code of "that feature", so you be able to look on code and do the same. But how the hell can you find this code?
Yes eclipse is open source and yes it comes with all the sources. But it has dozens and dozens of plugins and it can be exhausting to find the relevant plugin.

And here comes the "Plugin Spy", which was added in Eclipse 3.4. Just click Alt+Shift+F1 on the proper place in the workbench and it will show you a lot of useful information. It may be still not easy to find "that feature", but at least it gives you the directions where to start.

Wednesday, May 21, 2008

Generation of Eclipse projects using maven

I believe that everyone who uses maven and eclipse is familiar with eclipse:eclipse goal. For these who are not familiar: get familiar with it as quick as you can! It does a very simple but powerful thing: generates eclipse projects for you with all the dependencies.

And here are some tips:

1. To generate new eclipse project from pom.xml, type "mvn eclipse:eclipse".

2. To generate new eclipse project with source attachments type: "mvn eclipse:eclipse -DdownloadSources=true"

3. To regenerate eclipse project close the project in eclipse and type "mvn eclipse:clean eclipse:eclipse". Add "-DdownloadSources=true", if you like to.

4. Now suppose you have hierarchy of projects. You may like to generate all projects with the proper dependencies between them or you may like to generate a project or two, which are dependent on the repository.
In the first case run "mvn eclipse:eclipse" using root pom.xml. In the second case run "mvn eclipse:eclipse" from the project's directory.

5. To use the projects in eclipse, you need to configure variable called M2_REPO which must point to your local repository. Maven can do it for you by running "mvn -Declipse.workspace= eclipse:add-maven-repo". Although I don't find this feature very useful, since you need to do it only once per workspace and it can be shortly done manually.

Wednesday, April 9, 2008

Cut and Paste of strings in Eclipse

One important feature of IntelliJ that Eclipse was lacking (at least I thought so) is an automatic escaping when pasting strings.
So it appeared that Eclipse does not lack this feature, but for some reason it's unchecked by default and it's not easy to find it.

And here it is:
Windows --> Preferences --> Java --> Editor --> Typing --> In string literals --> Escape text when pasting into string literals


Recommended Reading

1. Guards! Guards!
2. Witches Abroad
3. Wyrd Sisters

Tuesday, April 8, 2008

EclEmma 1.3.1 - Java Code Coverage for Eclipse

A very nice plugin that shows code coverege.
It supports:
* Local Java application
* Eclipse/RCP application
* JUnit test
* JUnit plug-in test
* TestNG test
* Equinox OSGi framework

EclEmma web site
Update site for eclipse: http://update.eclemma.org/

Enjoy!

Saturday, April 5, 2008

Just discovered two very-very nice features of Eclipse:
1. Build in TCP/IP monitor that acts as intercepting proxy. No need for special Fiddler configuration or TCPMON anymore.
2. Ctrl+3. Click it and type "tcp monitor" or "new class" and see what happens.

P.S. Btw, the feature that all IntelliJ users was so proud of: the ability to find class by its capital letters is also supported. I'm not sure when it was added to IDE, but now it just works. Example: Click Ctrl+Shift+T and type "SB" you'll get both StringBuilder and StringBuffer.

Original post

Thursday, April 3, 2008

Arguments to run Eclipse

Usually when you run eclipse, you need to put some arguments to the command line. Many people do it, but doesn't know that eclipse also takes arguments from the file eclipse.ini, which is located in the eclipse root folder.

No paying attention to this file, sometimes causes errors during the start-up. Furthermore, the behavior of Eclipse often becomes different from the expected.

So the first purpose of this post is to increase awareness regarding the eclipse.ini file.

The second purpose is to keep an example of eclipse.ini here:

-showsplash
org.eclipse.platform
-clean
-vm
C:\jdk1.5.0_11\bin\javaw.exe
-vmargs
-XX:MaxPermSize=256m
-Xms512m
-Xmx512m


To sum it up:
1. Most of the arguments that are needed to run Eclipse I put to eclipse.ini file.
2. The only argument I add to shortcut is -data <path to workspace> in order to specify the workspace.

1/05/2009: Make Eclipse Faster:
-showsplash
org.eclipse.platform
-framework
plugins\org.eclipse.osgi_3.4.3.R34x_v20081215-1030.jar
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms512m
-Xmx512m
-XX:PermSize=256m
-XX:MaxPermSize=256m
-Xverify:none
-XX:+UseConcMarkSweepGC
-XX:+CMSClassUnloadingEnabled
-XX:+CMSPermGenSweepingEnabled