下面列出了javax.persistence.metamodel.StaticMetamodel#javax.lang.model.type.MirroredTypeException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
@Override
public <T> T getAttribute(final String attr) {
try {
return (T) Objects.requireNonNull(mConfigAnnotation)
.annotationType()
.getMethod(attr)
.invoke(mConfigAnnotation);
} catch (Exception e) {
if (e.getCause() instanceof MirroredTypeException) {
return (T) ((MirroredTypeException) e.getCause()).getTypeMirror();
}
}
return null;
}
public FactoryAnnotatedCls(TypeElement classElement) throws ProcessingException {
this.mAnnotatedClsElement = classElement;
ShapeType annotation = classElement.getAnnotation(ShapeType.class);
type = annotation.value();
try {
mSupperClsSimpleName = annotation.superClass().getSimpleName();
mSupperClsQualifiedName = annotation.superClass().getCanonicalName();
} catch (MirroredTypeException mte) {
DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
mSupperClsQualifiedName = classTypeElement.getQualifiedName().toString();
mSupperClsSimpleName = classTypeElement.getSimpleName().toString();
}
if (mSupperClsSimpleName == null || mSupperClsSimpleName.equals("")) {
throw new ProcessingException(classElement,
"superClass() in @%s for class %s is null or empty! that's not allowed",
ShapeType.class.getSimpleName(), classElement.getQualifiedName().toString());
}
}
private void processRefTarget(RoundEnvironment roundEnv) {
for (Element element : roundEnv.getElementsAnnotatedWith(RefTarget.class)) {
if (this.element == null) {
this.element = element;
}
TypeElement classElement = (TypeElement) element;
RefTarget refTarget = classElement.getAnnotation(RefTarget.class);
String interfaceFullName = classElement.getQualifiedName().toString();
String targetName;
try {
targetName = refTarget.clazz().getCanonicalName();
} catch (MirroredTypeException mte) {
targetName = mte.getTypeMirror().toString();
}
RefTargetModel model = new RefTargetModel(interfaceFullName,
targetName,
false,
refTarget.optimizationRef());
targetModelMap.put(interfaceFullName, model);
}
}
public Field(Element element, Key key) {
this.prefKeyName = key.name();
try {
Class clazz = key.serializer();
serializerType = TypeName.get(clazz);
serializeType = detectSerializeTypeNameByClass(clazz);
} catch (MirroredTypeException mte) {
DeclaredType classTypeMirror = (DeclaredType) mte.getTypeMirror();
TypeElement classTypeElement = (TypeElement) classTypeMirror.asElement();
serializerType = TypeName.get(classTypeMirror);
serializeType = detectSerializeTypeByTypeElement(classTypeElement);
}
VariableElement variable = (VariableElement) element;
this.fieldType = TypeName.get(element.asType());
this.name = element.getSimpleName().toString();
this.value = variable.getConstantValue();
}
private static void parseRClass(String respectivePackageName, String rClass) {
Element element;
try {
element = scanner.elementUtils.getTypeElement(rClass);
} catch (MirroredTypeException mte) {
element = scanner.typeUtils.asElement(mte.getTypeMirror());
}
JCTree tree = (JCTree) scanner.trees.getTree(element);
if (tree != null) {
IdScanner idScanner = new IdScanner(scanner.symbols, scanner.elementUtils.getPackageOf(element)
.getQualifiedName().toString(), respectivePackageName);
tree.accept(idScanner);
} else {
parseCompiledR(respectivePackageName, (TypeElement) element);
}
}
private void processElement(TypeElement serviceProvider) {
if (processed.contains(serviceProvider)) {
return;
}
processed.add(serviceProvider);
ServiceProvider annotation = serviceProvider.getAnnotation(ServiceProvider.class);
if (annotation != null) {
try {
annotation.value();
} catch (MirroredTypeException ex) {
TypeMirror serviceInterface = ex.getTypeMirror();
if (verifyAnnotation(serviceInterface, serviceProvider)) {
String interfaceName = ex.getTypeMirror().toString();
createProviderFile(serviceProvider, interfaceName);
}
}
}
}
private String getViewClassFromAnnotationParams(TypeElement typeElement) {
InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
String mvpViewClassName = "";
if (annotation != null) {
TypeMirror value = null;
try {
annotation.view();
} catch (MirroredTypeException mte) {
value = mte.getTypeMirror();
}
mvpViewClassName = Util.getFullClassName(value);
}
if (mvpViewClassName.isEmpty() || DefaultView.class.getName().equals(mvpViewClassName)) {
return null;
}
return mvpViewClassName;
}
private String getViewStateClassFromAnnotationParams(TypeElement typeElement) {
InjectViewState annotation = typeElement.getAnnotation(InjectViewState.class);
String mvpViewStateClassName = "";
if (annotation != null) {
TypeMirror value;
try {
annotation.value();
} catch (MirroredTypeException mte) {
value = mte.getTypeMirror();
mvpViewStateClassName = value.toString();
}
}
if (mvpViewStateClassName.isEmpty() || DefaultViewState.class.getName().equals(mvpViewStateClassName)) {
return null;
}
return mvpViewStateClassName;
}
private void parseConductorController(Element element,
Map<TypeElement, DelegateClassGenerator> delegateClassMap) {
if (!SuperficialValidation.validateElement(element)) {
error("Superficial validation error for %s", element.getSimpleName());
return;
}
if (!Validator.isNotAbstractClass(element)) {
error("%s is abstract", element.getSimpleName());
return;
}
if (!Validator.isSubType(element, CONDUCTOR_CONTROLLER_CLASS_NAME, processingEnv)) {
error("%s must extend View", element.getSimpleName());
return;
}
//getEnclosing for class type will returns its package/
TypeElement enclosingElement = (TypeElement) element;
DelegateClassGenerator delegateClassGenerator =
getDelegate(enclosingElement, delegateClassMap);
delegateClassGenerator.setViewType(ViewType.CONDUCTOR_CONTROLLER);
ConductorController annotation = element.getAnnotation(ConductorController.class);
try {
annotation.presenter();
} catch (MirroredTypeException mte) {
parsePresenter(delegateClassGenerator, mte);
}
}
public ArgumentAnnotatedField(Element element, TypeElement classElement, Arg annotation)
throws ProcessingException {
this.name = element.getSimpleName().toString();
this.key = getKey(element, annotation);
this.type = element.asType().toString();
this.element = element;
this.required = annotation.required();
this.classElement = classElement;
try {
Class<? extends ArgsBundler> clazz = annotation.bundler();
bundlerClass = getFullQualifiedNameByClass(clazz);
} catch (MirroredTypeException mte) {
TypeMirror baggerClass = mte.getTypeMirror();
bundlerClass = getFullQualifiedNameByTypeMirror(baggerClass);
}
}
Property(String fieldName, VariableElement element) {
this.fieldName = fieldName;
this.element = element;
this.typeName = TypeName.get(element.asType());
this.annotations = getAnnotations(element);
// get the parcel adapter if any
ParcelAdapter parcelAdapter = element.getAnnotation(ParcelAdapter.class);
if (parcelAdapter != null) {
try {
parcelAdapter.value();
} catch (MirroredTypeException e) {
this.typeAdapter = e.getTypeMirror();
}
}
// get the element version, default 0
ParcelVersion parcelVersion = element.getAnnotation(ParcelVersion.class);
this.version = parcelVersion == null ? 0 : parcelVersion.from();
}
public static TypeDef getInlineReturnType(BuilderContext context, Inline inline, TypeDef fallback) {
try {
Class returnType = inline.returnType();
if (returnType == null) {
return fallback;
}
return ClassTo.TYPEDEF.apply(inline.returnType());
} catch (MirroredTypeException e) {
if (None.FQN.equals(e.getTypeMirror().toString())) {
return fallback;
}
Element element = context.getTypes().asElement(e.getTypeMirror());
return ElementTo.TYPEDEF.apply((TypeElement) element);
}
}
private TypeMirror getAnnotationJsonType() {
try {
((JsonConfig) mConfigAnnotation).type();
} catch (MirroredTypeException e) {
return e.getTypeMirror();
}
return null;
}
private TypeMirror getConfigTypeResolverTypeMirror(final ConfigType configTypeAnnotation) {
try {
configTypeAnnotation.value();
} catch (MirroredTypeException e) {
return e.getTypeMirror();
}
// Should never happen
return null;
}
private TypeMirror getTypeMirror(final Element element) {
final Source annotation = element.getAnnotation(Source.class);
if (annotation != null) {
try {
annotation.value();
} catch (MirroredTypeException e) {
return e.getTypeMirror();
}
}
return null;
}
public ViewInfo(ViewField viewField){
fieldName = viewField.name();
id = viewField.id();
try
{
qualifiedClassName = viewField.type().getCanonicalName();
}
catch( MirroredTypeException mte )
{
qualifiedClassName = mte.getTypeMirror().toString();
}
}
private TypeElement getComponentTypeElement(PopUpController annotation) {
try {
annotation.component();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getComponentInterfaceTypeElement(PopUpController annotation) {
try {
annotation.componentInterface();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getTracker(Tracker trackerAnnotation) {
try {
trackerAnnotation.value();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getLogger(Debug debugAnnotation) {
try {
debugAnnotation.logger();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getComponentTypeElement(Controller annotation) {
try {
annotation.component();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getComponentInterfaceTypeElement(Controller annotation) {
try {
annotation.componentInterface();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getApplicationLoaderTypeElement(Application applicationAnnotation) {
try {
applicationAnnotation.loader();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getCustomAlertPresenterTypeElement(Application applicationAnnotation) {
try {
applicationAnnotation.alertPresenter();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getCustomConfirmPresenterTypeElement(Application applicationAnnotation) {
try {
applicationAnnotation.confirmPresenter();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getContextTypeElement(Application applicationAnnotation) {
try {
applicationAnnotation.context();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getCompositeTypeElement(Composite annotation) {
try {
annotation.compositeController();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getCompositeConditionElement(Composite annotation) {
try {
annotation.condition();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getLogger(Debug debugAnnotation) {
try {
debugAnnotation.logger();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}
private TypeElement getComponentTypeElement(ErrorPopUpController annotation) {
try {
annotation.component();
} catch (MirroredTypeException exception) {
return (TypeElement) this.processingEnvironment.getTypeUtils()
.asElement(exception.getTypeMirror());
}
return null;
}