本文整理汇总了Java中com.google.auto.common.MoreTypes类的典型用法代码示例。如果您正苦于以下问题:Java MoreTypes类的具体用法?Java MoreTypes怎么用?Java MoreTypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MoreTypes类属于com.google.auto.common包,在下文中一共展示了MoreTypes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例2: validateActionCreator
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private static void validateActionCreator(ExecutableElement element,
String actionName,
TypeMirror actionCreator,
ArrayList<VariableElement> args,
Map<String, ActionCreatorElement> knownActionCreators,
Env env) throws ValidationException {
Element actionCreatorElement = MoreTypes.asElement(actionCreator);
if (!MoreElements.isAnnotationPresent(actionCreatorElement, ActionCreator.class)) {
throw new ValidationException(element, "Action creator %s should be annotated with @%s", actionCreator, ActionCreator.class.getSimpleName());
}
ActionCreatorElement creatorElement = knownActionCreators.get(env.getElements().getBinaryName((TypeElement) actionCreatorElement).toString());
if (creatorElement == null) {
throw new ElementNotReadyException();
}
if (!creatorElement.hasAction(actionName, args)) {
throw new ValidationException(element, "Cannot find action creator for action \"%s\" and args %s in interface %s", actionName, toString(args), creatorElement.getName(env));
}
}
示例3: 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;
}
示例4: 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;
}
示例5: 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;
}
示例6: initTokenizerGetters
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private void initTokenizerGetters() {
if (this.factoryType != null) {
for (ExecutableElement method :
ElementFilter.methodsIn(elements.getAllMembers((TypeElement) factoryType.asElement()))) {
if (!method.getParameters().isEmpty()) {
continue;
}
if (!method.getModifiers().contains(Modifier.PUBLIC)) {
// TODO: support non-public but callable/visible methods (package-private or protected,
// when in same package)
continue;
}
ExecutableType methodType = (ExecutableType) types.asMemberOf(factoryType, method);
TypeMirror returnType = methodType.getReturnType();
if (!types.isSubtype(returnType, types.getDeclaredType(placeTokenizerType))) {
continue;
}
addPlaceTokenizer(
method,
getPrefixForTokenizerGetter(method, methodType),
MoreTypes.asDeclared(returnType));
}
}
}
示例7: 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;
}
示例8: parse
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private void parse() throws Throwable {
List<Element> allElements = new ArrayList<>();
allElements.add(mSourceClassEle);
Element currentClass = mSourceClassEle;
do {
Optional<DeclaredType> superClass = MoreTypes.nonObjectSuperclass(GlobalEnvironment.getProcessingEnv().getTypeUtils(),
GlobalEnvironment.getProcessingEnv().getElementUtils(), (DeclaredType) currentClass.asType());
if (superClass.isPresent()) {
currentClass = superClass.get().asElement();
allElements.add(currentClass);
LogUtil.logger("superclass.get().asElement().toString(): " + currentClass.toString());
} else {
currentClass = null;
}
} while (null != currentClass);
for (int i = allElements.size() - 1; i >= 0; i--) {
buildAllColumns(allElements.get(i));
}
}
示例9: 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();
}
示例10: typeAnnotationTargets
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static ImmutableSet<TypeElement> typeAnnotationTargets(final Descriptor descriptor, final TypeElement element) {
final AnnotationMirror descriptorMirror = descriptorMirror(descriptor, element);
final AnnotationValue classes = AnnotationMirrors.getAnnotationValue(descriptorMirror, "copyTypeAnnotationsTo");
final ImmutableSet.Builder<TypeElement> builder = ImmutableSet.builder();
for (final AnnotationValue value: (List<? extends AnnotationValue>)classes) {
final DeclaredType declared = MoreTypes.asDeclared((TypeMirror)value);
builder.add(MoreElements.asType(declared.asElement()));
}
return builder.build();
}
示例11: getBeanType
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private TypeMirror getBeanType(Element element) {
if(useInterface(element)){
TypeMirror objectReader = ((TypeElement) typeUtils.asElement(element.asType())).getInterfaces().get(0);
return MoreTypes.asDeclared(objectReader).getTypeArguments().get(0);
}else{
return element.asType();
}
}
示例12: getEnclosedElements
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private List<Element> getEnclosedElements() {
List<Element> elements = new ArrayList<>(type.getEnclosedElements());
for (Element element : MoreTypes.asTypeElements(type.getInterfaces())) {
elements.addAll(element.getEnclosedElements());
}
return elements;
}
示例13: createSetObjectMethod
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private static MethodSpec.Builder createSetObjectMethod( TypeName typeName, String objName,
EntityInfo entityInfo ) {
MethodSpec.Builder methodSetObject = MethodSpec.methodBuilder("createRecord")
.returns(TypeName.get(ContentValues.class))
.addParameter(typeName, objName, Modifier.FINAL)
.addParameter(String.class, "regex", Modifier.FINAL).addModifiers(Modifier.PUBLIC);
methodSetObject
.addStatement("android.content.ContentValues contentValues = new android.content.ContentValues()");
for (ColumnInfo c : entityInfo.getColumnInfos()) {
try {
MoreTypes.asPrimitiveType(c.getType());
methodSetObject.beginControlFlow(
"if(android.text.TextUtils.isEmpty(regex) || $S.matches(regex))",
c.getName());
methodSetObject.addCode(c.getContentValuesGetCode("contentValues", objName));
methodSetObject.endControlFlow();
} catch (IllegalArgumentException e) {
methodSetObject
.beginControlFlow(
"if("
+ c.getGetFromObjectCode(objName).toString()
+ " != null && (android.text.TextUtils.isEmpty(regex) || $S.matches(regex)))",
c.getName());
methodSetObject.addCode(c.getContentValuesGetCode("contentValues", objName));
methodSetObject.endControlFlow();
}
}
if (entityInfo.getSuperClass() != null
&& !entityInfo.getSuperClass().toString().equals("java.lang.Object")) {
methodSetObject
.addStatement(
"contentValues.putAll($L.DaoConfig.getConfig().getRecordAdapter($L.class).createRecord($L,regex));",
Constants.CORE_PKGNAME, entityInfo.getSuperClass().toString(), objName);
}
methodSetObject.addCode(CodeBlock.of("return contentValues;"));
return methodSetObject;
}
示例14: 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();
}
示例15: validateInterface
import com.google.auto.common.MoreTypes; //导入依赖的package包/类
private boolean validateInterface(TypeMirror typeMirror) {
TypeElement bindClassType = AnnotationUtils.getBindClassType(MoreTypes.asTypeElement(typeMirror), getProcessingEnv());
if (bindClassType == null) {
return true;
}
if (!SuperficialValidation.validateElement(bindClassType)) {
return false;
}
return true;
}