Coder Social home page Coder Social logo

vscode-java-code-generator's Introduction

Code Generator For Java

Buy Me A Coffee

Features

  • Generator GUI
  • Generate Setters & Getters
  • Generate toString()
  • Generate Constructor
  • Generate Constructor Using Fields
  • Generate Equals And HashCode
  • Generate Fluent Setters
  • Generate Logger Debug
  • Generate SerialVersionUID

Usage

how use

vscode-java-code-generator's People

Contributors

0x15f9 avatar aaronctech avatar sohibegit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vscode-java-code-generator's Issues

Require this in getters

I would prefer the usage of this in getter code generation:

public int getWidth() {
    return this.width;
}

Could this be an option?

Generate super class contructor

This would be a nice option to have in the GUI.

Generate a class constructor with the arguments of parent class and the call to super() with parent constructor arguments, and the additional assigning variable values which you currently have.

Not found error

I am unable to run this extension, it was working before. So I tried to reinstall it and same error.

snap-34

Sohibe code generator no longer working

I've taught the Sohibe code generators for Java in my Java courses at UC Santa Barbara for over a year now.

They suddenly stopped working for me sometime between December and now. It may have been the 7.0.0 release, I'm not sure.

The symptom is simple: I install the extension, but the menus that I'm used to seeing when I right click in a Java file simply aren't there:

image

The extensions is installed, but nothing works

image

I don't even know where to begin with trying to determine what is wrong. I really miss the functionality.

I made a token monetary donation to the project as a show of good faith.

Copy Javadoc to getters/setters

Coming from this discussion on Stack Overflow I search for a possibility to add Javadoc of property fields to getters and setters. While project lombok can be a solution I have some projects I need an alternative approach without any additional dependencies.

Because of this I'd like to ask if it's possible to add some functionality that copies Javadoc from property fields to the generated getters and setters.

Wrong class might be used if there is more than one class in a file

Create a file with the following:

class Class1 {

}

class Class2 {
    private int wat; // generate constructor, hashCode and equals on this gives

    public Class1{}(int wat) { // This should have Class2
        this.wat = wat;
    }

    @Override
    public boolean equals(Object o) {
        if (o == this)
            return true;
        if (!(o instanceof Class1{})) { // Again the wrong class
            return false;
        }
        Class1{} class1{} = (Class1{}) o; // And again
        return wat == class1{}.wat; // And again
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(wat);
    }


}

Getters and fluent setters only

I would like to have the possibility to generate getters and fluent setters - but NO "normal" setters.
Furthermore, the method names of the fluent setters should conform to the JavaBeans Naming Conventions.
I don't want two different kind of setters.

Or is this already possible and I simply failed badly at adapting the configuration settings properly?
Thanks in advance!

Example:

public class Whatever {

   private String propertyA;
   
   public String getPropertyA() {
       return propertyA;
   }
   
   public Whatever setPropertyA(String propertyA) {
       this.propertyA = propertyA;
       return this;
   }

}

Automatically create class by Filename and package

HI,

it would be nice, if the extension could automatically create a class inside the .java file with the filename as class-name and automatically set the package.

ideally via a button in the right-click context menu, as some people may not want this to automatically happen.

Feature request: Option to add @Generated annotation

If enabled, this would add @Generated("sohibe.java-generate-setters-getters") (or a similar unique identifier string) as an annotation to each generated method.

For example:

@Generated("sohibe.java-generate-setters-getters")
public String toString() {
  // ...
}

It would be up to the user to add the import for the annotation.

Creating constructor does not work

Wanted to create a constructor for a class, but it missed the last character of the class name and the opening bracket
I am using VS Code 1.66.1 on Windows 10

Example Code:

public class SplashScreen extends GameScreen {

    public SplashScree) {
    }
    
}

Additional Info: only happens when there are no attributes in the class and i use "Generate Constructor Using All Fields"

Support for Hungarian Notation

Property names such as "_property" or "m_property" result in a getter name of "get_property" and "getM_property" respectively. Ideally both would still produce the name "getProperty".

Add fluent setters support for Record

Taking advantage of lates JDK versions, is possible to use the record type, for immutable objects, which reduce a lot the dependency from Lombok, nevertheless, the builder pattern (a.k.a. fluent), is a beautiful and clean way to develop mappers and logic around how you set field values of an object. I still use Lombok just for the @Builder, but it causes issues for native builds with Graalvm.

@Builder
public record Transaction (
    UUID id,
    BigDecimal amount,
    String merchant,
    Long date,
    Long createdAt
) { }

So, you can build something like:

  static Transaction toModel(TransactionEntity entity) {
      return Transaction
          .builder()
          .id(entity.id())
          .amount(entity.amount())
          .merchant(entity.merchant())
          .date(entity.date())
          .type(entity.type())
          .createdAt(entity.createdAt())
          .build();
    }

Today, if you try Generate Only Fluent Setters it causes an error (and ask you to submit an issue 😄)

image

Does not work with nested, inner class

Plugin version: 7.0.1
Platform: Linux

The wrong ctor is created when trying to create for inner class Product, also the indentation are off, see code below.

Other issues

  1. I am not able to generate getter, setter,
  2. wrong equals and hashCode is generated for inner class
  3. wrong toString generated for inner class
public class Cart {

  long id;
  long count;
  String user;

  class Product {

    long id;
    String name;
    String description;
    double price;


  public Cart(long id, long count, String user) {
    this.id = id;
    this.count = count;
    this.user = user;
  }


  }

}

Creating constructors for static attributes and no attributes

Good morning, I noticed a problem when I create a constructor for my class when it has no attributes or only static attributes, the constructor misses the last letter of the class name and the first parenthesis, example.

public class Converter {
  public static int id = 0;

  public static int toConvert(int points) {
    return points * 100;
  }

  // Building a empty constructor
  public Converter() {
  }
  // Building a constructor with all fields
  public Converte) {
  }

}

Extension Doesnt Work

When I attempt to use the features, I just get an error message saying that ->
Command 'Generate Getters And Setters' resulted in an error (command 'extension.javaGenerateGettersAndSetter' not found).

Override methods from superclass

It would be cool to be able to generate constructors from super class (like in eclipse) or generate code for methods to override in general.

Generator GUI - constructor using fields not returning

Issue

The Constructor with no parameters selected should give empty constructor but it is generating wrong code, altough there is an option to generate empty constructor seperately but this option with no fields should raise an error or create an empty constructor.

How to regenerate.

A simple java class

public class Module {
    String first;
    String second;
    String third;
}
  1. Open Generator GUI
  2. Unselect all fields
  3. Select Constructor using fields

The generated code pattern will be like this

    public Modul) {
    }

where the last character in the name of the class is replaced by ).

Fluent Setter should call Simple Setter

In case a Simple Setter method is altered to implement some custom behavior, the Fluent Setter is better off calling the Simple Setter, rather than setting the field directly. If there's no Setter method, current behavior of setting the property directly is ok.

Opening braces on new line

Would it be possible to add an option to put the method's opening brace on a new line instead of the same line as the method declaration?

public Object getFoo()
{
    // whatever
}

instead of

public Object getFoo() {
    // whatever
}

False error, Empty constructor already exists

Please see screen shot, I am getting this error and unable to create a empty ctor (bottom right).

snap-36

Also when I select all the field I get the same error.

snap-37

After I close the GUI and reopen it, I am able to create multiple empty ctor.

snap-38

Feature request: Option to copy @JsonProperty annotations

If enabled, this would copy @JsonProperty annotations from variables to getters/setters.

For example:

@JsonProperty("vid")
private Integer visitorId;

@JsonProperty("vid")
public Integer getVisitorId() {
  return visitorId;
}

@JsonProperty("vid")
public void setVisitorId(Integer visitorId) {
  this.visitorId = visitorId;
}

This should be an option rather than a default because it's only necessary for some library versions.

It would be up to the user to add the import for the annotation.

GUI re-enables auto close

When I de-select "Auto close" the next time I bring up the GUI, I expect this setting to be remembered. This is not the case, and I am forced to turn off "Auto close" all the time.

Feature Request : generate serialVersionUID

It would be great feature if vscode-java-code-generator can general serialVersionUID

static final long serialVersionUID = -687991492884005033L;  //some random number

Thanks

GUI doesn't generate default ctor

Give the class below, bring up GUI

public class Person {

  private String name;
  private String surname;
  private int age;

}
  1. de-select auto close
  2. click on "Ctor using fields"
  3. de-select all fields
  4. click on "Ctor using fields"

Step 4 no default ctor is created.

Suggestion I would also make the "Auto close" option off by default. I didn't notice it at first and found the GUI annoying have to re-open multiple times to generate code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.