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

chore: various non-functional refactors #1066

Merged
merged 1 commit into from
Aug 26, 2024
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
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/BooleanHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface BooleanHook extends Hook<Boolean> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inheritDoc isn't valid for classes.


Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/DoubleHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface DoubleHook extends Hook<Double> {

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/dev/openfeature/sdk/ImmutableContext.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dev.openfeature.sdk;

import lombok.ToString;
import lombok.experimental.Delegate;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
import lombok.ToString;
import lombok.experimental.Delegate;

/**
* The EvaluationContext is a container for arbitrary contextual data
Expand All @@ -16,8 +17,8 @@
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public final class ImmutableContext implements EvaluationContext {

@Delegate
private final Structure structure;
@Delegate(excludes = DelegateExclusions.class)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge was coming both from this delegation and the superclass, which causes some odd compiler warnings. It's just coming via inheritance now.

private final ImmutableStructure structure;

/**
* Create an immutable context with an empty targeting_key and attributes provided.
Expand Down Expand Up @@ -84,4 +85,15 @@ public EvaluationContext merge(EvaluationContext overridingContext) {
return new ImmutableContext(
this.merge(ImmutableStructure::new, this.asMap(), overridingContext.asMap()));
}

@SuppressWarnings("all")
private static class DelegateExclusions {
@ExcludeFromGeneratedCoverageReport
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
Map<String, Value> base,
Map<String, Value> overriding) {

return null;
}
}
}
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/IntegerHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface IntegerHook extends Hook<Integer> {

Expand Down
26 changes: 19 additions & 7 deletions src/main/java/dev/openfeature/sdk/MutableContext.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package dev.openfeature.sdk;

import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Delegate;

import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import dev.openfeature.sdk.internal.ExcludeFromGeneratedCoverageReport;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.Delegate;

/**
* The EvaluationContext is a container for arbitrary contextual data
Expand All @@ -20,7 +21,8 @@
@SuppressWarnings("PMD.BeanMembersShouldSerialize")
public class MutableContext implements EvaluationContext {

@Delegate(excludes = HideDelegateAddMethods.class) private final MutableStructure structure;
@Delegate(excludes = DelegateExclusions.class)
private final MutableStructure structure;

public MutableContext() {
this(new HashMap<>());
Expand Down Expand Up @@ -124,11 +126,21 @@ public EvaluationContext merge(EvaluationContext overridingContext) {
/**
* Hidden class to tell Lombok not to copy these methods over via delegation.
*/
private static class HideDelegateAddMethods {
@SuppressWarnings("all")
private static class DelegateExclusions {

@ExcludeFromGeneratedCoverageReport
public <T extends Structure> Map<String, Value> merge(Function<Map<String, Value>, Structure> newStructure,
Map<String, Value> base,
Map<String, Value> overriding) {

return null;
}

public MutableStructure add(String ignoredKey, Boolean ignoredValue) {
return null;
}

public MutableStructure add(String ignoredKey, Double ignoredValue) {
return null;
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/dev/openfeature/sdk/OpenFeatureClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,17 @@
import lombok.extern.slf4j.Slf4j;

/**
* {@inheritDoc}
* OpenFeature Client implementation.
* You should not instantiate this or reference this class.
* Use the dev.openfeature.sdk.Client interface instead.
* @see Client
*
* @deprecated // TODO: eventually we will make this non-public. See issue #872
*/
@Slf4j
@SuppressWarnings({ "PMD.DataflowAnomalyAnalysis", "PMD.BeanMembersShouldSerialize",
"PMD.UnusedLocalVariable", "unchecked", "rawtypes" })
@Deprecated() // TODO: eventually we will make this non-public. See issue #872
public class OpenFeatureClient implements Client {

private final OpenFeatureAPI openfeatureApi;
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/dev/openfeature/sdk/StringHook.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package dev.openfeature.sdk;

/**
* {@inheritDoc}
* An extension point which can run around flag resolution. They are intended to be used as a way to add custom logic
* to the lifecycle of flag evaluation.
*
* @see Hook
*/
public interface StringHook extends Hook<String> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package dev.openfeature.sdk.internal;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

/**
* JaCoCo ignores coverage of methods annotated with any annotation with "generated" in the name.
*/
Comment on lines +8 to +10
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😎

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ExcludeFromGeneratedCoverageReport {
}
Loading