本文整理汇总了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;
}
示例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;
}
示例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;
}
}
示例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();
}
示例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));
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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)";
}
}
示例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;
}
示例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);
}
示例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");
}
}
示例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();
}
示例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;
}
示例15: isTypeRequiresSuppressWarnings
import com.squareup.javapoet.TypeName; //导入方法依赖的package包/类
static boolean isTypeRequiresSuppressWarnings(TypeName type) {
return type.equals(LIST) ||
type.equals(MAP);
}