Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidates the pico spi with the api into the new replacement "pico" module #5400

Merged
merged 7 commits into from
Nov 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@
<!-- Pico -->
<dependency>
<groupId>io.helidon.pico</groupId>
<artifactId>helidon-pico-api</artifactId>
<artifactId>helidon-pico</artifactId>
<version>${helidon.version}</version>
</dependency>
<dependency>
Expand Down
33 changes: 0 additions & 33 deletions pico/api/pom.xml

This file was deleted.

26 changes: 0 additions & 26 deletions pico/api/src/main/java/io/helidon/pico/api/package-info.java

This file was deleted.

2 changes: 1 addition & 1 deletion pico/builder/builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

This module can either be used compile-time only or at runtime as well depending upon your usage.

See the [main](../README.md) document for details.
See the [main](../README.md) for details.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.helidon.pico.builder.spi;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand All @@ -38,7 +39,7 @@
*/
@Deprecated
public class RequiredAttributeVisitor implements AttributeVisitor {
private List<String> errors;
private final List<String> errors = new ArrayList<>();

/**
* Default constructor.
Expand All @@ -64,20 +65,17 @@ public void visit(String attrName,
return;
}

if (Objects.isNull(errors)) {
errors = new java.util.LinkedList<>();
}
errors.add("'" + attrName + "' is a required attribute and should not be null");
}

/**
* Performs the validation. Any errors will result in a thrown error.
*
* @throws java.lang.AssertionError when any attributes are in violation with the validation policy
* @throws java.lang.IllegalStateException when any attributes are in violation with the validation policy
*/
public void validate() {
if (Objects.nonNull(errors) && !errors.isEmpty()) {
throw new AssertionError(String.join(", ", errors));
if (!errors.isEmpty()) {
throw new IllegalStateException(String.join(", ", errors));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

package io.helidon.pico.builder.processor.spi;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

Expand All @@ -48,13 +47,20 @@ public class DefaultTypeInfo implements TypeInfo {
protected DefaultTypeInfo(Builder b) {
this.typeName = b.typeName;
this.typeKind = b.typeKind;
this.annotations = Objects.isNull(b.annotations)
? Collections.emptyList() : Collections.unmodifiableList(new LinkedList<>(b.annotations));
this.elementInfo = Objects.isNull(b.elementInfo)
? Collections.emptyList() : Collections.unmodifiableList(new LinkedList<>(b.elementInfo));
this.annotations = Collections.unmodifiableList(new LinkedList<>(b.annotations));
this.elementInfo = Collections.unmodifiableList(new LinkedList<>(b.elementInfo));
this.superTypeInfo = b.superTypeInfo;
}

/**
* Creates a new builder for this type.
*
* @return the fluent builder
*/
public static Builder builder() {
return new Builder();
}

@Override
public TypeName typeName() {
return typeName;
Expand Down Expand Up @@ -96,26 +102,16 @@ protected String toStringInner() {
+ ", superTypeInfo=" + superTypeInfo();
}


/**
* Creates a new builder for this type.
*
* @return the fluent builder
*/
public static Builder builder() {
return new Builder();
}


/**
* Builder for this type.
*/
public static class Builder {
public static class Builder implements io.helidon.common.Builder<Builder, DefaultTypeInfo> {
private final List<AnnotationAndValue> annotations = new ArrayList<>();
private final List<TypedElementName> elementInfo = new ArrayList<>();

private TypeName typeName;
private String typeKind;
private List<AnnotationAndValue> annotations;
private List<TypedElementName> elementInfo;
private Map<TypedElementName, String> defaultValueMap;

private TypeInfo superTypeInfo;

/**
Expand All @@ -124,6 +120,16 @@ public static class Builder {
protected Builder() {
}

/**
* Builds the instance.
*
* @return the built instance
*/
@Override
public DefaultTypeInfo build() {
return new DefaultTypeInfo(this);
}

/**
* Sets the typeName to val.
*
Expand Down Expand Up @@ -153,7 +159,9 @@ public Builder typeKind(String val) {
* @return this fluent builder
*/
public Builder annotations(Collection<AnnotationAndValue> val) {
this.annotations = new LinkedList<>(Objects.requireNonNull(val));
Objects.requireNonNull(val);
this.annotations.clear();
this.annotations.addAll(val);
return this;
}

Expand All @@ -164,9 +172,7 @@ public Builder annotations(Collection<AnnotationAndValue> val) {
* @return this fluent builder
*/
public Builder addAnnotation(AnnotationAndValue val) {
if (Objects.isNull(annotations)) {
annotations = new LinkedList<>();
}
Objects.requireNonNull(val);
annotations.add(Objects.requireNonNull(val));
return this;
}
Expand All @@ -178,7 +184,9 @@ public Builder addAnnotation(AnnotationAndValue val) {
* @return this fluent builder
*/
public Builder elementInfo(Collection<TypedElementName> val) {
this.elementInfo = new LinkedList<>(Objects.requireNonNull(val));
Objects.requireNonNull(val);
this.elementInfo.clear();
this.elementInfo.addAll(val);
return this;
}

Expand All @@ -189,58 +197,22 @@ public Builder elementInfo(Collection<TypedElementName> val) {
* @return this fluent builder
*/
public Builder addElementInfo(TypedElementName val) {
if (Objects.isNull(elementInfo)) {
elementInfo = new LinkedList<>();
}
Objects.requireNonNull(val);
elementInfo.add(Objects.requireNonNull(val));
return this;
}

/**
* Sets the defaultValueMap to val.
*
* @param val the value
* @return this fluent builder
*/
public Builder defaultValueMap(Map<TypedElementName, String> val) {
this.defaultValueMap = new LinkedHashMap<>(Objects.requireNonNull(val));
return this;
}

/**
* Adds a singular defaultValue val.
*
* @param key the key
* @param val the value
* @return this fluent builder
*/
public Builder addDefaultValue(TypedElementName key, String val) {
if (Objects.isNull(defaultValueMap)) {
defaultValueMap = new LinkedHashMap<>();
}
defaultValueMap.put(key, val);
return this;
}

/**
* Sets the superTypeInfo to val.
*
* @param val the value
* @return this fluent builder
*/
public Builder superTypeInfo(TypeInfo val) {
Objects.requireNonNull(val);
this.superTypeInfo = val;
return this;
}

/**
* Builds the instance.
*
* @return the built instance
*/
public DefaultTypeInfo build() {
return new DefaultTypeInfo(this);
}
}

}
Loading