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


Java SimpleTypeVisitor6类代码示例

本文整理汇总了Java中javax.lang.model.util.SimpleTypeVisitor6的典型用法代码示例。如果您正苦于以下问题:Java SimpleTypeVisitor6类的具体用法?Java SimpleTypeVisitor6怎么用?Java SimpleTypeVisitor6使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getTypeArgument

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
@Nullable
private TypeMirror getTypeArgument(TypeMirror annotatedType, final TypeElement baseType) {
  for (TypeMirror type : getAllTypes(annotatedType)) {
    TypeMirror typeArgument = type.accept(new SimpleTypeVisitor6<TypeMirror, Void>() {
      @Override public TypeMirror visitDeclared(DeclaredType t, Void aVoid) {
        if (isAssignable(t, baseType)) {
          List<? extends TypeMirror> typeArguments = t.getTypeArguments();
          if (!typeArguments.isEmpty()) {
            return typeUtils.erasure(typeArguments.get(0));
          }
        }
        return null;
      }
    }, null);

    if (typeArgument != null) {
      return typeArgument;
    }
  }
  error("Failed to find a type argument for %s in %s", baseType, annotatedType);
  return null;
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:23,代码来源:CmdLineProcessor.java

示例2: asDeclaredType

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
private static DeclaredType asDeclaredType(TypeMirror type) {
    return type.accept(new SimpleTypeVisitor6<DeclaredType, Object>() {
        @Override
        public DeclaredType visitDeclared(DeclaredType t, Object o) {
            return t;
        }
    }, null);
}
 
开发者ID:evant,项目名称:gsonvalue,代码行数:9,代码来源:GsonValueProcessor.java

示例3: isValidMap

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
/**
 * Maps can only have String keys and Parcelable values.
 */
private static boolean isValidMap(Types types, TypeMirror type) {
  return type.accept(new SimpleTypeVisitor6<Boolean, Types>() {
    @Override public Boolean visitDeclared(DeclaredType t, Types o) {
      List<? extends TypeMirror> args = t.getTypeArguments();
      if (args.size() == 2) {
        TypeMirror key = args.get(0);
        TypeMirror value = args.get(1);
        if (STRING.equals(TypeName.get(key)) && isValidType(o, value)) {
          return true;
        }
      }
      return false;
    }
  }, types);
}
 
开发者ID:rharter,项目名称:auto-value-parcel,代码行数:19,代码来源:Parcelables.java

示例4: getGenericType

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
/**
 * Return the generic type if any
 */
public TypeElement getGenericType(TypeMirror typeMirror) {
    return typeMirror.accept(new SimpleTypeVisitor6<TypeElement, Void>() {
        @Override
        public TypeElement visitDeclared(DeclaredType declaredType, Void v) {
            TypeElement genericTypeElement = null;
            TypeElement typeElement = (TypeElement) declaredType.asElement();
            if (parcelClass != null && typeUtils.isAssignable(typeElement.asType(), listTypeMirror)) {
                List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
                if (!typeArguments.isEmpty()) {
                    for (TypeMirror genericType : typeArguments) {
                        if (genericType instanceof WildcardType) {
                            WildcardType wildcardType = (WildcardType) genericType;
                            TypeMirror extendsType = wildcardType.getExtendsBound();
                            if (extendsType != null) {
                                typeElement = elementUtils.getTypeElement(extendsType.toString());
                                if (typeElement.getAnnotation(parcelClass) != null) {
                                    genericTypeElement = typeElement;
                                    break;
                                }

                            }
                        } else {
                            typeElement = elementUtils.getTypeElement(genericType.toString());
                            if (typeElement.getAnnotation(parcelClass) != null) {
                                genericTypeElement = typeElement;
                                break;
                            }
                        }
                    }
                }
            }
            return genericTypeElement;
        }
    }, null);
}
 
开发者ID:josesamuel,项目名称:remoter,代码行数:39,代码来源:BindingManager.java

示例5: extractGetIfList

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
String extractGetIfList(TypeMirror typeMirror) {
    String name = typeMirror.toString();
    if (name.startsWith("java.util.List")) {
        //check type
        DeclaredType declaredType = typeMirror.accept(new SimpleTypeVisitor6<DeclaredType, String>() {
            @Override
            public DeclaredType visitDeclared(DeclaredType t, String s) {
                return t;
            }
        }, name);
        if (declaredType == null) {
            return null;
        }
        List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
        if (typeArguments.isEmpty()) {
            return null;
        }
        TypeMirror typeParameter = typeArguments.get(0);
        switch (MirrorUtils.flattenArrayListType(environment, typeParameter)) {
            case "java.lang.Integer":
                return "args.getIntegerArrayList($S)";
            case "java.lang.String":
                return "args.getStringArrayList($S)";
            case "java.lang.CharSequence":
                return "args.getCharSequenceArrayList($S)";
            case "android.os.Parcelable":
                return "args.getParcelableArrayList($S)";
        }
    }
    return null;
}
 
开发者ID:sys1yagi,项目名称:fragment-creator,代码行数:32,代码来源:FragmentCreatorReadGenerator.java

示例6: extractPutIfList

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
String extractPutIfList(TypeMirror typeMirror) {
    String name = typeMirror.toString();
    if (name.startsWith("java.util.List")) {
        //check type
        DeclaredType declaredType = typeMirror.accept(new SimpleTypeVisitor6<DeclaredType, String>() {
            @Override
            public DeclaredType visitDeclared(DeclaredType t, String s) {
                return t;
            }
        }, name);
        if (declaredType == null) {
            return null;
        }
        List<? extends TypeMirror> typeArguments = declaredType.getTypeArguments();
        if (typeArguments.isEmpty()) {
            return null;
        }
        TypeMirror typeParameter = typeArguments.get(0);
        switch (MirrorUtils.flattenArrayListType(environment, typeParameter)) {
            case "java.lang.Integer":
                return "args.putIntegerArrayList($S,";
            case "java.lang.String":
                return "args.putStringArrayList($S,";
            case "java.lang.CharSequence":
                return "args.putCharSequenceArrayList($S,";
            case "android.os.Parcelable":
                return "args.putParcelableArrayList($S,";
        }
    }
    return null;
}
 
开发者ID:sys1yagi,项目名称:fragment-creator,代码行数:32,代码来源:FragmentCreatorBuilderGenerator.java

示例7: TypeMirrorToDAInterfaceWithGeneric

import javax.lang.model.util.SimpleTypeVisitor6; //导入依赖的package包/类
public TypeMirrorToDAInterfaceWithGeneric(final JavaxExtractor javaxExtractor, final GenericTypeContext genericTypeContext) {
  this.daInterfaceExtractor = new SimpleTypeVisitor6<DAInterface, Void>() {

    @Override
    public DAInterface visitDeclared(DeclaredType declaredType, Void aVoid) {
      return new DAInterfaceImpl(javaxExtractor.extractType(declaredType, genericTypeContext));
    }
  };
}
 
开发者ID:lesaint,项目名称:damapping,代码行数:10,代码来源:JavaxParsingServiceImpl.java


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