Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:40:12+00:00 2026-05-24T23:40:12+00:00

I have several classes like in the following example: abstract class AClass { boolean

  • 0

I have several classes like in the following example:

abstract class AClass {
  boolean validate(){
    return true;
  }
}

When another class extends AClass, I do it like this:

class BClass extends AClass {
  @Override
  boolean validate() {
    if (!super.validate()) {
        return false;
    }
    // TODO validate
    return true;
  }
}

Is there an eclipse plugin that generates that code for me when I create a new class from the menu(File>New>Class)?
I’m thinking to use an annotation

@Target(ElementType.METHOD)
@interface Code {
    String content();
}

And add it to the method:

abstract class AClass {
    @Code(content = "\tif (!super.validate()) {\r\n" 
        + "\t\treturn false;\r\n" 
        + "\t}\r\n" 
        + "\t// TODO validate\r\n"
        + "\treturn true;")
    boolean validate() {
        return true;
    }
}

The plugin should look for the annotation and generate the code in the newly created class.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:40:12+00:00Added an answer on May 24, 2026 at 11:40 pm

    A solution to my request would be the following:

    Create in a plugin another “New class wizard”, by extending org.eclipse.jdt.internal.ui.wizards.NewElementWizard (similar to the NewClassCreationWizard class) with a page that extends org.eclipse.jdt.ui.wizards.NewTypeWizardPage (like NewClassWizardPage)

    Override org.eclipse.jdt.ui.wizards.NewTypeWizardPage.createTypeMembers(IType, ImportsManager, IProgressMonitor)

    First, call to createInheritedMethods (like in NewClassWizardPage)

    Then, type.getMethods() will give you the inherited methods from the superclass.

    Check if a method from the resulted array has the desired annotation in the superclass (e.g. @Code). If it does, create the new method code, including it’s declaration:

    StringBuffer buf = new StringBuffer();
    buf.append("@Override").append("\n");
    buf.append(Modifier.toString(Modifier.PUBLIC) + " ");
    buf.append(Signature.toString(method.getSignature(), method.getElementName(), method.getParameterNames(), false, true));
    buf.append(" {").append("\n");
    buf.append("// the code from the annotation\n");
    buf.append("}");
    

    Delete the current method:

    method.delete(true, monitor);
    

    Then add the method with the custom code:

    type.createMethod(buf.toString(), null, true, monitor);
    

    Now install the plugin, and when you create a new class with the wizard, the custom code for the methods will be automatically written there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume you have several arbitrary classes like below: class Foo { $foovar; public function
I have mapped several java classes like Customer, Assessment, Rating, ... to a database
Let's say I have a Base class and several Derived classes. Is there any
I have a class, Document and several sub-classes ( Invoice , PurchaseOrder , etc).
If I have interface IFoo, and have several classes that implement it, what is
I have several service classes that have static methods and offer a service to
I have a need for methods in several classes that must always follow a
I have a block of code that basically intializes several classes, but they are
I have an ABC with several derived classes. To create these derived classes I
I have been tasked with converting several php classes into java classes, which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.