Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Introduce Immutables Meta-Annotations #5494

Merged
merged 9 commits into from
Jun 8, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.palantir.atlasdb.persistent.api;

import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import java.util.List;
import java.util.Map;
Expand All @@ -31,7 +32,7 @@ public interface PersistentStore extends AutoCloseable {
* PostgreSQL table or RocksdDb column family. Handle is linked with one underlying store space.
*/
@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
interface Handle {
UUID id();

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

package com.palantir.atlasdb.transaction.api;

import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
/**
* A GuardedValue represents a value with a limited validity window.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package com.palantir.atlasdb.transaction.api;

import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.LockDescriptor;
import java.util.Map;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
public abstract class RowLockDescriptorMapping {
abstract Map<LockDescriptor, RowReference> mapping();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package com.palantir.atlasdb.transaction.api;

import com.palantir.atlasdb.keyvalue.api.TableReference;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
public interface RowReference {
TableReference tableRef();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.palantir.atlasdb.autobatch.CoalescingRequestFunction;
import com.palantir.atlasdb.autobatch.DisruptorAutobatcher;
import com.palantir.atlasdb.persistent.api.PersistentStore;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.common.streams.KeyedStream;
import com.palantir.logsafe.exceptions.SafeIllegalArgumentException;
import com.palantir.tritium.metrics.registry.MetricName;
Expand Down Expand Up @@ -190,7 +191,7 @@ private Map.Entry<ByteString, ByteString> serializeEntry(Map.Entry<K, V> entry)
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
interface CacheDescriptor {
AtomicInteger currentSize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(get = {"get*", "is*", "has*"})
@TableMetadataStyle
public abstract class TableMetadata implements Persistable {

@Value.Default
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.atlasdb.table.description;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.immutables.value.Value;

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(get = {"get*", "is*", "has*"})
public @interface TableMetadataStyle {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.common.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.immutables.value.Value;

public interface ImmutablesStyles {
@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@interface PackageVisibleImmutablesStyle {}

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(stagedBuilder = true)
@interface StagedBuilderStyle {}

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(stagedBuilder = false) // Intentional: used for e.g. inner classes of staged builder public classes.
@SuppressWarnings("RedundantModifier") // Unexpected bug in baseline check?
@interface NoStagedBuilderStyle {}

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(allParameters = true)
@interface AllParametersStyle {}

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(attributeBuilderDetection = true)
@interface AttributeBuilderDetectionStyle {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import java.time.Duration;
import java.util.concurrent.locks.LockSupport;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
public abstract class NanoTime implements Comparable<NanoTime> {
@JsonValue
abstract long time();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@
import com.palantir.atlasdb.util.MetricsManagers;
import com.palantir.atlasdb.versions.AtlasDbVersion;
import com.palantir.common.annotation.Output;
import com.palantir.common.annotations.ImmutablesStyles.NoStagedBuilderStyle;
import com.palantir.common.annotations.ImmutablesStyles.StagedBuilderStyle;
import com.palantir.common.concurrent.PTExecutors;
import com.palantir.common.time.Clock;
import com.palantir.conjure.java.api.config.service.ServicesConfigBlock;
Expand Down Expand Up @@ -210,7 +212,7 @@
import org.slf4j.LoggerFactory;

@Value.Immutable
@Value.Style(stagedBuilder = true)
@StagedBuilderStyle
public abstract class TransactionManagers {
private static final int LOGGING_INTERVAL = 60;
private static final Logger log = LoggerFactory.getLogger(TransactionManagers.class);
Expand Down Expand Up @@ -1500,7 +1502,7 @@ private static MultiTableSweepQueueWriter uninitializedTargetedSweeper(
}

@Value.Immutable
@Value.Style(stagedBuilder = false)
@NoStagedBuilderStyle
public interface LockAndTimestampServices {
LockService lock();

Expand Down
5 changes: 5 additions & 0 deletions changelog/@unreleased/pr-5494.v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type: improvement
improvement:
description: Immutables style annotations now have source retention.
links:
- https://github.com/palantir/atlasdb/pull/5494
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package com.palantir.paxos;

import com.google.common.net.HostAndPort;
import com.palantir.common.annotations.ImmutablesStyles.AllParametersStyle;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(allParameters = true)
@AllParametersStyle
public interface LeaderPingerContext<T> {
T pinger();

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

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import java.util.UUID;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
public abstract class LeadershipId {
@JsonValue
@Value.Parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.watch.LockWatchStateUpdate;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonSerialize(as = ImmutableStartTransactionWithWatchesResponse.class)
@JsonDeserialize(as = ImmutableStartTransactionWithWatchesResponse.class)
public interface StartTransactionWithWatchesResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Range;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.AtlasLockDescriptorRanges;
import com.palantir.lock.LockDescriptor;
import org.immutables.value.Value;
Expand Down Expand Up @@ -78,7 +79,7 @@ public interface Visitor<T> {
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonDeserialize(as = ImmutableEntireTable.class)
@JsonSerialize(as = ImmutableEntireTable.class)
@JsonTypeName(EntireTable.TYPE)
Expand All @@ -95,7 +96,7 @@ public <T> T accept(Visitor<T> visitor) {
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonDeserialize(as = ImmutableRowPrefix.class)
@JsonSerialize(as = ImmutableRowPrefix.class)
@JsonTypeName(RowPrefix.TYPE)
Expand All @@ -115,7 +116,7 @@ public <T> T accept(Visitor<T> visitor) {
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonDeserialize(as = ImmutableRowRange.class)
@JsonSerialize(as = ImmutableRowRange.class)
@JsonTypeName(RowRange.TYPE)
Expand All @@ -138,7 +139,7 @@ public <T> T accept(Visitor<T> visitor) {
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonDeserialize(as = ImmutableExactRow.class)
@JsonSerialize(as = ImmutableExactRow.class)
@JsonTypeName(ExactRow.TYPE)
Expand All @@ -158,7 +159,7 @@ public <T> T accept(Visitor<T> visitor) {
}

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonDeserialize(as = ImmutableExactCell.class)
@JsonSerialize(as = ImmutableExactCell.class)
@JsonTypeName(ExactCell.TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.errorprone.annotations.DoNotMock;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.LockDescriptor;
import com.palantir.lock.watch.LockWatchReferences.LockWatchReference;
import java.util.List;
Expand Down Expand Up @@ -63,7 +64,7 @@ static Snapshot snapshot(
* last known version.
*/
@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonSerialize(as = ImmutableSuccess.class)
@JsonDeserialize(as = ImmutableSuccess.class)
@JsonTypeName(Success.TYPE)
Expand All @@ -87,7 +88,7 @@ default <T> T accept(Visitor<T> visitor) {
* missed, but contains all of the current lock watch information as the state of the world moving forward.
*/
@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonSerialize(as = ImmutableSnapshot.class)
@JsonDeserialize(as = ImmutableSnapshot.class)
@JsonTypeName(Snapshot.TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.palantir.common.annotations.ImmutablesStyles.PackageVisibleImmutablesStyle;
import com.palantir.lock.v2.LockResponse;
import java.util.Optional;
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@PackageVisibleImmutablesStyle
@JsonSerialize(as = ImmutableTimestampedLockResponse.class)
@JsonDeserialize(as = ImmutableTimestampedLockResponse.class)
public interface TimestampedLockResponse {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.atlasdb.timelock.paxos;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.immutables.value.Value;

@Target({ElementType.PACKAGE, ElementType.TYPE})
@Retention(RetentionPolicy.SOURCE)
@Value.Style(typeInnerBuilder = "DoNotMatch")
public @interface DoNotMatchInnerBuilderStyle {}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.immutables.value.Value;

@Value.Immutable
@Value.Style(typeInnerBuilder = "DoNotMatch")
@DoNotMatchInnerBuilderStyle
public interface NetworkClientFactories {
Factory<PaxosAcceptorNetworkClient> acceptor();

Expand Down
Loading