Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2025 The Dagger Authors.
*
* 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 dagger.internal.codegen.xprocessing;
import static androidx.room.compiler.codegen.compat.XConverters.toJavaPoet;
import static androidx.room.compiler.codegen.compat.XConverters.toKotlinPoet;
import static androidx.room.compiler.codegen.compat.XConverters.toXPoet;
import static com.google.common.base.Preconditions.checkState;
import androidx.room.compiler.codegen.VisibilityModifier;
import androidx.room.compiler.codegen.XAnnotationSpec;
import androidx.room.compiler.codegen.XClassName;
import androidx.room.compiler.codegen.XCodeBlock;
import androidx.room.compiler.codegen.XPropertySpec;
import androidx.room.compiler.codegen.XTypeName;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.squareup.javapoet.AnnotationSpec;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.TypeName;
import com.squareup.kotlinpoet.KModifier;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.lang.model.element.Modifier;
// TODO(bcorso): Consider moving these methods into XProcessing library.
/** A utility class for {@link XPropertySpec} helper methods. */
public final class XPropertySpecs {
/**
* Creates a {@code XPropertySpec} with the given {@code name}, {@code typeName}, and {@code
* modifiers} and adds the given type-use nullability annotations to the type and the non-type-use
* annotations to the parameter.
*/
public static XPropertySpec of(
String name, XTypeName typeName, Nullability nullability, Modifier... modifiers) {
return builder(name, typeName, nullability, modifiers).build();
}
/**
* Creates a {@code XPropertySpec} with the given {@code name}, {@code typeName}, and {@code
* modifiers}.
*/
public static XPropertySpec of(String name, XTypeName typeName, Modifier... modifiers) {
return builder(name, typeName, modifiers).build();
}
/**
* Creates a builder with the given {@code name}, {@code typeName}, and {@code modifiers} and adds
* the given type-use nullability annotations to the type and the non-type-use annotations to the
* parameter.
*/
public static Builder builder(
String name, XTypeName typeName, Nullability nullability, Modifier... modifiers) {
return Builder.create(name, XTypeNames.withTypeNullability(typeName, nullability), modifiers)
.addAnnotationNames(nullability.nonTypeUseNullableAnnotations());
}
/** Creates a builder with the given {@code name}, {@code typeName}, and {@code modifiers}. */
public static Builder builder(String name, XTypeName typeName, Modifier... modifiers) {
return Builder.create(name, typeName, modifiers);
}
/** Creates a builder with the given {@code name}, {@code typeName}, and {@code modifiers}. */
public static Builder builder(TypeName typeName, String name, Modifier... modifiers) {
return Builder.create(name, typeName, modifiers);
}
/** Builds an {@link XPropertySpec} in a way that is more similar to the JavaPoet API. */
public static class Builder {
private static Builder create(String name, Object typeName, Modifier... modifiers) {
Builder builder = new Builder(name, typeName);
builder.addModifiers(modifiers);
return builder;
}
private final String name;
private final Object typeName;
private boolean isStatic = false;
private boolean isMutable = true; // The default in JavaPoet is true, i.e. non-final.
private VisibilityModifier visibility = null;
private XCodeBlock initializer = null;
private final List javadocs = new ArrayList<>();
private final List