Pages

Saturday, April 16, 2011

Code Snippet. Intercepting "On Save" Action in IntelliJIDEA

1. Add the following to META-INF/plugin.xml of your plug-in:
<application-components>
   <component>
      <implementation-class>my.plugin.OnFileSaveComponent</implementation-class>
    </component>
 </application-components>

2. Implement com.intellij.openapi.components.ApplicationComponent:
package my.plugin;

import com.intellij.AppTopics;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManagerAdapter;
import com.intellij.util.messages.MessageBus;
import com.intellij.util.messages.MessageBusConnection;
import org.jetbrains.annotations.NotNull;

public class OnFileSaveComponent implements ApplicationComponent {
  @NotNull
  public String getComponentName() {
    return "My On-Save Component";
  }

  public void initComponent() {
    MessageBus bus = ApplicationManager.getApplication().getMessageBus();

    MessageBusConnection connection = bus.connect();

    connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, 
      new FileDocumentManagerAdapter() {
      @Override
      public void beforeDocumentSaving(Document document) {
         // create your custom logic here
      }
    });
  }

  public void disposeComponent() {
  }
}

That's it! :)

So how could it be used? If you'd like to perform some synchronization with a remote server on each file save in IntelliJ, probably, this code snippet would help you.

Wednesday, April 6, 2011

33rd Degree, 2011, Day 1


ZeroTurnaround is exhibiting at 33rd degree conference in Krakow. In fact, we are the only software product company at the tiny expo here. The others, Luxoft and Tieto are the outsourcing companies, so we feel a bit lonely in this situation. BTW, Luxof has the most meaningless booth I've ever seen - it is huge and it completely ineffective.


Anyways, we've met a lot of smart people asking a lot of smart questions about JRebel and it is tough to answer all kind of questions - I wish I could.

I didn't have much time to attend the sessions myself. However I've managed to escape from the expo area and to attend Ted Neward's talk Busy Developer's Guide to Scala: Patterns. I've got smarter in a way. I've learned about some Scala idioms that diminish some of the classical design patterns that you need to implement in Java from scratch. In fact, I realized that many of the design patterns become obsolete once the target language supports closures.

At the end of the day we've organized the beer party for all the conference attendees. It is a funny thing but people are more interested in JRebel if they're are served with the free beer :)

Friday, April 1, 2011

Just Some Java Reflection Madness

import java.lang.reflect.Field;

public class Test {

  public static void main(String[] args) throws Exception {
    doStuff();
    System.out.println("Hello".equals("World"));  // --> true
  }

  public static void doStuff() throws Exception {
    Field value = String.class.getDeclaredField("value");
    value.setAccessible(true);
    value.set("Hello", "World".toCharArray());
  }

}

http://www.javaspecialists.eu/talks/oslo09/ReflectionMadness.pdf

Disqus for Code Impossible