Giter Club home page Giter Club logo

valueclassgenerator's Introduction

Metrics

valueclassgenerator's People

Contributors

benjohnde avatar ingwersaft avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

valueclassgenerator's Issues

add support for value class "enums"

example:

public static class Status {
        private static final String STARTED = "started";
        private static final String FINISHED = "finished";
        private String status;

        public static Status of(String given) {
            if (STARTED.equals(given)) {
                return Status.started();
            }
            if (FINISHED.equals(given)) {
                return Status.finished();
            }

            throw new IllegalArgumentException(given + " not a valid Status");
        }

        public static Status started() {
            return new Status(STARTED);
        }

        public static Status finished() {
            return new Status(FINISHED);
        }

        private Status(String status) {
            this.status = status;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            Status status1 = (Status) o;

            return status.equals(status1.status);
        }

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

        @Override
        public String toString() {
            return "Status[" + status + "]";
        }

        public String get() {
            return status;
        }
    }

best if this is done with the gui: select fields which shall be value enums. for selected field(s), open new gui asking for possible values.

Possible StringIndexOutOfBoundsException

Trying to invoke ValueClassGenerator on a class which contains no properties at all throws the following exception:

String index out of range: -3
java.lang.StringIndexOutOfBoundsException: String index out of range: -3
	at java.lang.String.substring(String.java:1967)
	at com.kesselring.valuegenerator.generator.ValueClass.createEquals(ValueClass.java:94)
	at com.kesselring.valuegenerator.generator.ValueClass.asString(ValueClass.java:57)
	at com.kesselring.valuegenerator.generator.ValueClass.getGeneratedPsiElements(ValueClass.java:126)
	at com.kesselring.valuegenerator.GeneratedValueWriter.run(GeneratedValueWriter.java:47)
	at com.intellij.openapi.command.WriteCommandAction$1.run(WriteCommandAction.java:252)
	at com.intellij.openapi.command.WriteCommandAction$Simple.run(WriteCommandAction.java:234)
	at com.intellij.openapi.application.RunResult.run(RunResult.java:35)
	at com.intellij.openapi.command.WriteCommandAction.lambda$null$1(WriteCommandAction.java:171)
	at com.intellij.openapi.application.impl.ApplicationImpl.runWriteAction(ApplicationImpl.java:1031)
	at com.intellij.openapi.command.WriteCommandAction.lambda$performWriteCommandAction$2(WriteCommandAction.java:170)
	at com.intellij.openapi.command.WriteCommandAction.lambda$doExecuteCommand$4(WriteCommandAction.java:210)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:141)
	at com.intellij.openapi.command.impl.CoreCommandProcessor.executeCommand(CoreCommandProcessor.java:119)
	at com.intellij.openapi.command.WriteCommandAction.doExecuteCommand(WriteCommandAction.java:212)
	at com.intellij.openapi.command.WriteCommandAction.performWriteCommandAction(WriteCommandAction.java:168)
	at com.intellij.openapi.command.WriteCommandAction.execute(WriteCommandAction.java:151)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:254)
	at com.intellij.openapi.command.WriteCommandAction.runWriteCommandAction(WriteCommandAction.java:241)
	at com.kesselring.valuegenerator.GenerateValueClassHandler.doExecute(GenerateValueClassHandler.java:64)
	at com.intellij.openapi.editor.actionSystem.EditorActionHandler$4.perform(EditorActionHandler.java:217)

For better UX either disable the context menu entry or show modal dialog. KISS approach would be do nothing.

Cheers!

create basic functionality

starting code:

public class User {
    private String name, surname, address;
    private Integer age;
}

to:

public class User {
    public final Name name;
    public final Surname surname;
    public final Address address;
    public final Age age;

    public User(Name name, Surname surname, Address address, Age age) {
        this.name = name;
        this.surname = surname;
        this.address = address;
        this.age = age;
    }

    public static final class Name {
        private final String name;

        public String get() {
            return name;
        }

        public Name(String name) {
            this.name = name;
        }
    }

    public static final class Surname {
        private final String surname;

        public String get() {
            return surname;
        }

        public Surname(String surname) {
            this.surname = surname;
        }
    }

    public static final class Address {
        private final String adress;

        public String get() {
            return adress;
        }

        public Address(String adress) {
            this.adress = adress;
        }
    }

    public static final class Age {
        private final Integer age;

        public Integer get() {
            return age;
        }

        public Age(Integer age) {
            this.age = age;
        }
    }
}

create equals methods

new Person(new Surname("Wurst"), new Name("Hans"), new Age(1))
should equal
new Person(new Surname("Wurst"), new Name("Hans"), new Age(1))

Created project can not be imported as plugin

Seems that we have the following issues:

  • My IntelliJ only accepts jar files.
  • Currently, the classes lie in the classes directory and thus are not detected. Putting them straight in the root directory fixes the problem.
  • The description section in the plugin.xml is wrapped in a CDATA-tag, which seems to be removed after the plugin is compiled. Thus, IntelliJ can not parse the xml file.
  • In the current downloadable build (from releases), the <idea-version since-build='...'> is too high.

Currently, I have no clue why the heck the plugin.xml is modified in that way.

add optional builder creation to generation

see #2 +

public static final class Builder {
        public String name;
        public String surname;
        public String address;
        public Integer age;

        private Builder() {
        }

        public static Builder anUser() {
            return new Builder();
        }

        public Builder withName(String name) {
            this.name = name;
            return this;
        }

        public Builder withSurname(String surname) {
            this.surname = surname;
            return this;
        }

        public Builder withAddress(String address) {
            this.address = address;
            return this;
        }

        public Builder withAge(Integer age) {
            this.age = age;
            return this;
        }

        public User build() {
            User user = new User(new Name(name), new Surname(surname), new Address(address), new Age(age));
            return user;
        }
    }

note: the builder uses the primitives, not the generated value classe

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.