当前位置: 首页>>代码示例>>Java>>正文


Java Builder.add方法代码示例

本文整理汇总了Java中com.squareup.javapoet.CodeBlock.Builder.add方法的典型用法代码示例。如果您正苦于以下问题:Java Builder.add方法的具体用法?Java Builder.add怎么用?Java Builder.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.squareup.javapoet.CodeBlock.Builder的用法示例。


在下文中一共展示了Builder.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateClassJavadoc

import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
private CodeBlock generateClassJavadoc(Set<String> glideExtensionClassNames) {
  Builder builder = CodeBlock.builder()
      .add("Automatically generated from {@link $T} annotated classes.\n",
          GlideExtension.class)
      .add("\n")
      .add("@see $T\n", requestOptionsName);

  for (String glideExtensionClass : glideExtensionClassNames) {
    builder.add("@see $T\n", ClassName.bestGuess(glideExtensionClass));
  }
  return builder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:RequestOptionsGenerator.java

示例2: getDecodeCode

import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
@Override
public CodeBlock getDecodeCode(Property property, DecodeCodeProviders decodeProviders) {
	Builder builder = CodeBlock.builder();
	TypeMirror tm = property.getResolvedType();
	
	String accessName = property.getSetterCall();
	accessName += property.hasSetter() ? "(" : " = ";
	builder.add("instance." + accessName);
	putDecodeCode(builder, tm, decodeProviders, null, true);
	if ( property.hasSetter() ){
		builder.add(")");
	}
	builder.add(";\n");
	return builder.build();
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:16,代码来源:SingleStatementDecodeCodeProvider.java

示例3: putDecodeCode

import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
@Override
public void putDecodeCode(Builder cb, TypeMirror tm, DecodeCodeProviders decodeProviders, String variableToUse, boolean declareVariable) {
	DeclaredType entry = (DeclaredType)tm;
	TypeMirror keyArgument = entry.getTypeArguments().get(0);
	TypeMirror valueArgument = entry.getTypeArguments().get(1);
	
	cb.addStatement("reader.readStartDocument()");
	cb.addStatement("reader.readName(\"key\")");
	cb.addStatement("$T $L = null", keyArgument, variableToUse+"0");
	cb.addStatement("$T $L = null", valueArgument, variableToUse+"1");
	cb.addStatement("bsonType = reader.getCurrentBsonType()",  CodeUtil.bsonTypeTypeName());
	cb.beginControlFlow("if (bsonType == $T.NULL)", CodeUtil.bsonTypeTypeName());
		cb.addStatement("reader.readNull()");
		cb.addStatement("reader.skipName()");
		cb.addStatement("reader.skipValue()");
	cb.nextControlFlow("else");
		Builder builder = CodeBlock.builder();
		decodeProviders.putDecodeCode(builder, keyArgument, variableToUse+"0", false);
		boolean hasToInstantiate = decodeProviders.hasToInstantiate(keyArgument);
		if ( hasToInstantiate ){
			cb.add(builder.build());
		}else{
			cb.add("$L = ", variableToUse+"0");
			cb.add(builder.build()+";\n");
		}
		cb.addStatement("reader.readName(\"value\")");
		builder = CodeBlock.builder();
		decodeProviders.putDecodeCode(builder, valueArgument, variableToUse+"1", false);
		hasToInstantiate = decodeProviders.hasToInstantiate(valueArgument);
		if ( hasToInstantiate ){
			cb.add(builder.build());
		}else{
			cb.add("$L = ", variableToUse+"1");
			cb.add(builder.build()+";\n");
		}
	cb.endControlFlow();
	cb.addStatement("reader.readEndDocument()");		
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:39,代码来源:EntryDecodeCodeProvider.java

示例4: putDecodeCode

import com.squareup.javapoet.CodeBlock.Builder; //导入方法依赖的package包/类
protected void putDecodeCode(Builder cb, TypeMirror iterableTypeMirror, DecodeCodeProviders decodeProviders, String variableToUse, boolean instantiate, boolean declareVariable) {
	TypeMirror iterableType = getIterableType(iterableTypeMirror);
	String addMethod = getAddMethod();
	
	if ( instantiate ){
		TypeMirror iterableImplementationCollectionClass = getIterableImplementationType(iterableTypeMirror);
		TypeMirror iterableDeclarationCollectionClass = getIterableDeclarationType(iterableTypeMirror);
		if ( declareVariable ){
			cb.addStatement("$T $L = new $T()", iterableDeclarationCollectionClass, variableToUse, iterableImplementationCollectionClass);
		}else{
			cb.addStatement("$L = new $T()", variableToUse, iterableImplementationCollectionClass);
		}
	}

	cb.addStatement("reader.readStartArray()");
	cb.beginControlFlow("while (reader.readBsonType() != $T.END_OF_DOCUMENT)", CodeUtil.bsonTypeTypeName());
	cb.addStatement("bsonType = reader.getCurrentBsonType()",  CodeUtil.bsonTypeTypeName());
	cb.beginControlFlow("if (bsonType == $T.NULL)", CodeUtil.bsonTypeTypeName());
	cb.addStatement("reader.readNull()");
	if ( supportsNull(iterableType) ){
		cb.addStatement("$L.$L(null)", variableToUse, addMethod);
	}
	cb.nextControlFlow("else");
	Builder builder2 = CodeBlock.builder();
	if ( decodeProviders.applies(iterableType) ){
		String varName = nameGenerator.instanceName(iterableType).toLowerCase();
		decodeProviders.putDecodeCode(builder2, iterableType, varName);
		boolean hasToInstantiate = decodeProviders.hasToInstantiate(iterableType);
		if ( hasToInstantiate ){
			cb.add(builder2.build());
		}
		cb.add("$L.$L(",variableToUse, addMethod);
		if ( hasToInstantiate ){
			List<String> namesUsed = nameGenerator.generateNames(varName, decodeProviders.variablesUsed(iterableType));
			cb.add(Joiner.on(',').join(namesUsed));
		}else{
			cb.add(builder2.build());
		}
		cb.add(");\n");
	}
	cb.endControlFlow();
	cb.endControlFlow();
	cb.addStatement("reader.readEndArray()");
	return;
}
 
开发者ID:guicamest,项目名称:bsoneer,代码行数:46,代码来源:IterableDecodeCodeProvider.java


注:本文中的com.squareup.javapoet.CodeBlock.Builder.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。