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


Java ClassName.bestGuess方法代码示例

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


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

示例1: bestGuess

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private static TypeName bestGuess(String type) {
  switch (type) {
    case "void": return TypeName.VOID;
    case "boolean": return TypeName.BOOLEAN;
    case "byte": return TypeName.BYTE;
    case "char": return TypeName.CHAR;
    case "double": return TypeName.DOUBLE;
    case "float": return TypeName.FLOAT;
    case "int": return TypeName.INT;
    case "long": return TypeName.LONG;
    case "short": return TypeName.SHORT;
    default:
      int left = type.indexOf('<');
      if (left != -1) {
        ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
        List<TypeName> typeArguments = new ArrayList<>();
        do {
          typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
          left = type.indexOf('<', left + 1);
        } while (left != -1);
        return ParameterizedTypeName.get(typeClassName,
            typeArguments.toArray(new TypeName[typeArguments.size()]));
      }
      return ClassName.bestGuess(type);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:BindingSet.java

示例2: generateConstructor

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec generateConstructor(ClassName appGlideModule,
    Set<String> libraryGlideModuleClassNames, Set<String> excludedGlideModuleClassNames) {
  MethodSpec.Builder constructorBuilder = MethodSpec.constructorBuilder();
  constructorBuilder.addStatement("appGlideModule = new $T()", appGlideModule);

  ClassName androidLogName = ClassName.get("android.util", "Log");

  // Add some log lines to indicate to developers which modules where discovered.
  constructorBuilder.beginControlFlow("if ($T.isLoggable($S, $T.DEBUG))",
      androidLogName, GLIDE_LOG_TAG, androidLogName);
  constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
      "Discovered AppGlideModule from annotation: " + appGlideModule);
  // Excluded GlideModule classes from the manifest are logged in Glide's singleton.
  for (String glideModule : libraryGlideModuleClassNames) {
    ClassName moduleClassName = ClassName.bestGuess(glideModule);
    if (excludedGlideModuleClassNames.contains(glideModule)) {
      constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
          "AppGlideModule excludes LibraryGlideModule from annotation: " + moduleClassName);
    } else {
      constructorBuilder.addStatement("$T.d($S, $S)", androidLogName, GLIDE_LOG_TAG,
          "Discovered LibraryGlideModule from annotation: " + moduleClassName);
    }
  }
  constructorBuilder.endControlFlow();
  return constructorBuilder.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:27,代码来源:AppModuleGenerator.java

示例3: generateAdditionalRequestManagerMethodNew

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec generateAdditionalRequestManagerMethodNew(
    ExecutableElement extensionMethod) {
   String returnType = processorUtil.findClassValuesFromAnnotationOnClassAsNames(extensionMethod,
      GlideType.class).iterator().next();
  ClassName returnTypeClassName = ClassName.bestGuess(returnType);
  ParameterizedTypeName parameterizedTypeName =
      ParameterizedTypeName.get(generatedRequestBuilderClassName, returnTypeClassName);

  return MethodSpec.methodBuilder(extensionMethod.getSimpleName().toString())
      .addModifiers(Modifier.PUBLIC)
      .returns(parameterizedTypeName)
      .addJavadoc(processorUtil.generateSeeMethodJavadoc(extensionMethod))
      .addStatement(
          "return ($T) $T.$N(this.as($T.class))",
          parameterizedTypeName,
          extensionMethod.getEnclosingElement(),
          extensionMethod.getSimpleName(),
          returnTypeClassName)
      .build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:21,代码来源:RequestManagerGenerator.java

示例4: generateRegisterComponents

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec generateRegisterComponents(Set<String> libraryGlideModuleClassNames,
    Set<String> excludedGlideModuleClassNames) {
  MethodSpec.Builder registerComponents =
      MethodSpec.methodBuilder("registerComponents")
          .addModifiers(Modifier.PUBLIC)
          .addAnnotation(Override.class)
          .addParameter(ClassName.get("android.content", "Context"), "context")
          .addParameter(ClassName.get("com.bumptech.glide", "Glide"), "glide")
          .addParameter(ClassName.get("com.bumptech.glide", "Registry"), "registry");

  for (String glideModule : libraryGlideModuleClassNames) {
    if (excludedGlideModuleClassNames.contains(glideModule)) {
      continue;
    }
    ClassName moduleClassName = ClassName.bestGuess(glideModule);
    registerComponents.addStatement(
        "new $T().registerComponents(context, glide, registry)", moduleClassName);
  }
  // Order matters here. The AppGlideModule must be called last.
  registerComponents.addStatement("appGlideModule.registerComponents(context, glide, registry)");
  return registerComponents.build();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:AppModuleGenerator.java

示例5: generateListType

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
@Nonnull
private TypeName generateListType(@Nonnull String className, @Nonnull JsonValue value, @Nonnull ClassBuilder builder) {
    if (value.isArray()) {
        final JsonValue firstValue = value.asArray()
                .stream()
                .findFirst()
                .orElse(new JsonNull());
        final TypeName type = generateListType(className, firstValue, builder);
        return ParameterizedTypeName.get(ClassName.get(List.class), type);
    }

    if (value.isObject()) {
        final TypeSpec innerClass = fromObject(className, value.asObject(), Modifier.PUBLIC, Modifier.STATIC);
        builder.addInnerType(innerClass);

        final TypeName innerClassType = ClassName.bestGuess(innerClass.name);
        return ParameterizedTypeName.get(ClassName.get(List.class), innerClassType);
    }

    return ParameterizedTypeName.get(ClassName.get(List.class), value.getType().box());
}
 
开发者ID:t28hub,项目名称:json2java4idea,代码行数:22,代码来源:JavaConverter.java

示例6: callMethodShortcut

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private MethodSpec callMethodShortcut() {
    HashMap<String, List<String>> classMethodsMap = new HashMap<>();

    for (final ShortcutAnnotatedElement annotatedElement : annotatedElements) {
        if (annotatedElement instanceof ShortcutAnnotatedMethod) {
            final ShortcutAnnotatedMethod annotatedMethod = (ShortcutAnnotatedMethod) annotatedElement;
            if (classMethodsMap.containsKey(annotatedMethod.getClassName())) {
                classMethodsMap.get(annotatedElement.getClassName()).add(annotatedMethod.getMethodName());
            } else {
                classMethodsMap.put(annotatedMethod.getClassName(), new ArrayList<String>() {{
                    add(annotatedMethod.getMethodName());
                }});
            }
        }
    }

    final MethodSpec.Builder methodBuilder = MethodSpec.methodBuilder("callMethodShortcut")
            .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
            .returns(void.class)
            .addParameter(activity, "activity");

    for (final Map.Entry<String, List<String>> annotatedMethodName : classMethodsMap.entrySet()) {
        ClassName activityClassName = ClassName.bestGuess(annotatedMethodName.getKey());
        List<String> methodNames = annotatedMethodName.getValue();
        methodBuilder.beginControlFlow("if (activity instanceof $T)", activityClassName);
        for (final String methodName : methodNames) {
            methodBuilder.beginControlFlow("if ($S.equals(activity.getIntent().getStringExtra($S)))", methodName, EXTRA_METHOD);
            methodBuilder.addStatement("(($T) activity).$L()", activityClassName, methodName);
            methodBuilder.endControlFlow();
        }
        methodBuilder.endControlFlow();
    }

    return methodBuilder
            .build();
}
 
开发者ID:MatthiasRobbers,项目名称:shortbread,代码行数:37,代码来源:CodeGenerator.java

示例7: PresenterCommandSourceWriter

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public PresenterCommandSourceWriter(ProcessorElement processorElement, String targetPackage,
                                    String className, String presenterName) {
    super(processorElement);
    this.targetPackage = targetPackage;
    this.className = className;
    this.presenterType = ClassName.bestGuess(presenterName);
}
 
开发者ID:GwtDomino,项目名称:domino,代码行数:8,代码来源:PresenterCommandSourceWriter.java

示例8: testNestedBeanTypeField

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
@Test
public void testNestedBeanTypeField() throws Exception {

    ClassName serializer = ClassName.bestGuess("com.progressoft.brix.domino.jacksonapt.processor.TestBeanBeanJsonSerializerImpl");
    TypeRegistry.registerSerializer("com.progressoft.brix.domino.jacksonapt.processor.TestBean", serializer);
    addFieldTest("testBean", result -> assertEquals(buildTestString("new $T()", serializer), result));

    runTests();
}
 
开发者ID:vegegoku,项目名称:gwt-jackson-apt,代码行数:10,代码来源:SerializerInstanceBuilderTest.java

示例9: getJavadocSafeName

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
/**
 * Returns a safe String to use in a Javadoc that will function in a link.
 *
 * <p>This method exists because by Javadoc doesn't handle type parameters({@literal <T>}
 * in {@literal RequestOptions<T>} for example).
 */
private TypeName getJavadocSafeName(Element element) {
  Types typeUtils = processingEnv.getTypeUtils();
  TypeMirror type = element.asType();
  if (typeUtils.asElement(type) == null) {
    // If there is no Element, it's a primitive and can't have additional types, so we're done.
    return ClassName.get(element.asType());
  }
  Name simpleName = typeUtils.asElement(type).getSimpleName();
  return ClassName.bestGuess(simpleName.toString());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:17,代码来源:ProcessorUtil.java

示例10: bestGuess

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
private static TypeName bestGuess(String type) {
    switch (type) {
        case "void":
            return TypeName.VOID;
        case "boolean":
            return TypeName.BOOLEAN;
        case "byte":
            return TypeName.BYTE;
        case "char":
            return TypeName.CHAR;
        case "double":
            return TypeName.DOUBLE;
        case "float":
            return TypeName.FLOAT;
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "short":
            return TypeName.SHORT;
        default:
            int left = type.indexOf('<');
            if (left != -1) {
                ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
                List<TypeName> typeArguments = new ArrayList<>();
                do {
                    typeArguments.add(WildcardTypeName.subtypeOf(Object.class));
                    left = type.indexOf('<', left + 1);
                } while (left != -1);
                return ParameterizedTypeName.get(typeClassName,
                        typeArguments.toArray(new TypeName[typeArguments.size()]));
            }
            return ClassName.bestGuess(type);
    }
}
 
开发者ID:qq542391099,项目名称:butterknife-parent,代码行数:36,代码来源:BindingSet.java

示例11: bestGuessDeep

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
/**
 * @param type
 * @return
 */
public static TypeName bestGuessDeep(String type) {
    switch (type) {
        case "void":
            return TypeName.VOID;
        case "boolean":
            return TypeName.BOOLEAN;
        case "byte":
            return TypeName.BYTE;
        case "char":
            return TypeName.CHAR;
        case "double":
            return TypeName.DOUBLE;
        case "float":
            return TypeName.FLOAT;
        case "int":
            return TypeName.INT;
        case "long":
            return TypeName.LONG;
        case "short":
            return TypeName.SHORT;
        default:
            int left = type.indexOf('<');
            int right = type.indexOf('>');
            if (-1 != left && -1 != right) {
                ClassName typeClassName = ClassName.bestGuess(type.substring(0, left));
                List<TypeName> typeArguments = new ArrayList<>();
                do {
                    typeArguments.add(WildcardTypeName.subtypeOf(bestGuess(type.substring(left + 1, right))));
                    left = type.indexOf('<', left + 1);
                    right = type.indexOf('>', right - 1);
                } while (left != -1);
                return ParameterizedTypeName.get(typeClassName,
                        typeArguments.toArray(new TypeName[typeArguments.size()]));
            }
            return ClassName.bestGuess(type);
    }
}
 
开发者ID:wangjiegulu,项目名称:RapidRouter,代码行数:42,代码来源:EasyType.java

示例12: processGet

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
void processGet(ElementDescription elem, MethodSpec.Builder builder) {
    if(elem.code != null && elem.code.isGeneric()) {
        String[] types = elem.code.genericTypes();
        Object[] args = new Object[types.length + 2];
        args[0] = ClazzNames.GSON_HELPER;
        args[1] = ClazzNames.STORAGE_HELPER;
        args[2] = ClazzNames.TYPE_TOKEN;
        for (int i=3; i<args.length; i++) {
            args[i] = ClassName.bestGuess(types[i-2]);
        }
        builder.addStatement("return $T.fromJson($T.get(app, \""
                + elem.key + "\"), new $T<" + elem.code.genericTypes()[0]+">(){}.getType())",
                args);
    } else if(isBool(elem)) {
        builder.addStatement("return $T.getBoolean(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else if(isFloat(elem)) {
        builder.addStatement("return $T.getFloat(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else if(isInt(elem)) {
        builder.addStatement("return $T.getInt(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else if(isLong(elem)) {
        builder.addStatement("return $T.getLong(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else if(isString(elem)) {
        builder.addStatement("return $T.get(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else if(isStringSet(elem)) {
        builder.addStatement("return $T.getStringSet(app, \"" + elem.key + "\")", ClazzNames.STORAGE_HELPER);
    } else {
        builder.addStatement("return $T.fromJson($T.get(app, \""
                + elem.key + "\"), " + elem.fieldType.toString()+".class)",
                ClazzNames.GSON_HELPER,
                ClazzNames.STORAGE_HELPER);
    }
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:33,代码来源:SharePreferenceGenerator.java

示例13: toWrite

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public static void toWrite(ProcessorHelper helper, LJSONTypeElement ljsonElement, Filer filer) throws IOException {

        // create common ClassName
        ClassName thisObj = ClassName.bestGuess(ljsonElement.getTypeName());
        ClassName jsonObject = ClassName.get("org.json", "JSONObject");

        MethodSpec.Builder createMethod = MethodSpec.methodBuilder("create")
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                .returns(thisObj)
                .addParameter(ClassName.get(String.class), "json", Modifier.FINAL)
                .addParameter(TypeName.BOOLEAN, "allowNull", Modifier.FINAL)
                .addStatement("$T thisObj = new $T()", thisObj, thisObj)
                .beginControlFlow("try")
                .addStatement("$T root = new $T(json)", jsonObject, jsonObject);

        List<LIMITJSONVariable> ljsonVariableElements = ljsonElement.getVariableElements();
        addLJSONVariable(helper, createMethod, ljsonVariableElements);

        createMethod.nextControlFlow("catch (Exception e)")
                .beginControlFlow("if (allowNull)")
                .addStatement("return null")
                .endControlFlow()
                .endControlFlow();

        createMethod.addStatement("return thisObj");
        // generate whole class
        TypeSpec finderClass = TypeSpec.classBuilder(ljsonElement.getTypeName() + "$$CREATOR")
                .addModifiers(Modifier.PUBLIC)
//                .addSuperinterface(ParameterizedTypeName.get(ClassName.get(CORE_PACKAGE_NAME, "Core"), TypeName.get(classElement.asType())))
                .addMethod(createMethod.build())
//                .addMethod(parseIntentBuilder.build())
//                .addMethod(saveInstanceStateBuilder.build())
                .build();

        String packageName = ljsonElement.getTypePackageName();
        // generate file
        JavaFile.builder(packageName, finderClass).build().writeTo(filer);
    }
 
开发者ID:freelifer,项目名称:limitjson,代码行数:39,代码来源:LJSONAnnotatedClass.java

示例14: process

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
@TargetApi(24)
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnvironment) {
    if (annotations.isEmpty()) {
        return true;
    }

    TypeElement originalClass = roundEnvironment.getElementsAnnotatedWith(WrapStatic.class).stream()
            .filter(element -> element.getKind() == ElementKind.CLASS)
            .map(element -> (TypeElement) element)
            .findFirst()
            .get();

    List<ExecutableElement> staticMethods = originalClass.getEnclosedElements().stream()
            .filter(element -> element.getKind() == ElementKind.METHOD)
            .map(element -> (ExecutableElement) element)
            .filter(executableElement -> executableElement.getModifiers().stream().anyMatch(modifier -> modifier == Modifier.STATIC))
            .filter(executableElement -> executableElement.getModifiers().stream().noneMatch(modifier -> modifier == Modifier.PRIVATE))
            .collect(Collectors.toList());

    List<MethodSpec> proxyMethods = staticMethods.stream()
            .map((method) -> getProxyMethod(originalClass, method))
            .collect(Collectors.toList());

    String targetPackage = elementUtils.getPackageOf(originalClass).getQualifiedName().toString();
    String targetClassName = getTargetClassName(originalClass);
    ClassName className = ClassName.bestGuess(String.format("%s.%s", targetPackage, targetClassName));
    FieldSpec singletonField = getSingletonField(className);

    TypeSpec targetTypeSpec = TypeSpec
            .classBuilder(targetClassName)
            .addModifiers(getTargetClassModifiers(originalClass))
            .addField(singletonField)
            .addMethod(getSingletonGetterMethod(className, singletonField))
            .addMethod(getSingletonSetterMethod(className, singletonField))
            .addMethods(proxyMethods)
            .build();

    JavaFile javaFile = JavaFile
            .builder(targetPackage, targetTypeSpec)
            .addFileComment("This is auto-generated code. Do not modify this directly.")
            .build();

    try {
        javaFile.writeTo(filer);
    } catch (IOException e) {
        messager.printMessage(Diagnostic.Kind.ERROR, e.getMessage());
    }

    return true;
}
 
开发者ID:srym,项目名称:shoebill,代码行数:52,代码来源:ShoebillProcessor.java

示例15: addType

import com.squareup.javapoet.ClassName; //导入方法依赖的package包/类
public void addType(TargetDescriptor des) {
    ClassName serviceType = ClassName.bestGuess(des.name);
    ClassName builderName = ClassName.bestGuess(des.name + AnnotationConstants.SUFFIX_SERVICE_TARGET);
    addType(des.getSimpleName(), des.name, serviceType, builderName, null);
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:6,代码来源:ServiceHandler.java


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