本文整理匯總了Java中com.squareup.javapoet.TypeSpec.interfaceBuilder方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeSpec.interfaceBuilder方法的具體用法?Java TypeSpec.interfaceBuilder怎麽用?Java TypeSpec.interfaceBuilder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.javapoet.TypeSpec
的用法示例。
在下文中一共展示了TypeSpec.interfaceBuilder方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildNativeLifecycleInterface
import com.squareup.javapoet.TypeSpec; //導入方法依賴的package包/類
@Nonnull
private static TypeSpec buildNativeLifecycleInterface( @Nonnull final ComponentDescriptor descriptor )
{
final TypeSpec.Builder builder = TypeSpec.interfaceBuilder( "Lifecycle" );
builder.addAnnotation( AnnotationSpec.builder( JS_TYPE_CLASSNAME ).
addMember( "isNative", "true" ).
build() );
builder.addModifiers( Modifier.STATIC );
// Lifecycle methods
{
for ( final MethodDescriptor lifecycleMethod : descriptor.getLifecycleMethods() )
{
final String methodName = lifecycleMethod.getMethod().getSimpleName().toString();
final MethodSpec.Builder method =
MethodSpec.methodBuilder( methodName ).
addModifiers( Modifier.ABSTRACT, Modifier.PUBLIC ).
returns( ClassName.get( lifecycleMethod.getMethodType().getReturnType() ) );
ProcessorUtil.copyTypeParameters( lifecycleMethod.getMethodType(), method );
final List<? extends VariableElement> sourceParameters = lifecycleMethod.getMethod().getParameters();
final List<? extends TypeMirror> sourceParameterTypes = lifecycleMethod.getMethodType().getParameterTypes();
final int parameterCount = sourceParameters.size();
for ( int i = 0; i < parameterCount; i++ )
{
final VariableElement parameter = sourceParameters.get( i );
final TypeMirror parameterType = sourceParameterTypes.get( i );
final String parameterName = parameter.getSimpleName().toString();
final ParameterSpec.Builder parameterSpec =
ParameterSpec.builder( TypeName.get( parameterType ), parameterName ).addAnnotation( NONNULL_CLASSNAME );
method.addParameter( parameterSpec.build() );
}
builder.addMethod( method.build() );
}
}
return builder.build();
}