當前位置: 首頁>>代碼示例>>Java>>正文


Java TypeName.equals方法代碼示例

本文整理匯總了Java中com.squareup.javapoet.TypeName.equals方法的典型用法代碼示例。如果您正苦於以下問題:Java TypeName.equals方法的具體用法?Java TypeName.equals怎麽用?Java TypeName.equals使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.squareup.javapoet.TypeName的用法示例。


在下文中一共展示了TypeName.equals方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: generateReadMethod

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private static boolean generateReadMethod(Context context) {
  TypeElement type = context.autoValueClass();
  //Find method with param as JSONObject and return type as autovalue class.
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (method.getModifiers().contains(Modifier.STATIC) && method.getParameters().size() == 1) {
      TypeMirror rType = method.getReturnType();
      TypeName returnType = TypeName.get(rType);

      TypeMirror pType = method.getParameters().get(0).asType();
      TypeName paramType = TypeName.get(pType);
      if (returnType.equals(TypeName.get(type.asType())) && paramType.equals(
          JSON_OBJ_CLASS_NAME)) {
        return true;
      }
    }
  }
  return false;
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:19,代碼來源:AutoValueJsonExtension.java

示例2: getValidatorMethod

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
@Nullable private ExecutableElement getValidatorMethod(Element element) {
  ParameterizedTypeName validatorType =
      ParameterizedTypeName.get(ClassName.get(Validator.class), TypeName.get(element.asType()));
  for (ExecutableElement method : ElementFilter.methodsIn(element.getEnclosedElements())) {
    if (method.getModifiers()
        .contains(Modifier.STATIC) && method.getModifiers()
        .contains(PUBLIC)) {
      TypeMirror rType = method.getReturnType();
      TypeName returnType = TypeName.get(rType);
      if (returnType.equals(validatorType)) {
        return method;
      }
    }
  }
  return null;
}
 
開發者ID:hzsweers,項目名稱:inspector,代碼行數:17,代碼來源:InspectorFactoryProcessor.java

示例3: find

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
@Nullable
public static TypeName find(KeyDefinition keyDefinition) {
    TypeName customPrefsAdapterType = keyDefinition.getCustomPrefsAdapterType();
    if (customPrefsAdapterType.equals(KonohanaTypes.UseBuildInPrefsAdapter)) {
        // Use BuildIn Adapter
        return Stream.of(BUILD_IN)
                .filter(prefsAdapter -> prefsAdapter.match(keyDefinition.getFieldTypeName()))
                .map(prefsAdapter -> prefsAdapter.adapter)
                .findFirst()
                .orElseGet(() -> {
                    if (keyDefinition.isEnum()) {
                        return KonohanaTypes.EnumPrefsAdapter;
                    } else if (keyDefinition.isList()) {
                        return KonohanaTypes.ListPrefsAdapter;
                    } else if (keyDefinition.isSet()) {
                        return KonohanaTypes.SetPrefsAdapter;
                    } else {
                        return KonohanaTypes.GsonPrefsAdapter;
                    }
                });
    } else {
        return customPrefsAdapterType;
    }
}
 
開發者ID:hisaichi5518,項目名稱:konohana,代碼行數:25,代碼來源:PrefsAdapter.java

示例4: getMethodByType

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private String getMethodByType(TypeName clazz) {
    StringBuilder sb = new StringBuilder("get");
    if (clazz.equals(TypeName.INT) || clazz.equals(TypeName.INT.box())) {
        sb.append("Int");
    } else if (clazz.equals(TypeName.BOOLEAN) || clazz.equals(TypeName.BOOLEAN.box())) {
        sb.append("Boolean");
    } else if (clazz.equals(TypeName.FLOAT) || clazz.equals(TypeName.FLOAT.box())) {
        sb.append("Float");
    } else if (clazz.equals(TypeName.DOUBLE) || clazz.equals(TypeName.DOUBLE.box())) {
        sb.append("Double");
    } else if (clazz.equals(TypeName.LONG) || clazz.equals(TypeName.LONG.box())) {
        sb.append("Long");
    } else if (clazz.equals(TypeName.SHORT) || clazz.equals(TypeName.SHORT.box())) {
        sb.append("Short");
    } else if (clazz.equals(TypeName.CHAR) || clazz.equals(TypeName.CHAR.box())) {
        sb.append("Char");
    } else if (clazz.equals(TypeName.VOID) || clazz.equals(TypeName.VOID.box()) ||
            clazz.equals(TypeName.BYTE) || clazz.equals(TypeName.BYTE.box())
            || clazz.equals(TypeName.OBJECT)) {
        //should not use this type
    } else {
        sb.append("String");
    }
    return sb.append("Param").toString();
}
 
開發者ID:bboylin,項目名稱:D-Router,代碼行數:26,代碼來源:ActivityHelperGenerator.java

示例5: getTargetType

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private TypeName getTargetType(TypeMirror mirror) {
  TypeName typeName = TypeName.get(mirror);
  if (typeName instanceof ParameterizedTypeName) {
    ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;
    if (parameterizedTypeName.rawType.equals(VIEW_MANAGER_TYPE)) {
      return parameterizedTypeName.typeArguments.get(0);
    }
  } else if (typeName.equals(SHADOW_NODE_TYPE)) {
    return SHADOW_NODE_TYPE;
  } else if (typeName.equals(TypeName.OBJECT)) {
    throw new IllegalArgumentException("Could not find target type");
  }

  List<? extends TypeMirror> types = mTypes.directSupertypes(mirror);
  return getTargetType(types.get(0));
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:17,代碼來源:ReactPropertyProcessor.java

示例6: readValue

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
static CodeBlock readValue(Types types, JsonProperty property, ParameterSpec json,
    FieldSpec field, FieldSpec key, NameAllocator nameAllocator) {
  //TODO Handle collections.
  TypeName type = getTypeNameFromProperty(property, types);
  CodeBlock.Builder builder = CodeBlock.builder();

  if (type.equals(STRING)) {
    builder.addStatement("$N = $N.getString($N)", field, json, key);
  } else if (type.equals(TypeName.INT) || type.equals(TypeName.INT.box())) {
    builder.addStatement("$N = $N.getInt($N)", field, json, key);
  } else if (type.equals(TypeName.DOUBLE) || type.equals(TypeName.DOUBLE.box())) {
    builder.addStatement("$N = $N.getDouble($N)", field, json, key);
  } else if (type.equals(TypeName.FLOAT) || type.equals(TypeName.FLOAT.box())) {
    builder.addStatement("$N = (float) $N.getDouble($N)", field, json, key);
  } else if (type.equals(TypeName.BOOLEAN) || type.equals(TypeName.BOOLEAN.box())) {
    builder.addStatement("$N = $N.getBoolean($N)", field, json, key);
  } else if (type.equals(TypeName.LONG) || type.equals(TypeName.LONG.box())) {
    builder.addStatement("$N = $N.getLong($N)", field, json, key);
  } else if (type.equals(TypeName.SHORT) || type.equals(TypeName.SHORT.box())) {
    builder.addStatement("$N = (short) $N.getInt($N)", field, json, key);
  } else if (type.equals(TypeName.BYTE) || type.equals(TypeName.BYTE.box())) {
    builder.addStatement("$N = (byte) $N.getInt($N)", field, json, key);
  } else if (type.equals(TypeName.CHAR) || type.equals(TypeName.CHAR.box())) {
    FieldSpec tempVal =
        FieldSpec.builder(String.class, nameAllocator.newName("tempVal"), Modifier.FINAL).build();
    builder.addStatement("$T $N = $N.getString($N)", tempVal.type, tempVal, json, key);
    builder.beginControlFlow("if(!$N.isEmpty())", tempVal);
    builder.addStatement("$N = $N.charAt(0)", field, tempVal);
    builder.endControlFlow();
  } else if (type.equals(ENUM)) {
    builder.addStatement("$N = $T.valueOf($N.getString($N))", field, field.type, json, key);
  } else {
    throw new IllegalStateException(String.format("supportedType [%s] with not method.", type));
  }

  return builder.build();
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:38,代碼來源:JsonGeneratorUtils.java

示例7: processTypes

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
void processTypes(ElementDescription elem, MethodSpec.Builder intent, MethodSpec.Builder fill) {
    String left = "smart." + elem.fieldName;
    String right = left + ")";

    String key = elem.key;
    TypeName fieldType = elem.fieldType;
    String set = elem.setterCode();
    String get = elem.getterCode();

    if(Util.textNotNull(set) && Util.textNotNull(get)) {
        set = String.format(set, "\"" + elem.key + "\"", left);
        get = String.format(get, "\"" + elem.key + "\"");
        intent.addStatement("in." + set);
        fill.addStatement(left + " = $T.convert(source." + get + ")", ClazzNames.INTENT_VALUE_GETTER);
    } else if(fieldType.equals(ClazzNames.PARCELABLE_ARRAYLIST)) {
        intent.addStatement("in.putParcelableArrayListExtra(\"" + key +"\", " + right);
        fill.addStatement(left + " = source.getParcelableArrayListExtra(\"" + key + "\")");
    } else if(fieldType.equals(ClazzNames.INTEGER_ARRAYLIST)) {
        intent.addStatement("in.putIntegerArrayListExtra(\"" + key + "\", " + right);
        fill.addStatement(left + " = source.getIntegerArrayListExtra(\"" + key + "\")");
    } else if(fieldType.equals(ClazzNames.STRING_ARRAYLIST)) {
        intent.addStatement("in.putStringArrayListExtra(\"" + key + "\", " + right);
        fill.addStatement(left + " = source.getStringArrayListExtra(\"" + key + "\")");
    } else if(fieldType.equals(ClazzNames.CHARSEQUENCE_ARRAYLIST)) {
        intent.addStatement("in.putCharSequenceArrayListExtra(\"" + key + "\", " + right);
        fill.addStatement(left + " = source.getCharSequenceArrayListExtra(\"" + key + "\")");
    } else {
        intent.addStatement("in.putExtra(\"" + key + "\", " + right);
        processNonSetTypes(elem, fill);
    }
}
 
開發者ID:foreveruseful,項目名稱:smartkey,代碼行數:32,代碼來源:IntentGenerator.java

示例8: processNonSetTypes

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
void processNonSetTypes(ElementDescription elem, MethodSpec.Builder fill) {
    TypeName fieldType = elem.fieldType;
    String key = elem.key;
    String left = "smart." + elem.fieldName;
    if(Util.isWrapper(fieldType)) { // 包裝類型需要使用Serializable才能保持null值的正確傳遞
        fill.addStatement(left + " = (" + elem.fieldType + ") source.getSerializableExtra(\"" + key + "\")");
    } else if(fieldType.equals(TypeName.BOOLEAN)) {
        fill.addStatement(left + " = source.getBooleanExtra(\"" + key + "\", false)");
    } else if(fieldType.equals(TypeName.BYTE)) {
        fill.addStatement(left + " = source.getByteExtra(\"" + key + "\", (byte) 0)");
    } else if(fieldType.equals(TypeName.CHAR)) {
        fill.addStatement(left + " = source.getCharExtra(\"" + key + "\", '\\0')");
    } else if(fieldType.equals(TypeName.SHORT)) {
        fill.addStatement(left + " = source.getShortExtra(\"" + key + "\", (short) 0)");
    } else if(fieldType.equals(TypeName.INT)) {
        fill.addStatement(left + " = source.getIntExtra(\"" + key + "\", 0)");
    } else if(fieldType.equals(TypeName.LONG)) {
        fill.addStatement(left + " = source.getLongExtra(\"" + key + "\", 0)");
    } else if(fieldType.equals(TypeName.FLOAT)) {
        fill.addStatement(left + " = source.getFloatExtra(\"" + key + "\", 0.0f)");
    } else if(fieldType.equals(TypeName.DOUBLE)) {
        fill.addStatement(left + " = source.getDoubleExtra(\"" + key + "\", 0.0)");
    } else if(fieldType.equals(ClazzNames.STRING)) {
        fill.addStatement(left + " = source.getStringExtra(\"" + key + "\")");
    } else if(fieldType.equals(ClazzNames.CHARSEQUENCE)) {
        fill.addStatement(left + " = source.getCharSequenceExtra(\"" + key + "\")");
    } else {
        String tn = fieldType.toString();
        if(tn.indexOf('<') >= 0) {
            tn = tn.substring(0, tn.indexOf('<'));
        }
        fill.addStatement(left + " = ($T) $T.getValue(source, \"" + key + "\", " + tn + ".class)", fieldType, ClazzNames.INTENT_VALUE_GETTER);
    }
}
 
開發者ID:foreveruseful,項目名稱:smartkey,代碼行數:35,代碼來源:IntentGenerator.java

示例9: getQueryCast

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
public static String getQueryCast(VariableElement variableElement) {
    TypeName typeName = getFieldClass(variableElement);
    if (ClassName.get(String.class).equals(typeName)) {
        return "$L";
    } else if (typeName == TypeName.BOOLEAN || typeName.equals(TypeName.get(Boolean.class))) {
        return "String.valueOf($L ? 1 : 0)";
    } else {
        return "String.valueOf($L)";
    }
}
 
開發者ID:florent37,項目名稱:RxAndroidOrm,代碼行數:11,代碼來源:ProcessUtils.java

示例10: parseClass

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private ClassInfo parseClass(ClassName className, TypeElement typeElement) {
  TypeName targetType = getTargetType(typeElement.asType());
  TypeName viewType = targetType.equals(SHADOW_NODE_TYPE) ? null : targetType;

  ClassInfo classInfo = new ClassInfo(className, typeElement, viewType);
  findProperties(classInfo, typeElement);

  return classInfo;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:10,代碼來源:ReactPropertyProcessor.java

示例11: build

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
public PropertyInfo build(Element element, Property property)
    throws ReactPropertyException {
  String methodName = element.getSimpleName().toString();

  ExecutableElement method = (ExecutableElement) element;
  List<? extends VariableElement> parameters = method.getParameters();

  if (parameters.size() != getArgCount(mClassInfo.getType(), property)) {
    throw new ReactPropertyException("Wrong number of args", element);
  }

  int index = 0;
  if (mClassInfo.getType() == SettableType.VIEW_MANAGER) {
    TypeMirror mirror = parameters.get(index++).asType();
    if (!mTypes.isSubtype(mirror, mElements.getTypeElement("android.view.View").asType())) {
      throw new ReactPropertyException("First argument must be a subclass of View", element);
    }
  }

  if (property instanceof GroupProperty) {
    TypeName indexType = TypeName.get(parameters.get(index++).asType());
    if (!indexType.equals(TypeName.INT)) {
      throw new ReactPropertyException(
          "Argument " + index + " must be an int for @ReactPropGroup",
          element);
    }
  }

  TypeName propertyType = TypeName.get(parameters.get(index++).asType());
  if (!DEFAULT_TYPES.containsKey(propertyType)) {
    throw new ReactPropertyException(
        "Argument " + index + " must be of a supported type",
        element);
  }

  return new PropertyInfo(methodName, propertyType, element, property);
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:38,代碼來源:ReactPropertyProcessor.java

示例12: checkIfTypeIsSupported

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private void checkIfTypeIsSupported(VariableElement variableElement) {
    final TypeName typeOfCurrentElement = ClassName.get(variableElement.asType());
    if (!typeOfCurrentElement.equals(ClassName.get(String.class)) &&
            !typeOfCurrentElement.equals(BYTE_ARRAY_TYPE) &&
            !typeOfCurrentElement.isPrimitive() &&
            !typeOfCurrentElement.isBoxedPrimitive()) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    } else if ((typeOfCurrentElement.isPrimitive() || typeOfCurrentElement.isBoxedPrimitive())
            && (typeOfCurrentElement.unbox().equals(TypeName.BYTE) || typeOfCurrentElement.unbox().equals(TypeName.CHAR))) {

        throwError("SlimOrm: Type " + typeOfCurrentElement + " is not supported");
    }
}
 
開發者ID:Neristance,項目名稱:slimorm,代碼行數:15,代碼來源:SlimOrmProcessor.java

示例13: writeValue

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
public static CodeBlock writeValue(Types types, JsonProperty property, FieldSpec json) {
  //TODO If write method declares JSONException then don't wrap all puts.
  //TODO Handle collections.
  TypeName type = getTypeNameFromProperty(property, types);
  CodeBlock.Builder builder = CodeBlock.builder();

  if (type.equals(STRING)) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.INT) || type.equals(TypeName.INT.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.DOUBLE) || type.equals(TypeName.DOUBLE.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.FLOAT) || type.equals(TypeName.FLOAT.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.BOOLEAN) || type.equals(TypeName.BOOLEAN.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.LONG) || type.equals(TypeName.LONG.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.SHORT) || type.equals(TypeName.SHORT.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.BYTE) || type.equals(TypeName.BYTE.box())) {
    builder.addStatement("$N.put($S, $N())", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(TypeName.CHAR) || type.equals(TypeName.CHAR.box())) {
    builder.addStatement("$N.put($S, String.valueOf($N()))", json, property.serializedName(),
        property.methodName);
  } else if (type.equals(ENUM)) {
    builder.addStatement("$N.put($S, $N().name())", json, property.serializedName(),
        property.methodName);
  } else {
    throw new IllegalStateException(String.format("supportedType [%s] with no method.", type));
  }

  return builder.build();
}
 
開發者ID:setheclark,項目名稱:auto-value-json,代碼行數:43,代碼來源:JsonGeneratorUtils.java

示例14: applicable

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
private boolean applicable(TypeElement type) {
  // check that the class contains a public static method returning a Validator
  TypeName typeName = TypeName.get(type.asType());
  ParameterizedTypeName validatorType =
      ParameterizedTypeName.get(ClassName.get(Validator.class), typeName);
  TypeName returnedValidator = null;
  for (ExecutableElement method : ElementFilter.methodsIn(type.getEnclosedElements())) {
    if (method.getModifiers()
        .contains(STATIC) && !method.getModifiers()
        .contains(PRIVATE)) {
      TypeMirror rType = method.getReturnType();
      TypeName returnType = TypeName.get(rType);
      if (returnType.equals(validatorType)) {
        return true;
      }

      if (returnType.equals(validatorType.rawType) || (returnType instanceof ParameterizedTypeName
          && ((ParameterizedTypeName) returnType).rawType.equals(validatorType.rawType))) {
        returnedValidator = returnType;
      }
    }
  }

  if (returnedValidator == null) {
    return false;
  }

  // emit a warning if the user added a method returning a Validator, but not of the right type
  if (returnedValidator instanceof ParameterizedTypeName) {
    ParameterizedTypeName paramReturnType = (ParameterizedTypeName) returnedValidator;
    TypeName argument = paramReturnType.typeArguments.get(0);

    // If the original type uses generics, user's don't have to nest the generic type args
    if (typeName instanceof ParameterizedTypeName) {
      ParameterizedTypeName pTypeName = (ParameterizedTypeName) typeName;
      if (pTypeName.rawType.equals(argument)) {
        return true;
      }
    } else {
      messager.printMessage(Diagnostic.Kind.WARNING,
          String.format("Found public static method returning Validator<%s> on %s class. "
              + "Skipping InspectorValidator generation.", argument, type));
    }
  } else {
    messager.printMessage(Diagnostic.Kind.WARNING,
        "Found public static method returning "
            + "Validator with no type arguments, skipping Validator generation.");
  }

  return false;
}
 
開發者ID:hzsweers,項目名稱:inspector,代碼行數:52,代碼來源:InspectorProcessor.java

示例15: isTypeRequiresSuppressWarnings

import com.squareup.javapoet.TypeName; //導入方法依賴的package包/類
static boolean isTypeRequiresSuppressWarnings(TypeName type) {
    return type.equals(LIST) ||
            type.equals(MAP);
}
 
開發者ID:foodora,項目名稱:android-auto-mapper,代碼行數:5,代碼來源:Parcelables.java


注:本文中的com.squareup.javapoet.TypeName.equals方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。