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


Java MoreTypes.isTypeOf方法代码示例

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


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

示例1: createUnmodifiableStatement

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
@Nonnull
public static CodeBlock createUnmodifiableStatement(@Nonnull TypeMirror type, @Nonnull String variable) {
    if (type.getKind() == TypeKind.ARRAY) {
        return CodeBlock.of("$T.copyOf($N, $N.length)", Arrays.class, variable, variable);
    }

    if (MoreTypes.isTypeOf(List.class, type)) {
        return CodeBlock.of("new $T<>($N)", ArrayList.class, variable);
    }

    if (MoreTypes.isTypeOf(Set.class, type)) {
        return CodeBlock.of("new $T<>($N)", HashSet.class, variable);
    }

    if (MoreTypes.isTypeOf(Map.class, type)) {
        return CodeBlock.of("new $T<>($N)", HashMap.class, variable);
    }
    return CodeBlock.of("$N", variable);
}
 
开发者ID:t28hub,项目名称:shade,代码行数:20,代码来源:CodeBlocks.java

示例2: getReducerSuperInterface

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public static DeclaredType getReducerSuperInterface(DeclaredType reducerType) {
    List<? extends TypeMirror> supertypes = MoreTypes.asTypeElement(reducerType).getInterfaces();

    for (TypeMirror supertype : supertypes) {
        boolean isReducer = MoreTypes.isTypeOf(Reducer.class, supertype);
        if (isReducer) {
            return MoreTypes.asDeclared(supertype);
        }
    }

    TypeMirror superclass = MoreTypes.asTypeElement(reducerType).getSuperclass();
    if (!MoreTypes.isTypeOf(Object.class, superclass)) {
        return getReducerSuperInterface(MoreTypes.asDeclared(superclass));
    }

    return null;
}
 
开发者ID:Yarikx,项目名称:reductor,代码行数:18,代码来源:Utils.java

示例3: findWriteToParcel

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
@Nullable private ExecutableElement findWriteToParcel(TypeElement subject) {
  TypeMirror parcel = elements.getTypeElement("android.os.Parcel").asType();
  @SuppressWarnings("deprecation") // Support for kapt2
  ImmutableSet<ExecutableElement> methods =
      MoreElements.getLocalAndInheritedMethods(subject, elements);
  for (ExecutableElement element : methods) {
    if (element.getSimpleName().contentEquals("writeToParcel")
        && MoreTypes.isTypeOf(void.class, element.getReturnType())
        && !element.getModifiers().contains(Modifier.ABSTRACT)) {
      List<? extends VariableElement> parameters = element.getParameters();
      if (parameters.size() == 2
          && types.isSameType(parcel, parameters.get(0).asType())
          && MoreTypes.isTypeOf(int.class, parameters.get(1).asType())) {
        return element;
      }
    }
  }
  return null;
}
 
开发者ID:grandstaish,项目名称:paperparcel,代码行数:20,代码来源:PaperParcelAutoValueExtensionValidator.java

示例4: needsContentDescriptor

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
private static boolean needsContentDescriptor(Context context) {
  ProcessingEnvironment env = context.processingEnvironment();
  TypeElement autoValueTypeElement = context.autoValueClass();
  Elements elements = env.getElementUtils();
  @SuppressWarnings("deprecation") // Support for kapt2
  ImmutableSet<ExecutableElement> methods =
      MoreElements.getLocalAndInheritedMethods(autoValueTypeElement, elements);
  for (ExecutableElement element : methods) {
    if (element.getSimpleName().contentEquals("describeContents")
        && MoreTypes.isTypeOf(int.class, element.getReturnType())
        && element.getParameters().isEmpty()
        && !element.getModifiers().contains(ABSTRACT)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:grandstaish,项目名称:paperparcel,代码行数:18,代码来源:PaperParcelAutoValueExtension.java

示例5: findWriteToParcel

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
private static ExecutableElement findWriteToParcel(Context context) {
  ProcessingEnvironment env = context.processingEnvironment();
  TypeMirror parcel = env.getElementUtils().getTypeElement("android.os.Parcel").asType();
  for (ExecutableElement element : MoreElements.getLocalAndInheritedMethods(
      context.autoValueClass(), env.getElementUtils())) {
    if (element.getSimpleName().contentEquals("writeToParcel")
        && MoreTypes.isTypeOf(void.class, element.getReturnType())
        && !element.getModifiers().contains(ABSTRACT)) {
      List<? extends VariableElement> parameters = element.getParameters();
      if (parameters.size() == 2
          && env.getTypeUtils().isSameType(parcel, parameters.get(0).asType())
          && MoreTypes.isTypeOf(int.class, parameters.get(1).asType())) {
        return element;
      }
    }
  }
  return null;
}
 
开发者ID:rharter,项目名称:auto-value-parcel,代码行数:19,代码来源:AutoValueParcelExtension.java

示例6: valueCodeBlock

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public static CodeBlock valueCodeBlock(ProcessingEnvironment env, TypeMirror t, Object value) {
    // try unbox so primitive types are handle by kind
    try { t = env.getTypeUtils().unboxedType(t); } catch (Exception ignore) {}

    CodeBlock.Builder block = CodeBlock.builder();
    switch (t.getKind()) {
        case BOOLEAN:
        case BYTE:
        case SHORT:
        case INT:
        case LONG:
        case FLOAT:
        case DOUBLE:
            block.add("$L", value);
            break;
        case CHAR:
            block.add("'$L'", value);
            break;
        case DECLARED:
            if (MoreTypes.isTypeOf(String.class, t)) {
                block.add("$S", value);
            } else if (isEnum(t)) {
                block.add("$T.$L", t, value);
            } else if (env.getTypeUtils().isSubtype(t, typeElementFor(env, Number.class).asType())) {
                block.add("$L", value);
            } else if (MoreTypes.isTypeOf(Class.class, t)) {
                block.add("$T.class", value);
            } else {
                block.add("$T.valueOf($S)", t, value);
            }
            break;
        default:
            throw new IllegalArgumentException("illegal property type " + t);
    }
    return block.build();
}
 
开发者ID:intendia-oss,项目名称:qualifier,代码行数:37,代码来源:StaticQualifierMetamodelProcessor.java

示例7: getGetFromObjCodeWithType

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public CodeBlock getGetFromObjCodeWithType( CodeBlock cbInner ) {
    CodeBlock.Builder cb = CodeBlock.builder();

    String temp;
    if(MoreTypes.isTypeOf(boolean.class, getType()) || MoreTypes.isTypeOf(Boolean.class, getType())){
        temp ="java.lang.String.valueOf(";
        cb.add(temp +cbInner+")");
    }else if(MoreTypes.isTypeOf(Date.class, getType()) ){
        temp = ".getTime()";
        cb.add(cbInner+temp);
    }else if(MoreTypes.isTypeOf(Calendar.class, getType()) ){
        temp = ".getTimeInMillis()";
        cb.add(cbInner+temp);
    }else if(getType().getKind() == TypeKind.DECLARED){
        TypeMirror superType = ((TypeElement)((DeclaredType)getType()).asElement()).getSuperclass();
        if(MoreTypes.isTypeOf(Enum.class,superType)) {
            temp = ".ordinal()";
            cb.add(cbInner+temp);
        }else{
            return cbInner;
        }
    }else{
        return cbInner;
    }

    return cb.build();
}
 
开发者ID:joker535,项目名称:sorm,代码行数:28,代码来源:ColumnInfo.java

示例8: needsContentDescriptor

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
private static boolean needsContentDescriptor(Context context) {
  ProcessingEnvironment env = context.processingEnvironment();
  for (ExecutableElement element : MoreElements.getLocalAndInheritedMethods(
      context.autoValueClass(), env.getElementUtils())) {
    if (element.getSimpleName().contentEquals("describeContents")
        && MoreTypes.isTypeOf(int.class, element.getReturnType())
        && element.getParameters().isEmpty()
        && !element.getModifiers().contains(ABSTRACT)) {
      return false;
    }
  }
  return true;
}
 
开发者ID:rharter,项目名称:auto-value-parcel,代码行数:14,代码来源:AutoValueParcelExtension.java

示例9: StoreMethodModel

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public StoreMethodModel(ExecutableElement element, StoreModel storeModel) {
    this.element = element;
    this.storeModel = storeModel;

    List<TypeName> states = FluentIterable.from(storeModel.getStoreImplModels())
            .transform(new Function<StoreImplModel, TypeName>() {
                @Override
                public TypeName apply(StoreImplModel input) {
                    return input.getState();
                }
            }).toList();

    returnType = MoreTypes.asDeclared(element.getReturnType());

    if (states.contains(ClassName.get(returnType))) {
        kind = Kind.GETTER;
        isBindable = element.getAnnotation(Bindable.class) != null;
    } else if (getName().equals(DispatcherModel.DISPATCH_METHOD_NAME)) {
        kind = Kind.DISPATCH;
    } else if (MoreTypes.isTypeOf(OBSERVE_METHOD_CLASS, returnType.asElement().asType())
            && states.contains(ClassName.get(returnType.getTypeArguments().get(0)))) {
        if (element.getParameters() != null
                && !element.getParameters().isEmpty()
                && MoreTypes.isTypeOf(BACKPRESSURE_STRATEGY_PARAM_CLASS, element.getParameters().get(0).asType())) {
            bpsParamName = element.getParameters().get(0).getSimpleName().toString();
            kind = Kind.OBSERVE_WITH_BPS;
        } else {
            kind = Kind.OBSERVE;
        }
    } else {
        kind = Kind.UNKNOWN;
    }
}
 
开发者ID:izumin5210,项目名称:Droidux,代码行数:34,代码来源:StoreMethodModel.java

示例10: isEnum

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
private static boolean isEnum(TypeMirror type) {
    return MoreTypes.isTypeOf(Enum.class, MoreElements.asType(MoreTypes.asElement(type)).getSuperclass());
}
 
开发者ID:intendia-oss,项目名称:qualifier,代码行数:4,代码来源:StaticQualifierMetamodelProcessor.java

示例11: isValidFieldType

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
private boolean isValidFieldType(TypeMirror fieldType) {
    switch (fieldType.getKind()) {
        // These primitive types are valid immediately.
        case BOOLEAN:
        case DOUBLE:
        case FLOAT:
        case INT:
        case LONG:
        case SHORT:
            return true;
        // For declared, we need to do a bit of extra work.
        case DECLARED:
            try {
                // If it's a boxed primitive, other than byte or char, return true.
                TypeName typeName = TypeName.get(fieldType).unbox();
                if (typeName.equals(TypeName.BYTE) || typeName.equals(TypeName.CHAR)) return false;
                if (typeName.isPrimitive()) return true;
            } catch (UnsupportedOperationException e) {
                // Do nothing, we just did this to try and check if this was a boxed primitive.
            }

            // Strings and java.util.Dates are okay.
            DeclaredType declaredType = MoreTypes.asDeclared(fieldType);
            if (MoreTypes.isTypeOf(String.class, declaredType) || MoreTypes.isTypeOf(Date.class, declaredType))
                return true;

            // Any of our classes annotated with @RealmClass are okay.
            if (Utils.isSubtypeOfType(fieldType, TypeNames.REALM_MODEL.toString())) return true;

            // RealmLists are okay as well.
            TypeName fieldTypeName = TypeName.get(fieldType);
            if (isRealmList(fieldTypeName)) return true;

            // Everything else is bad.
            return false;
        // We ignore these types.
        case ARRAY:
        case BYTE:
        case CHAR:
        case ERROR:
        case EXECUTABLE:
        case NONE:
        case NULL:
        case OTHER:
        case PACKAGE:
        case TYPEVAR:
        case UNION:
        case VOID:
        case WILDCARD:
        default:
            return false;
    }
}
 
开发者ID:bkromhout,项目名称:Ruqus,代码行数:54,代码来源:ClassDataBuilder.java

示例12: forComponentMethod

import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
static Optional<ComponentMethodDescriptor> forComponentMethod(Types types, DeclaredType componentElement, ExecutableElement componentMethod) {
  // Using same algorithm as Dagger's ComponentDescriptor#getDescriptorForComponentMethod
  ExecutableType resolvedComponentMethod = MoreTypes.asExecutable(types.asMemberOf(componentElement, componentMethod));
  TypeMirror returnType = resolvedComponentMethod.getReturnType();
  if (returnType.getKind() == TypeKind.DECLARED) {
    if (MoreTypes.isTypeOf(Provider.class, returnType)
        || MoreTypes.isTypeOf(Lazy.class, returnType)) {
      return methodDescriptor(
          ComponentMethodKind.PROVIDER_OR_LAZY,
          MoreTypes.asDeclared(MoreTypes.asDeclared(returnType).getTypeArguments().get(0)),
          componentMethod);
    } else if (MoreTypes.isTypeOf(MembersInjector.class, returnType)) {
      return methodDescriptor(
          ComponentMethodKind.MEMBERS_INJECTOR,
          MoreTypes.asDeclared(MoreTypes.asDeclared(returnType).getTypeArguments().get(0)),
          componentMethod);
    } else if (MoreElements.getAnnotationMirror(types.asElement(returnType), Subcomponent.class).isPresent()) {
      // Ignore subcomponent methods
      return Optional.absent();
    }
  }

  if (resolvedComponentMethod.getParameterTypes().isEmpty()
      && resolvedComponentMethod.getReturnType().getKind() == TypeKind.DECLARED) {
    return methodDescriptor(
        ComponentMethodKind.SIMPLE_PROVISION,
        MoreTypes.asDeclared(returnType),
        componentMethod);
  }

  List<? extends TypeMirror> parameterTypes = resolvedComponentMethod.getParameterTypes();
  if (parameterTypes.size() == 1
      && parameterTypes.get(0).getKind() == TypeKind.DECLARED
      && (returnType.getKind().equals(TypeKind.VOID)
          || types.isSameType(returnType, parameterTypes.get(0)))) {
    return methodDescriptor(
        ComponentMethodKind.SIMPLE_MEMBERS_INJECTION,
        MoreTypes.asDeclared(parameterTypes.get(0)),
        componentMethod);
  }

  // Let Dagger do the validation
  return Optional.absent();
}
 
开发者ID:tbroyer,项目名称:bullet,代码行数:45,代码来源:ComponentMethodDescriptor.java


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