Skip to content

Commit

Permalink
Defines the AutoCodec FieldGenerator for DeferredObjectCodec.
Browse files Browse the repository at this point in the history
The new AutoCodec implementation will use this implementation.

PiperOrigin-RevId: 655359804
Change-Id: I9451eef6cb70d5bfeda77bd83f1d3bb092bc3e31
  • Loading branch information
aoeui authored and copybara-github committed Jul 24, 2024
1 parent 0803ad3 commit d5a73cd
Show file tree
Hide file tree
Showing 3 changed files with 671 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ java_library(
srcs = [
"AutoCodecProcessor.java",
"CodecGenerator.java",
"DeferredObjectCodecConstants.java",
"DeferredObjectCodecFieldGenerators.java",
"FieldGenerator.java",
"Initializers.java",
"InterningObjectCodecFieldGenerators.java",
Expand All @@ -128,6 +130,7 @@ java_library(
":type-operations",
"//src/main/java/com/google/devtools/build/lib/skyframe/serialization",
"//src/main/java/com/google/devtools/build/lib/unsafe:unsafe-provider",
"//src/main/java/com/google/devtools/build/lib/util:string",
"//third_party:auto_service",
"//third_party:auto_value",
"//third_party:guava",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2024 The Bazel Authors. 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.google.devtools.build.lib.skyframe.serialization.autocodec;

import static com.google.devtools.build.lib.util.StringUtilities.capitalize;

import com.google.devtools.build.lib.skyframe.serialization.DeferredObjectCodec;
import java.lang.invoke.MethodHandles;
import javax.lang.model.element.Name;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;

/** Common {@link DeferredObjectCodec} building constants and helper methods. */
final class DeferredObjectCodecConstants {
/** Name of constructor scoped variable holding the {@link MethodHandles.Lookup} instance. */
static final String CONSTRUCTOR_LOOKUP_NAME = "lookup";

/** Class name for the codec's {@link DeferredObjectCodec.DeferredValue} implementation. */
static final String BUILDER_TYPE_NAME = "Builder";

/** Name of an instance variable in the deserialize method storing the builder instance. */
static final String BUILDER_NAME = "builder";

static String makeGetterName(VariableElement parameter) {
String prefix = parameter.asType().getKind() == TypeKind.BOOLEAN ? "is" : "get";
String suffix = capitalize(parameter.getSimpleName().toString());
return prefix + suffix;
}

static String makeSetterName(Name name) {
return "set" + capitalize(name.toString());
}

private DeferredObjectCodecConstants() {}
}
Loading

0 comments on commit d5a73cd

Please sign in to comment.