Skip to content

Commit 2d4fc70

Browse files
committed
address post merge conflicts, fix code style violations.
1 parent c614d44 commit 2d4fc70

File tree

17 files changed

+2012
-506
lines changed

17 files changed

+2012
-506
lines changed

fdb-java-annotations/src/main/java/com/apple/foundationdb/annotation/GenerateVisitorAnnotationHelper.java

Lines changed: 7 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
package com.apple.foundationdb.annotation;
2222

23-
import com.google.common.annotations.VisibleForTesting;
2423
import com.squareup.javapoet.AnnotationSpec;
2524
import com.squareup.javapoet.ClassName;
2625
import com.squareup.javapoet.CodeBlock;
@@ -44,21 +43,18 @@
4443
import javax.lang.model.element.Modifier;
4544
import javax.lang.model.element.PackageElement;
4645
import javax.lang.model.element.TypeElement;
47-
import javax.lang.model.type.DeclaredType;
4846
import javax.lang.model.type.TypeKind;
4947
import javax.lang.model.type.TypeMirror;
5048
import javax.lang.model.util.Types;
5149
import javax.tools.Diagnostic;
5250
import java.io.IOException;
53-
import java.util.Arrays;
5451
import java.util.List;
5552
import java.util.Locale;
5653
import java.util.Map;
5754
import java.util.Objects;
5855
import java.util.Set;
5956
import java.util.function.BiFunction;
6057
import java.util.stream.Collectors;
61-
import java.util.stream.Stream;
6258

6359
/**
6460
* A separate class to support (@link GenerateVisitorAnnotationProcessor) so that dependency on javapoet does not leak to anyone
@@ -106,8 +102,8 @@ static boolean process(final ProcessingEnvironment processingEnv, Set<? extends
106102
.getEnclosedElements()
107103
.stream()
108104
.flatMap(packageElement -> packageElement.getEnclosedElements().stream())
109-
.flatMap(element -> element.getKind() == ElementKind.CLASS && element.getModifiers().contains(Modifier.ABSTRACT) ? element.getEnclosedElements().stream() : Stream.of(element) )
110-
.filter(element -> element.getKind() == ElementKind.CLASS && !element.getModifiers().contains(Modifier.ABSTRACT))
105+
.filter(element -> element.getKind() == ElementKind.CLASS &&
106+
!element.getModifiers().contains(Modifier.ABSTRACT))
111107
.map(Element::asType)
112108
.filter(mirror -> mirror.getKind() == TypeKind.DECLARED)
113109
.filter(mirror -> typeUtils.isSubtype(mirror, rootTypeMirror))
@@ -156,19 +152,18 @@ private static void generateInterface(@Nonnull final Types typeUtils,
156152
.addModifiers(Modifier.PUBLIC)
157153
.addTypeVariable(typeVariableName);
158154

159-
final var packageName = packageElement.getQualifiedName().toString();
160155
final var jumpMapBuilder = FieldSpec.builder(ParameterizedTypeName.get(ClassName.get(Map.class),
161156
ParameterizedTypeName.get(ClassName.get(Class.class), WildcardTypeName.subtypeOf(Object.class)),
162157
ParameterizedTypeName.get(ClassName.get(BiFunction.class),
163-
ParameterizedTypeName.get(ClassName.get(packageName, interfaceName), WildcardTypeName.subtypeOf(Object.class)),
158+
ParameterizedTypeName.get(ClassName.get(packageElement.getQualifiedName().toString(), interfaceName), WildcardTypeName.subtypeOf(Object.class)),
164159
TypeName.get(rootTypeMirror),
165160
WildcardTypeName.subtypeOf(Object.class))),
166161
"jumpMap", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
167162

168163
final var initializerStrings = subClassTypeMirrors.stream()
169164
.map(typeMirror -> {
170165
final var typeElement = (TypeElement)typeUtils.asElement(typeMirror);
171-
return "Map.entry(" + getRawTypeName(typeMirror, packageName) + ".class, (visitor, element) -> visitor." + methodNameOfVisitMethod(generateVisitor, typeElement) + "((" + getWildcardTypeName(typeMirror, packageName) + ")element))";
166+
return "Map.entry(" + typeElement.getSimpleName() + ".class, (visitor, element) -> visitor." + methodNameOfVisitMethod(generateVisitor, typeElement) + "((" + typeElement.getSimpleName() + ")element))";
172167
})
173168
.collect(Collectors.joining(", \n"));
174169

@@ -177,7 +172,6 @@ private static void generateInterface(@Nonnull final Types typeUtils,
177172
.build();
178173

179174
typeBuilder.addField(jumpMapBuilder
180-
.addAnnotation(AnnotationSpec.builder(SuppressWarnings.class).addMember("value", "$S", "unchecked").build())
181175
.initializer(initializerBlock)
182176
.build());
183177

@@ -189,7 +183,7 @@ private static void generateInterface(@Nonnull final Types typeUtils,
189183
.methodBuilder(methodName)
190184
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
191185
.addAnnotation(Nonnull.class)
192-
.addParameter(ParameterSpec.builder(getWildcardTypeName(typeMirror, packageName), parameterName).addAnnotation(Nonnull.class).build())
186+
.addParameter(ParameterSpec.builder(TypeName.get(typeMirror), parameterName).addAnnotation(Nonnull.class).build())
193187
.returns(typeVariableName);
194188
typeBuilder.addMethod(specificVisitMethodBuilder.build());
195189
}
@@ -199,7 +193,7 @@ private static void generateInterface(@Nonnull final Types typeUtils,
199193
.methodBuilder(defaultMethodName)
200194
.addModifiers(Modifier.PUBLIC, Modifier.ABSTRACT)
201195
.addAnnotation(Nonnull.class)
202-
.addParameter(ParameterSpec.builder(getWildcardTypeName(rootTypeMirror, packageName), parameterName).addAnnotation(Nonnull.class).build())
196+
.addParameter(ParameterSpec.builder(TypeName.get(rootTypeMirror), parameterName).addAnnotation(Nonnull.class).build())
203197
.returns(typeVariableName);
204198
typeBuilder.addMethod(visitDefaultMethodBuilder.build());
205199

@@ -222,105 +216,6 @@ private static void generateInterface(@Nonnull final Types typeUtils,
222216
.writeTo(Objects.requireNonNull(filer));
223217
}
224218

225-
/**
226-
* Converts a type mirror to a raw TypeName without type parameters.
227-
* <p>
228-
* For generic types, this method returns the raw type without any type arguments
229-
* (e.g., {@code List<String>} becomes {@code List}). For non-generic types, the type
230-
* is returned as-is. If the type belongs to the same package as {@code currentPackage},
231-
* the package prefix is omitted from the generated type name.
232-
* <p>
233-
* This is particularly useful when generating code that needs to reference the
234-
* {@code .class} literal of a generic type, as class literals must use raw types.
235-
*
236-
* @param typeMirror the type mirror to convert
237-
* @param currentPackage the current package name, used to determine whether to omit
238-
* package prefixes for types in the same package
239-
* @return a TypeName representing the raw type (without type parameters) if the type
240-
* is generic, or the original type name if not generic
241-
*/
242-
@Nonnull
243-
private static TypeName getRawTypeName(@Nonnull TypeMirror typeMirror, @Nonnull String currentPackage) {
244-
if (typeMirror.getKind() == TypeKind.DECLARED) {
245-
final var declaredType = (DeclaredType) typeMirror;
246-
final var typeElement = (TypeElement) declaredType.asElement();
247-
final boolean isGeneric = !typeElement.getTypeParameters().isEmpty();
248-
249-
if (isGeneric) {
250-
final ClassName className = ClassName.get(typeElement);
251-
return removePackagePrefix(className, currentPackage);
252-
}
253-
}
254-
255-
// return as-is, remove the package if it is the same as the currentPackage.
256-
final TypeName typeName = TypeName.get(typeMirror);
257-
if (typeName instanceof ClassName) {
258-
return removePackagePrefix((ClassName) typeName, currentPackage);
259-
}
260-
261-
return typeName;
262-
}
263-
264-
/**
265-
* Converts a type mirror to a TypeName with wildcard type arguments for generic types.
266-
* <p>
267-
* For generic types, this method creates a parameterized type with wildcard bounds
268-
* (e.g., {@code List<String>} becomes {@code List<?>}). For non-generic types, the type
269-
* is returned as-is. If the type belongs to the same package as {@code currentPackage},
270-
* the package prefix is omitted from the generated type name.
271-
*
272-
* @param typeMirror the type mirror to convert
273-
* @param currentPackage the current package name, used to determine whether to omit
274-
* package prefixes for types in the same package
275-
* @return a TypeName representing the type with wildcard type arguments if the type
276-
* is generic, or the original type name if not generic
277-
*/
278-
@Nonnull
279-
private static TypeName getWildcardTypeName(@Nonnull final TypeMirror typeMirror, @Nonnull final String currentPackage) {
280-
if (typeMirror.getKind() == TypeKind.DECLARED) {
281-
final var declaredType = (DeclaredType) typeMirror;
282-
final var typeElement = (TypeElement) declaredType.asElement();
283-
final boolean isGeneric = !typeElement.getTypeParameters().isEmpty();
284-
285-
if (isGeneric) {
286-
ClassName rawType = ClassName.get(typeElement);
287-
rawType = removePackagePrefix(rawType, currentPackage);
288-
289-
final WildcardTypeName[] wildcards = new WildcardTypeName[typeElement.getTypeParameters().size()];
290-
Arrays.fill(wildcards, WildcardTypeName.subtypeOf(Object.class));
291-
return ParameterizedTypeName.get(rawType, wildcards);
292-
}
293-
}
294-
295-
// return as-is, remove the package if it is the same as the currentPackage.
296-
final TypeName typeName = TypeName.get(typeMirror);
297-
if (typeName instanceof ClassName) {
298-
return removePackagePrefix((ClassName) typeName, currentPackage);
299-
}
300-
301-
return typeName;
302-
}
303-
304-
/**
305-
* Removes the package prefix from a ClassName if it belongs to the same package as currentPackage.
306-
* <p>
307-
* This is useful when generating code references to types that are in the same package,
308-
* as the package prefix can be omitted for brevity.
309-
*
310-
* @param className the ClassName to potentially strip the package prefix from
311-
* @param currentPackage the current package name to compare against
312-
* @return a ClassName without the package prefix if it's in the same package,
313-
* otherwise returns the original ClassName unchanged
314-
*/
315-
@Nonnull
316-
private static ClassName removePackagePrefix(@Nonnull final ClassName className, @Nonnull final String currentPackage) {
317-
if (className.packageName().equals(currentPackage)) {
318-
return ClassName.get("", className.topLevelClassName().simpleName(),
319-
className.simpleNames().subList(1, className.simpleNames().size()).toArray(new String[0]));
320-
}
321-
return className;
322-
}
323-
324219
private static void generateImplementationWithDefaults(@Nonnull final Types typeUtils,
325220
@Nonnull final Filer filer,
326221
@Nonnull final GenerateVisitor generateVisitor,
@@ -345,7 +240,7 @@ private static void generateImplementationWithDefaults(@Nonnull final Types type
345240
.addModifiers(Modifier.PUBLIC, Modifier.DEFAULT)
346241
.addAnnotation(Nonnull.class)
347242
.addAnnotation(Override.class)
348-
.addParameter(ParameterSpec.builder(getWildcardTypeName(typeMirror, packageElement.getQualifiedName().toString()), parameterName).addAnnotation(Nonnull.class).build())
243+
.addParameter(ParameterSpec.builder(TypeName.get(typeMirror), parameterName).addAnnotation(Nonnull.class).build())
349244
.returns(typeVariableName)
350245
.addCode(CodeBlock.builder()
351246
.addStatement("return " + defaultMethodName + "(" + parameterName + ")")

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/values/Value.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.apple.foundationdb.record.query.plan.cascades.values;
2222

2323
import com.apple.foundationdb.annotation.API;
24-
import com.apple.foundationdb.annotation.GenerateVisitor;
2524
import com.apple.foundationdb.record.EvaluationContext;
2625
import com.apple.foundationdb.record.PlanHashable;
2726
import com.apple.foundationdb.record.PlanSerializable;
@@ -92,7 +91,6 @@
9291
* A scalar value type.
9392
*/
9493
@API(API.Status.EXPERIMENTAL)
95-
@GenerateVisitor
9694
public interface Value extends Correlated<Value>, TreeLike<Value>, UsesValueEquivalence<Value>, PlanHashable, Typed, Narrowable<Value>, PlanSerializable {
9795

9896
@Nonnull
@@ -311,31 +309,6 @@ default Value translateCorrelations(@Nonnull final TranslationMap translationMap
311309
}, false).orElseThrow(() -> new RecordCoreException("unable to map tree"));
312310
}
313311

314-
@Nonnull
315-
@SuppressWarnings("PMD.CompareObjectsWithEquals")
316-
default Value translateCorrelationsRecursively(@Nonnull final TranslationMap translationMap) {
317-
if (translationMap.definesOnlyIdentities()) {
318-
return this;
319-
}
320-
return replaceLeavesMaybe(value -> {
321-
if (value instanceof LeafValue) {
322-
final var leafValue = (LeafValue)value;
323-
final var correlatedTo = value.getCorrelatedTo();
324-
if (correlatedTo.isEmpty()) {
325-
return leafValue;
326-
}
327-
328-
Verify.verify(correlatedTo.size() == 1);
329-
final var sourceAlias = Iterables.getOnlyElement(correlatedTo);
330-
return translationMap.containsSourceAlias(sourceAlias)
331-
? translationMap.applyTranslationFunction(sourceAlias, leafValue)
332-
: leafValue;
333-
}
334-
Verify.verify(value.getCorrelatedTo().isEmpty());
335-
return value;
336-
}, true).orElseThrow(() -> new RecordCoreException("unable to map tree"));
337-
}
338-
339312
@Nonnull
340313
default <V extends Value> V narrow(@Nonnull Class<V> narrowedClass) {
341314
return narrowedClass.cast(this);

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/metadata/RecordLayerIndex.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,6 @@ public Map<String, String> getOptions() {
123123
return options;
124124
}
125125

126-
@Nonnull
127-
public Builder toBuilder() {
128-
return newBuilder().setName(getName())
129-
.setIndexType(getIndexType())
130-
.setTableName(getTableName())
131-
.setUnique(isUnique())
132-
.setKeyExpression(getKeyExpression())
133-
.setPredicate(getPredicate())
134-
.setOptions(getOptions());
135-
}
136-
137126
@Nonnull
138127
public static RecordLayerIndex from(@Nonnull final String tableName, @Nonnull String tableStorageName, @Nonnull final com.apple.foundationdb.record.metadata.Index index) {
139128
final var indexProto = index.toProto();

fdb-relational-core/src/main/java/com/apple/foundationdb/relational/recordlayer/query/ddl/MaterializedViewIndexGenerator.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ private MaterializedViewIndexGenerator(@Nonnull RelationalExpression relationalE
144144
}
145145

146146
@Nonnull
147-
public RecordLayerIndex.Builder generate(@Nonnull RecordLayerSchemaTemplate.Builder schemaTemplateBuilder, @Nonnull String indexName, boolean isUnique, boolean containsNullableArray) {
147+
public RecordLayerIndex.Builder generate(@Nonnull RecordLayerSchemaTemplate.Builder schemaTemplateBuilder, @Nonnull String indexName,
148+
boolean isUnique, boolean containsNullableArray, boolean generateKeyValueExpressionWithEmptyKey) {
148149
final String recordTypeName = getRecordTypeName();
149150
// Have to use the storage name here because the index generator uses it
150151
final Type.Record tableType = schemaTemplateBuilder.findTableByStorageName(recordTypeName).getType();
@@ -189,7 +190,10 @@ public RecordLayerIndex.Builder generate(@Nonnull RecordLayerSchemaTemplate.Buil
189190
}
190191
final var reordered = reorderValues(fieldValues, orderByValues);
191192
final var expression = generate(reordered, orderingFunctions);
192-
final var splitPoint = orderByValues.isEmpty() ? -1 : orderByValues.size();
193+
var splitPoint = orderByValues.size();
194+
if (orderByValues.isEmpty() && !generateKeyValueExpressionWithEmptyKey) {
195+
splitPoint = -1;
196+
}
193197
if (splitPoint != -1 && splitPoint < fieldValues.size()) {
194198
indexBuilder.setKeyExpression(KeyExpression.fromProto(NullableArrayUtils.wrapArray(keyWithValue(expression, splitPoint).toKeyExpression(), tableType, containsNullableArray)));
195199
} else {
@@ -232,7 +236,7 @@ public RecordLayerIndex.Builder generate(@Nonnull RecordLayerSchemaTemplate.Buil
232236
if (IndexTypes.PERMUTED_MIN.equals(indexType) || IndexTypes.PERMUTED_MAX.equals(indexType)) {
233237
int permutedSize = aggregateOrderIndex < 0 ? 0 : (fieldValues.size() - aggregateOrderIndex);
234238
indexBuilder.setOption(IndexOptions.PERMUTED_SIZE_OPTION, permutedSize);
235-
} else if (aggregateOrderIndex >= 0) {
239+
} else if (aggregateOrderIndex > 0) {
236240
Assert.failUnchecked(ErrorCode.UNSUPPORTED_OPERATION, "Unsupported index definition. Cannot order " + indexType + " index by aggregate value");
237241
}
238242
}

0 commit comments

Comments
 (0)