本文整理匯總了Java中com.squareup.javapoet.AnnotationSpec.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java AnnotationSpec.Builder方法的具體用法?Java AnnotationSpec.Builder怎麽用?Java AnnotationSpec.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.javapoet.AnnotationSpec
的用法示例。
在下文中一共展示了AnnotationSpec.Builder方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generate
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
private static TypeSpec generate(List<TypeElement> libraryModules,
Class<? extends Annotation> annotation) {
AnnotationSpec.Builder annotationBuilder =
AnnotationSpec.builder(Index.class);
String value = getAnnotationValue(annotation);
for (TypeElement childModule : libraryModules) {
annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
}
String indexerName = INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_";
for (TypeElement element : libraryModules) {
indexerName += element.getQualifiedName().toString().replace(".", "_");
indexerName += "_";
}
indexerName = indexerName.substring(0, indexerName.length() - 1);
return TypeSpec.classBuilder(indexerName)
.addAnnotation(annotationBuilder.build())
.addModifiers(Modifier.PUBLIC)
.build();
}
示例2: generate
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
private static TypeSpec generate(List<TypeElement> libraryModules,
Class<? extends Annotation> annotation) {
AnnotationSpec.Builder annotationBuilder =
AnnotationSpec.builder(Index.class);
String value = getAnnotationValue(annotation);
for (TypeElement childModule : libraryModules) {
annotationBuilder.addMember(value, "$S", ClassName.get(childModule).toString());
}
StringBuilder indexerName = new StringBuilder(
INDEXER_NAME_PREFIX + annotation.getSimpleName() + "_");
for (TypeElement element : libraryModules) {
indexerName.append(element.getQualifiedName().toString().replace(".", "_"));
indexerName.append("_");
}
indexerName = new StringBuilder(indexerName.substring(0, indexerName.length() - 1));
return TypeSpec.classBuilder(indexerName.toString())
.addAnnotation(annotationBuilder.build())
.addModifiers(Modifier.PUBLIC)
.build();
}
示例3: getMethodSpec
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
/**
* genera il metodo di test per method di clazz
*
* @param count
* @param method
* @param clazz
* @param infoFromMongoDb
* @param methodOutput
* @return
*/
private MethodSpec getMethodSpec(int count, Method method, Class<?> clazz, Document methodInputs,
Document methodOutput) {
String result = getAssignmentOfMethodResult(method);
String expected = getExpectedResultAsBooleanAssert(method, methodOutput);
MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder(method.getName() + count + TEST);
/*
* for non spring test
*/
String invokerName = getInvokerName(method, clazz, methodInputs, methodBuilder);
String params = getParams(method, methodBuilder, methodInputs);
AnnotationSpec.Builder annSpecBuilder = AnnotationSpec.builder(Test.class);
addExpectedExceptionIfAny(methodInputs, annSpecBuilder);
AnnotationSpec annTestSpec = annSpecBuilder.build();
methodBuilder.addAnnotation(annTestSpec)
.addStatement(result + invokerName + ".$N(" + params + ")", method.getName())
.addModifiers(Modifier.PUBLIC);
methodBuilder.addStatement("$L.assertTrue(" + expected + ")", Assert.class.getName());
methodBuilder.addJavadoc("\n");
return methodBuilder.build();
}
示例4: getTypeSpec
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
/**
* genera classe di test per clazz
*
* @param clazz
* @param prop
* @param mongo
* @return
*/
@Override
public TypeSpec getTypeSpec(Class<?> clazz) {
Builder classTestBuilder = TypeSpec.classBuilder(clazz.getSimpleName() + TEST);
ClassName superClass = ClassName.get(
PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_PACKAGE),
PropertiesUtils.getRequiredProperty(prop, PropertiesUtils.TEST_BASE_CLASS));
classTestBuilder.superclass(superClass);
classTestBuilder.addJavadoc("@author \n");
classTestBuilder.addModifiers(Modifier.PUBLIC);
AnnotationSpec.Builder annSpecBuilder = AnnotationSpec.builder(Generated.class);
annSpecBuilder.addMember("value", "\"it.fratta.jerkoff.Generator\"");
annSpecBuilder.addMember("date", "\"" + Calendar.getInstance().getTime().toString() + "\"");
AnnotationSpec annGenSpec = annSpecBuilder.build();
classTestBuilder.addAnnotation(annGenSpec);
/*
* for spring test
*/
// FieldSpec.Builder spec = FieldSpec.builder(clazz,
// getNewInstanceOfNoParameters(clazz), Modifier.PRIVATE);
// spec.addAnnotation(Autowired.class);
// classTestBuilder.addField(spec.build());
addClassMethodsToBuilder(classTestBuilder, clazz);
return classTestBuilder.build();
}
示例5: suppressWarnings
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
public static AnnotationSpec suppressWarnings(String... warnings) {
AnnotationSpec.Builder builder = AnnotationSpec.builder(SuppressWarnings.class);
CodeBlock.Builder names = CodeBlock.builder();
boolean first = true;
for (String warning : warnings) {
if (first) {
names.add("$S", warning);
first = false;
} else {
names.add(", $S", warning);
}
}
if (warnings.length == 1) {
builder.addMember("value", names.build());
} else {
builder.addMember("value", "{$L}", names.build());
}
return builder.build();
}
示例6: build
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
public AnnotationSpec build() {
AnnotationSpec.Builder builder = SPEC.toBuilder();
if (value != null) {
builder.addMember("value", valueFormat, value);
}
if (allOf != null && allOf.size() > 0) {
builder.addMember("allOf", allOfFormat, allOf.toArray());
}
if (anyOf != null && anyOf.size() > 0) {
builder.addMember("anyOf", anyOfFormat, anyOf.toArray());
}
if (conditional != null) {
builder.addMember("conditional", conditionalFormat, conditional);
}
return builder.build();
}
示例7: build
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
public AnnotationSpec build() {
AnnotationSpec.Builder builder = SPEC.toBuilder();
if (value != null) {
builder.addMember("value", valueFormat, value);
}
if (min != null) {
builder.addMember("min", minFormat, min);
}
if (max != null) {
builder.addMember("max", maxFormat, max);
}
if (multiple != null) {
builder.addMember("multiple", multipleFormat, multiple);
}
return builder.build();
}
示例8: build
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
public AnnotationSpec build() {
AnnotationSpec.Builder builder = SPEC.toBuilder();
if (from != null) {
builder.addMember("from", fromFormat, this.from);
}
if (to != null) {
builder.addMember("to", toFormat, this.to);
}
if (fromInclusive != null) {
builder.addMember("fromInclusive", fromInclusiveFormat, this.fromInclusive);
}
if (toInclusive != null) {
builder.addMember("toInclusive", toInclusiveFormat, this.toInclusive);
}
return builder.build();
}
示例9: suppressWarnings
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
private AnnotationSpec suppressWarnings(Collection<String> warnings) {
AnnotationSpec.Builder anno = AnnotationSpec.builder(SuppressWarnings.class);
if (warnings.isEmpty()) {
throw new IllegalArgumentException("No warnings present - compiler error?");
}
if (warnings.size() == 1) {
anno.addMember("value", "$S", Iterables.get(warnings, 0));
} else {
StringBuilder sb = new StringBuilder("{");
for (String warning : warnings) {
sb.append("\"");
sb.append(warning);
sb.append("\", ");
}
sb.setLength(sb.length() - 2);
sb.append("}");
anno.addMember("value", "$L", sb.toString());
}
return anno.build();
}
示例10: fieldAnnotation
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
private static AnnotationSpec fieldAnnotation(Field field) {
AnnotationSpec.Builder ann = AnnotationSpec.builder(ThriftField.class)
.addMember("fieldId", "$L", field.id());
if (field.required()) {
ann.addMember("isRequired", "$L", field.required());
}
if (field.optional()) {
ann.addMember("isOptional", "$L", field.optional());
}
String typedef = field.typedefName();
if (!Strings.isNullOrEmpty(typedef)) {
ann = ann.addMember("typedefName", "$S", typedef);
}
return ann.build();
}
示例11: build
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
@Override
protected TypeSpec.Builder build()
{
String params = "{";
ClassName[] vars = new ClassName[viewElements.size()];
int i = 0;
for (Iterator<Element> it = viewElements.iterator(); it.hasNext(); i++)
{
Element element = it.next();
params += "$T.class";
vars[i] = ClassName.bestGuess(element.asType().toString());
if (i < viewElements.size() - 1)
{
params += ", ";
}
}
params += "}";
AnnotationSpec.Builder annotationBuilder = AnnotationSpec.builder(Generate.class);
annotationBuilder.addMember("views", params, (Object[]) vars);
annotationBuilder.addMember("application", "$T.class", applicationClassName);
return TypeSpec.classBuilder("Trigger")
.addModifiers(Modifier.ABSTRACT)
.addAnnotation(annotationBuilder.build());
}
示例12: getQualifiers
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
/**
* Returns list of all annotations given <code>element</code> has.
*
* @param element Element.
*/
public List<AnnotationSpec> getQualifiers(Element element) {
List<AnnotationSpec> list = new ArrayList<>();
for (AnnotationMirror a : element.getAnnotationMirrors()) {
if (a.getAnnotationType().asElement().getAnnotation(Qualifier.class) == null) {
continue; // ignore non-Qualifier annotations
}
ClassName annotationClassName = (ClassName) ClassName.get(a.getAnnotationType());
AnnotationSpec.Builder annotation = AnnotationSpec.builder(annotationClassName);
for (Map.Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : a.getElementValues().entrySet()) {
String format = (entry.getValue().getValue() instanceof String) ? "$S" : "$L";
annotation.addMember(entry.getKey().getSimpleName().toString(), format, entry.getValue().getValue());
}
list.add(annotation.build());
}
return list;
}
示例13: addGeneratedAnnotation
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
private void addGeneratedAnnotation(
final TypeSpec.Builder typeSpecBuilder, final ProcessorContext processorContext
) {
final AnnotationSpec.Builder annotationBuilder =
AnnotationSpec.builder(Generated.class)
.addMember("value", "$S", JackdawProcessor.class.getName());
if (processorContext.isAddGeneratedDate()) {
final String currentTime =
DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(new Date());
annotationBuilder.addMember("date", "$S", currentTime);
}
typeSpecBuilder.addAnnotation(annotationBuilder.build());
}
示例14: mimicMethodAnnotations
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
/** Mimic annotations of the method, but exclude @Yield annotation during processing. */
public static void mimicMethodAnnotations(@NonNull final MethodSpec.Builder builder,
@NonNull final Symbol.MethodSymbol ms) throws Exception {
if (ms.hasAnnotations()) {
for (final Attribute.Compound am : ms.getAnnotationMirrors()) {
if (extractClass(am) == AutoProxy.Yield.class) continue;
if (extractClass(am) == AutoProxy.AfterCall.class) continue;
final AnnotationSpec.Builder builderAnnotation = mimicAnnotation(am);
if (null != builderAnnotation) {
builder.addAnnotation(builderAnnotation.build());
}
}
}
}
示例15: mimicParameters
import com.squareup.javapoet.AnnotationSpec; //導入方法依賴的package包/類
/** Compose method parameters that mimic original code. */
@NonNull
public static StringBuilder mimicParameters(@NonNull final MethodSpec.Builder builder,
@NonNull final Symbol.MethodSymbol ms) throws Exception {
String delimiter = "";
final StringBuilder arguments = new StringBuilder();
final com.sun.tools.javac.util.List<Symbol.VarSymbol> parameters = ms.getParameters();
for (int i = 0, len = parameters.size(); i < len; i++) {
final Symbol.VarSymbol param = parameters.get(i);
// mimic parameter of the method: name, type, modifiers
final TypeName paramType = TypeName.get(param.asType());
final String parameterName = param.name.toString();
final ParameterSpec.Builder parameter = ParameterSpec.builder(paramType, parameterName, Modifier.FINAL);
if (param.hasAnnotations()) {
// DONE: copy annotations of parameter
for (final Attribute.Compound am : param.getAnnotationMirrors()) {
final AnnotationSpec.Builder builderAnnotation = mimicAnnotation(am);
if (null != builderAnnotation) {
parameter.addAnnotation(builderAnnotation.build());
}
}
}
// support VarArgs if needed
builder.varargs(ms.isVarArgs() && i == len - 1);
builder.addParameter(parameter.build());
// compose parameters list for forwarding
arguments.append(delimiter).append(parameterName);
delimiter = ", ";
}
return arguments;
}