Hi,

I want to customize the add unimplemented method in eclipse based on some condition. I wants to put some programming logic in eclipse based on that condition i want that it will generate the code for unimplemented method.

Any help will be appreciated.

Thanks in advance

Recommended Answers

All 15 Replies

may I ask why you want to do this?

so, if I understand your question correctly:
you want, if you create a method:

public int addTwoIntegers(int one, int two){

}

your IDE to automatically generate something like:

public int addTwoIntegers(int one, int two){
return one + two;
}

??

how do you think to do something like this?
just because the methodname and params
public int addTwoIntegers(int one, int two)

are perfectly clear for you, your compiler/IDE/... will NOT know what you want it to do (what logic you want in it) or what it means until you actually code that logic. To the compiler, this is just a methodname that needs to follow certain rules: either static or return-type, followed by (<params here>) and a block of code between brackets, ...

So, unless you come up with a very impressive AI, teach it to understand the language in which you code AND teach it all the logic you'll ever use, I doubt you'll have much success implementing such an option.

naturally, I could have misunderstood your question.

Eclipse's add unimplemented methods is a helper that kicks in when you declare a class that implements an interface or extends an abstract class but doesn't have all the necessary methods. The helper adds stub (empty) methods for all the missing methods. It's particularly useful when creating anonymous inner classes for Swing listeners.
pankajagar: what are the "conditions" and kind of code do you want to generate here?

Thanks all for reply.


Actually as for the faster code development i want to implement this functionality. I will put some logic based on the className.

My application has some layers. For example :
1. UI layer
2. Service Layer
3. Persistor Layer

In service layer and persistor layer. i define one interface and two class implements that interface.

For example

In service layer

RequestService (Interface)
RequestServiceImpl (Implementaion)
RequestServiceOfflineImpl (Implementaion)


In persistor Layer

RequestPersistor (Interface)
RequestPersistorImpl (Implementaion)
RequestPersistorOfflineImpl (Implementaion)


I wants to generate code based on which layer i defined the method in interface.


For example if i am in service layer and my interface has following method.

// In service layer interface
public void show();

Then i want to generate the following code when i implement method in service layer

public void show(){
Start logging
End logging
}

Similarly if i implement a method in persistor layer then i wants to also perform serval predefind functioanlity like logging, connection open, close and others.

Its help me a lot to write code faster.

Please suggest to implement this.

implement the code like that and you won't be able to compile your code.
Start logging and End loggin.
are these supposed to be comments, method calls, .. ?

Maybe you should be using abstract classes rather than interfaces and defining that common code in the abstract superclass?

These are just the example of functionality that i wants to implement. There will be some logical code that will do logging. Actually in each method i need to write this code. for service and persistor layer. I just want to automate this process.

Maybe you should be using abstract classes rather than interfaces and defining that common code in the abstract superclass?

Hi James,

its just an example. There will be lot of classes in each layer and each class will consist several methods. That is only the reason. Application is developed by many people. So i want whenever a person add a method in interface, the class implementing this interface should consist atleast minimum required code like logging, connection open and close, release connection etc.

That does sound like a case for inheriting those "skeleton" methods, Maybe using this pattern:

public void doSomeNewStuff() { // this is a new method that others will call
  openConnection();
  logStuff();
  doSomeNewStuffImplementation();
  closeConnection();
}
abstract protected void doSomeNewStuffImplementation(); // this is where subclasses implement their own stuff

That does sound like a case for inheriting those "skeleton" methods, Maybe using this pattern:

public void doSomeNewStuff() { // this is a new method that others will call
  openConnection();
  logStuff();
  doSomeNewStuffImplementation();
  closeConnection();
}
abstract protected void doSomeNewStuffImplementation(); // this is where subclasses implement their own stuff

Thanks JamesCherrill for reply.

But this approach will not work for me as this is an existing application and it is very big. I cann't modify the architecture of that application. In a simplest way i can say that i am looking for some template type approach which is used to generate the implementation of method from interface based on some condition.

unless your IDE "understands" the names of your methods and your intention, I don't see how to do something like that, if not in a way like JamesCherrill suggested.

It means in eclipse there is no way to customize add unimplemented method functionlity. My condition will based on the file name.
If file name consist 'service' then generate the some code.


if file name contains 'persistor' then generate the some another code.

while implement the method from interface.

Its also help me if anyone tell me the way to find the list of unimplmented method in class file. For example if Class A implementing interface B then i want the list of unimplmented method of Class A.

Its also help me if anyone tell me the way to find the list of unimplmented method in class file. For example if Class A implementing interface B then i want the list of unimplmented method of Class A.

Eclipse will generate an error in that case, and can add the method headers/stubs for any/all missing methods, so you can see exactly what they are.

Eclipse will generate an error in that case, and can add the method headers/stubs for any/all missing methods, so you can see exactly what they are.

i know this thing. I want to know programtically how i can find the list of unimplmented method.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.