本文整理匯總了Java中com.squareup.javapoet.TypeSpec.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeSpec.Builder方法的具體用法?Java TypeSpec.Builder怎麽用?Java TypeSpec.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.javapoet.TypeSpec
的用法示例。
在下文中一共展示了TypeSpec.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateHashCode
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
private static void generateHashCode(TypeSpec.Builder typeBuilder, Collection<FieldData> fields,
Collection<FieldData> superFields, boolean hasSuperClass){
if(fields.isEmpty()){
return;
}
MethodSpec.Builder hashBuilder = MethodSpec.methodBuilder("hashCode")
.returns(TypeName.INT)
.addModifiers(Modifier.PUBLIC)
.addAnnotation(Override.class);
if(hasSuperClass && !superFields.isEmpty()){
hashBuilder.addStatement("int result = super.hashCode()");
}else{
hashBuilder.addStatement("int result = 0");
}
for(FieldData fd : fields){
addStatementForHashcode(hashBuilder, fd);
}
hashBuilder.addStatement("return result");
sTemp_defined = false;
typeBuilder.addMethod(hashBuilder.build());
}
示例2: addGetParcelObject
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
/**
* getParcelObject method
*/
private void addGetParcelObject(TypeSpec.Builder classBuilder) {
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("getParcelerObject")
.addModifiers(Modifier.PRIVATE)
.returns(Object.class)
.addParameter(String.class, "pClassName")
.addParameter(ClassName.get("android.os", "Parcel"), "data")
.beginControlFlow("try")
.addStatement("$T p = null", ClassName.get("android.os", "Parcelable"))
.addStatement("$T creator = (Parcelable.Creator)Class.forName(pClassName+\"$$$$Parcelable\").getField(\"CREATOR\").get(null)", ClassName.get("android.os", "Parcelable.Creator"))
.addStatement("Object pWrapper = creator.createFromParcel(data)")
.addStatement("return pWrapper.getClass().getMethod(\"getParcel\", (Class[])null).invoke(pWrapper)")
.endControlFlow()
.beginControlFlow("catch (Exception ignored)")
.addStatement("return null")
.endControlFlow();
classBuilder.addMethod(methodBuilder.build());
}
示例3: poetSpec
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
@Override
public TypeSpec poetSpec() {
TypeSpec.Builder builder =
PoetUtils.createClassBuilder(builderClassName)
.addModifiers(Modifier.ABSTRACT)
.addAnnotation(SdkInternalApi.class)
.addTypeVariable(PoetUtils.createBoundedTypeVariableName("B", builderInterfaceName, "B", "C"))
.addTypeVariable(TypeVariableName.get("C"))
.superclass(PoetUtils.createParameterizedTypeName(DefaultClientBuilder.class, "B", "C"))
.addJavadoc("Internal base class for {@link $T} and {@link $T}.",
ClassName.get(basePackage, model.getMetadata().getSyncBuilder()),
ClassName.get(basePackage, model.getMetadata().getAsyncBuilder()));
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
ClassName advancedConfiguration = ClassName.get(basePackage,
model.getCustomizationConfig().getServiceSpecificClientConfigClass());
builder.addField(FieldSpec.builder(advancedConfiguration, "advancedConfiguration")
.addModifiers(Modifier.PRIVATE)
.build());
}
builder.addMethod(serviceEndpointPrefixMethod());
builder.addMethod(serviceDefaultsMethod());
builder.addMethod(defaultSignerProviderMethod());
if (model.getCustomizationConfig().getServiceSpecificClientConfigClass() != null) {
builder.addMethod(setAdvancedConfigurationMethod())
.addMethod(getAdvancedConfigurationMethod())
.addMethod(beanStyleSetAdvancedConfigurationMethod());
}
if (model.getCustomizationConfig().getServiceSpecificHttpConfig() != null) {
builder.addMethod(serviceSpecificHttpConfigMethod());
}
return builder.build();
}
示例4: buildProxyClass
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
public JavaFile.Builder buildProxyClass() {
ClassName proxyClassName = getProxyClassName();
TypeSpec.Builder proxyClassBuilder = TypeSpec
.classBuilder(proxyClassName.simpleName())
.addModifiers(Modifier.PUBLIC)
.addSuperinterface(TypeName.get(getRemoterInterfaceElement().asType()));
for (TypeParameterElement typeParameterElement : ((TypeElement) getRemoterInterfaceElement()).getTypeParameters()) {
proxyClassBuilder.addTypeVariable(TypeVariableName.get(typeParameterElement.toString()));
}
//constructor
proxyClassBuilder.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addJavadoc("Initialize this {@link " + getProxyClassName().simpleName() + "} with the given {@link IBinder}\n\n")
.addJavadoc("@param binder An {@link IBinder} that exposes a remote {@link " + getRemoterInterfaceClassName() + "}\n")
.addParameter(ClassName.get("android.os", "IBinder"), "binder")
.addStatement("this.mRemote = binder").build());
getBindingManager().getFieldBuilder(getRemoterInterfaceElement()).addProxyFields(proxyClassBuilder);
getBindingManager().getMethoddBuilder(getRemoterInterfaceElement()).addProxyMethods(proxyClassBuilder);
proxyClassBuilder.addJavadoc("Wraps a remote {@link IBinder} that implements {@link " + getRemoterInterfaceClassName() + "} interface\n");
proxyClassBuilder.addJavadoc("<p>\n");
proxyClassBuilder.addJavadoc("Autogenerated by <a href=\"https://bit.ly/Remoter\">Remoter</a>\n");
proxyClassBuilder.addJavadoc("@see " + getStubClassName().simpleName() + "\n");
return JavaFile.builder(proxyClassName.packageName(), proxyClassBuilder.build());
}
示例5: createBuilder
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
private TypeSpec.Builder createBuilder(final TypeElement model) {
ClassName factoryClassName = ClassName.get(AutoAdapterProcessor.LIBRARY_PACKAGE, "ViewHolderFactory");
ParameterizedTypeName factoryTypeName = ParameterizedTypeName.get(factoryClassName,
ParameterizedTypeName.get(model.asType()));
return TypeSpec.classBuilder(viewHolderFactoryClassName).addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.addSuperinterface(factoryTypeName);
}
示例6: createNavigator
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
private void createNavigator(Set<ActivityIntentModel> activityModels) {
TypeSpec.Builder navigatorBuilder = TypeSpec.classBuilder(navigatorClassName)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL);
for (ActivityIntentModel model : activityModels) {
createActivityIntent(model);
/**
* public static MainActivityIntent toMainActivity(Context context){
* MainActivityIntent intent = new MainActivityIntent(context, "com.com.MainActivity");
* return intent;
* }
*/
ClassName returnType = ClassName.get(model.getPackageName(), model.getIntentClzName());
MethodSpec.Builder methodSpecBuilder = MethodSpec
.methodBuilder(METHOD_PREFIX + model.getClzName());
methodSpecBuilder.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(classContext, "context")
.returns(ClassName.get(model.getPackageName(), model.getIntentClzName()))
.addStatement("$T intent = new $T($L,$S)", returnType, returnType, "context", model.getQualifiedName())
.addStatement("return intent");
navigatorBuilder.addMethod(methodSpecBuilder.build());
}
addPreGoListener(navigatorBuilder);
try {
JavaFile.builder(navigatorPackageName, navigatorBuilder.build()).build().writeTo(filer);
} catch (IOException e) {
e.printStackTrace();
}
}
示例7: addResourceField
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
private static void addResourceField(TypeSpec.Builder resourceType, VariableDeclarator variable,
ClassName annotation) {
String fieldName = variable.getId().getName();
String fieldValue = variable.getInit().toString();
FieldSpec.Builder fieldSpecBuilder = FieldSpec.builder(int.class, fieldName)
.addModifiers(PUBLIC, STATIC, FINAL)
.initializer(fieldValue);
if (annotation != null) {
fieldSpecBuilder.addAnnotation(annotation);
}
resourceType.addField(fieldSpecBuilder.build());
}
示例8: build
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
@Override
public JavaFile build() {
TypeSpec.Builder result =
TypeSpec.classBuilder(getClassName()).addModifiers(Modifier.PUBLIC)
.addSuperinterface(
ParameterizedTypeName.get(VIEW_DELEGATE, viewClass,
getPresenterFactoryTypeName()));
decorator.build(result);
return JavaFile.builder(getPackageName(), result.build())
.addFileComment("Generated class from EasyMVP. Do not modify!").build();
}
示例9: copyAccessModifiers
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
static void copyAccessModifiers( @Nonnull final TypeElement element, @Nonnull final TypeSpec.Builder builder )
{
if ( element.getModifiers().contains( Modifier.PUBLIC ) )
{
builder.addModifiers( Modifier.PUBLIC );
}
}
示例10: addMethods
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
protected void addMethods(TypeSpec.Builder result) {
result
.addMethod(getInitializeMethod())
.addMethod(getInitializeMethodWithFactory())
.addMethod(getAttachViewMethod())
.addMethod(getDetachViewMethod())
.addMethod(getLoaderManagerMethod(getLoaderMethodSignature()))
;
}
示例11: buildStubClass
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
public JavaFile.Builder buildStubClass() {
ClassName stubClassName = getStubClassName();
TypeSpec.Builder stubClassBuilder = TypeSpec
.classBuilder(stubClassName.simpleName())
.addModifiers(Modifier.PUBLIC)
.superclass(TypeName.get(getBindingManager().getType("android.os.Binder")));
for (TypeParameterElement typeParameterElement : ((TypeElement) getRemoterInterfaceElement()).getTypeParameters()) {
stubClassBuilder.addTypeVariable(TypeVariableName.get(typeParameterElement.toString()));
}
//constructor
stubClassBuilder.addMethod(MethodSpec.constructorBuilder()
.addModifiers(Modifier.PUBLIC)
.addJavadoc("Initialize this {@link " + getStubClassName().simpleName() + "} with the given {@link " + getRemoterInterfaceClassName() + "} implementation \n\n")
.addJavadoc("@param serviceImpl An implementation of {@link " + getRemoterInterfaceClassName() + "}\n")
.addParameter(TypeName.get(getRemoterInterfaceElement().asType()), "serviceImpl")
.addStatement("this.serviceImpl = serviceImpl")
.beginControlFlow("this.attachInterface(new $T()", ClassName.get("android.os", "IInterface"))
.beginControlFlow("public $T asBinder()", ClassName.get("android.os", "IBinder"))
.addStatement("return " + stubClassName.simpleName() + ".this")
.endControlFlow()
.endControlFlow()
.addStatement(", DESCRIPTOR)")
.build());
getBindingManager().getFieldBuilder(getRemoterInterfaceElement()).addStubFields(stubClassBuilder);
getBindingManager().getMethoddBuilder(getRemoterInterfaceElement()).addStubMethods(stubClassBuilder);
stubClassBuilder.addJavadoc("Wraps a {@link " + getRemoterInterfaceClassName() + "} implementation and expose it as a remote {@link IBinder}\n");
stubClassBuilder.addJavadoc("<p>\n");
stubClassBuilder.addJavadoc("Autogenerated by <a href=\"https://bit.ly/Remoter\">Remoter</a>\n");
stubClassBuilder.addJavadoc("@see " + getProxyClassName().simpleName() + "\n");
return JavaFile.builder(stubClassName.packageName(), stubClassBuilder.build());
}
示例12: build
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
@Override
public JavaFile build() {
TypeSpec.Builder result =
TypeSpec.classBuilder(getClassName()).addModifiers(Modifier.PUBLIC)
.addTypeVariable(TypeVariableName.get("P", Presenter.class))
.superclass(ParameterizedTypeName.get(AndroidLoaderUtils.getLoader(supportLibrary),
TypeVariableName.get("P")));
addConstructor(result);
addFields(result);
addMethods(result);
return JavaFile.builder(getPackageName(), result.build())
.addFileComment("Generated class from EasyMVP. Do not modify!").build();
}
示例13: generate
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
TypeSpec generate(String generatedCodePackageName, Set<String> glideExtensionClassNames) {
glideOptionsName =
ClassName.get(generatedCodePackageName, GENERATED_REQUEST_OPTIONS_SIMPLE_NAME);
List<MethodAndStaticVar> methodsForExtensions =
generateMethodsForExtensions(glideExtensionClassNames);
Set<MethodSignature> extensionMethodSignatures = ImmutableSet.copyOf(
Iterables.transform(methodsForExtensions,
new Function<MethodAndStaticVar, MethodSignature>() {
@Nullable
@Override
public MethodSignature apply(MethodAndStaticVar f) {
return new MethodSignature(f.method);
}
}));
List<MethodAndStaticVar> staticOverrides = generateStaticMethodOverridesForRequestOptions();
List<MethodSpec> instanceOverrides = generateInstanceMethodOverridesForRequestOptions();
List<MethodAndStaticVar> allMethodsAndStaticVars = new ArrayList<>();
for (MethodAndStaticVar item : staticOverrides) {
if (extensionMethodSignatures.contains(new MethodSignature(item.method))) {
continue;
}
allMethodsAndStaticVars.add(item);
}
for (MethodSpec methodSpec : instanceOverrides) {
if (extensionMethodSignatures.contains(new MethodSignature(methodSpec))) {
continue;
}
allMethodsAndStaticVars.add(new MethodAndStaticVar(methodSpec));
}
allMethodsAndStaticVars.addAll(methodsForExtensions);
TypeSpec.Builder classBuilder = TypeSpec.classBuilder(GENERATED_REQUEST_OPTIONS_SIMPLE_NAME)
.addAnnotation(
AnnotationSpec.builder(SuppressWarnings.class)
.addMember("value", "$S", "deprecation")
.build())
.addJavadoc(generateClassJavadoc(glideExtensionClassNames))
.addModifiers(Modifier.FINAL)
.addModifiers(Modifier.PUBLIC)
.superclass(requestOptionsName);
for (MethodAndStaticVar methodAndStaticVar : allMethodsAndStaticVars) {
if (methodAndStaticVar.method != null) {
classBuilder.addMethod(methodAndStaticVar.method);
}
if (methodAndStaticVar.staticField != null) {
classBuilder.addField(methodAndStaticVar.staticField);
}
}
return classBuilder.build();
}
示例14: createEnumBuilder
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
public static TypeSpec.Builder createEnumBuilder(ClassName name) {
return TypeSpec.enumBuilder(name).addAnnotation(GENERATED).addModifiers(Modifier.PUBLIC);
}
示例15: createInterfaceBuilder
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
public static TypeSpec.Builder createInterfaceBuilder(ClassName name) {
return TypeSpec.interfaceBuilder(name).addAnnotation(GENERATED).addModifiers(Modifier.PUBLIC);
}