Skip to content

Commit

Permalink
chore: code clean-up
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-grgt committed Mar 20, 2024
1 parent 140f312 commit 8b832af
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 61 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public class Car {
this.price = price;
}

// getters toString and hashcode left out for brevity
}
```

Expand Down Expand Up @@ -132,15 +131,15 @@ Can be used as:

```java
Cup<BigDecimal, String> string = new CupBuilder<BigDecimal, String>().topping("cream")
.contents(BigDecimal.ZERO)
.build();
.contents(BigDecimal.ZERO)
.build();
```

or alternatively:

```java
GenericsAreBuildableBuilder.of(BigDecimal.class, String.class)
.topping("cream")
.contents(BigDecimal.ZERO)
.build();
.topping("cream")
.contents(BigDecimal.ZERO)
.build();
```
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>bob-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.squareup</groupId>
<artifactId>javapoet</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/jonasg/bob/Formatter.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.jonasg.bob;

public class Formatter {
public final class Formatter {

public static String format(String source, Object ... args) {
return String.format(source.replaceAll("\\$\\w+", "%s"), args);
Expand Down
18 changes: 0 additions & 18 deletions src/main/java/io/jonasg/bob/TypeSpecFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -200,20 +200,6 @@ private List<TypeName> simpleClassNames(List<SimpleTypeDefinition> definitions)
return typeNames;
}

private TypeName classNameWithoutGenerics(TypeDefinition definition) {
return ClassName.get(definition.packageName(), definition.fullTypeName());
}

private boolean defaultConstructorPresent() {
if (typeDefinition.constructors().isEmpty())
return true;
else
for (ConstructorDefinition constructor : typeDefinition.constructors())
if (constructor.parameters().isEmpty())
return true;
return false;
}

private String fieldName(String name) {
if (buildable.prefix().isEmpty()) {
return name;
Expand All @@ -225,10 +211,6 @@ private boolean notExcluded(ParameterDefinition field) {
return !Arrays.asList(buildable.excludes()).contains(field.name());
}

private boolean notWithinTheSamePackage() {
return !typeDefinition.packageName().equals(buildable.packageName());
}

private MethodSpec constructor() {
return MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
Expand Down
12 changes: 4 additions & 8 deletions src/main/java/io/jonasg/bob/definitions/FieldDefinition.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package io.jonasg.bob.definitions;

import java.util.Set;

import javax.lang.model.element.Modifier;
import javax.lang.model.type.TypeMirror;

public class FieldDefinition {

private final String name;
private final Set<Modifier> modifiers;
private final TypeMirror type;

public FieldDefinition(String name, Set<Modifier> modifiers, TypeMirror type) {
private final TypeMirror type;

public FieldDefinition(String name, TypeMirror type) {
this.name = name;
this.modifiers = modifiers;
this.type = type;
this.type = type;
}

public String name() {
Expand Down
26 changes: 4 additions & 22 deletions src/main/java/io/jonasg/bob/definitions/ParameterDefinition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.jonasg.bob.definitions;


import java.util.Objects;

import javax.lang.model.type.TypeMirror;

public class ParameterDefinition {
Expand All @@ -22,34 +24,14 @@ public TypeMirror type() {
return type;
}

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

public static class Builder {

private String name;

private TypeMirror type;

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

public ParameterDefinition build() {
return new ParameterDefinition(this.type, this.name);
}
}

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

ParameterDefinition that = (ParameterDefinition) o;

return name != null ? name.equals(that.name) : that.name == null;
return Objects.equals(name, that.name);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ private static String join(String[] aArr, String sSep) {
private List<FieldDefinition> fields(List<VariableElement> fields) {
List<FieldDefinition> definitions = new ArrayList<>();
for (VariableElement field : fields)
definitions.add(new FieldDefinition(field.getSimpleName().toString(), field.getModifiers(), field.asType()));
definitions.add(new FieldDefinition(field.getSimpleName().toString(), field.asType()));
return definitions;
}

Expand Down

0 comments on commit 8b832af

Please sign in to comment.