本文整理汇总了Java中com.google.auto.common.MoreTypes.asTypeElement方法的典型用法代码示例。如果您正苦于以下问题:Java MoreTypes.asTypeElement方法的具体用法?Java MoreTypes.asTypeElement怎么用?Java MoreTypes.asTypeElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.auto.common.MoreTypes
的用法示例。
在下文中一共展示了MoreTypes.asTypeElement方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompositionMergeConflictPolicy
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static IMergeConflictPolicy getCompositionMergeConflictPolicy(TypeElement element, ProcessingEnvironment env) {
Optional<AnnotationValue> value = getParameterFrom(element, Composition.class, "onConflict", env);
if (value.isPresent()) {
TypeElement typeElement = MoreTypes.asTypeElement((Type) value.get().getValue());
try {
return (IMergeConflictPolicy) Class.forName(typeElement.getQualifiedName().toString()).newInstance();
} catch (Exception ignore) { }
}
throw new IncompleteAnnotationException(Composition.class, "onConflict");
}
示例2: hasInheritedInjectionAnnotation
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public static boolean hasInheritedInjectionAnnotation(TypeElement element) {
if (hasUseInjectionAnnotation(element))
return true;
for (TypeMirror typeInterface : element.getInterfaces()) {
TypeElement asElement = MoreTypes.asTypeElement(typeInterface);
if (hasUseInjectionAnnotation(asElement))
return true;
}
return false;
}
示例3: getMethodsMap
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
/**
* Get list of executable elements and list of overriders
* @param element element that contains executable elements
* @param env annotation processing environment
* @return map
*/
public static Map<IExecutableElementContainer, List<ITypeElementPairContainer>> getMethodsMap(TypeElement element, ProcessingEnvironment env) {
HashMap<IExecutableElementContainer, List<ITypeElementPairContainer>> map = new HashMap<IExecutableElementContainer, List<ITypeElementPairContainer>>();
Map<Visibility, ? extends List<ExecutableElement>> executableElements = getVisibleExecutableElements(element, env);
for (TypeMirror mirror : element.getInterfaces()) {
TypeElement typeInterfaceElement = MoreTypes.asTypeElement(mirror);
TypeElement bindClassType = AnnotationUtils.getBindClassType(typeInterfaceElement, env);
if (bindClassType == null)
continue;
boolean hasInjectAnnotation = AnnotationUtils.hasUseInjectionAnnotation(typeInterfaceElement);
Map<Visibility, ? extends List<ExecutableElement>> executableElementBind = getVisibleExecutableElements(bindClassType, env);
List<ExecutableElement> publicInterfaceElements = executableElements.get(Visibility.PUBLIC);
processInterfaceElements(publicInterfaceElements,
executableElementBind.get(Visibility.PUBLIC),
element, typeInterfaceElement, bindClassType, map, hasInjectAnnotation, env);
processBindElements(publicInterfaceElements,
executableElementBind.get(Visibility.PUBLIC),
element, typeInterfaceElement, bindClassType, map, hasInjectAnnotation, env);
processBindElements(publicInterfaceElements,
executableElementBind.get(Visibility.PROTECTED),
element, typeInterfaceElement, bindClassType, map, hasInjectAnnotation, env);
}
return map;
}
示例4: visitDeclared
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
@Override public TypeMirror visitDeclared(DeclaredType type, Types types) {
TypeElement element = MoreTypes.asTypeElement(type);
List<? extends TypeMirror> args = type.getTypeArguments();
TypeMirror[] strippedArgs = new TypeMirror[args.size()];
for (int i = 0; i < args.size(); i++) {
TypeMirror arg = args.get(i);
strippedArgs[i] = arg.accept(this, types);
}
return types.getDeclaredType(element, strippedArgs);
}
示例5: getBindClassType
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public static TypeElement getBindClassType(TypeElement element, ProcessingEnvironment env) {
Optional<AnnotationValue> value = getParameterFrom(element
, Bind.class
, "value"
, env);
if (value.isPresent()) {
TypeElement typeElement = MoreTypes.asTypeElement((Type) value.get().getValue());
AnnotationMirror bindMirror = MoreElements.getAnnotationMirror(typeElement, Bind.class).orNull();
if (!typeElement.getKind().isClass()) {
env.getMessager().printMessage(Diagnostic.Kind.ERROR
, "Bind's annotation value must be class"
, element
, bindMirror
, value.get());
return null;
}
/**
* Bind annotation is not valid if Bind's class value isn't implements element interface
*/
javax.lang.model.util.Types types = env.getTypeUtils();
if (!types.isAssignable(types.getDeclaredType(typeElement), types.getDeclaredType(element))
&& !types.isAssignable(typeElement.getSuperclass(), element.asType())) {
env.getMessager().printMessage(Diagnostic.Kind.ERROR
, "Bind's annotation value class must implement " + element.getSimpleName() + " interface"
, element
, bindMirror
, value.get());
return null;
}
return typeElement;
}
return null;
}
示例6: getAnnotationMirrorValueAsTypeElement
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
static TypeElement getAnnotationMirrorValueAsTypeElement(AnnotationMirror annotationMirror, String methodName) {
AnnotationValue value = getAnnotationValue(annotationMirror, methodName);
return value == null ? null : MoreTypes.asTypeElement((TypeMirror) value.getValue());
}
示例7: element
import com.google.auto.common.MoreTypes; //导入方法依赖的package包/类
public TypeElement element() {
return MoreTypes.asTypeElement(type());
}