javax.lang.model.type.MirroredTypeException Java Examples

The following examples show how to use javax.lang.model.type.MirroredTypeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: aircon   Author: ironSource   File: LibraryConfigAnnotationParser.java    License: MIT License 6 votes vote down vote up
@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;
}
 
Example #2
Source Project: ShapeView   Author: xwc520   File: FactoryAnnotatedCls.java    License: Apache License 2.0 6 votes vote down vote up
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());
    }
}
 
Example #3
Source Project: Intimate   Author: eleme   File: IntimateProcesser.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #4
Source Project: kvs-schema   Author: rejasupotaro   File: Field.java    License: MIT License 6 votes vote down vote up
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();
}
 
Example #5
Source Project: convalida   Author: wellingtoncosta   File: AndroidResourceSanner.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #6
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ServiceProviderProcessor.java    License: GNU General Public License v2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #7
Source Project: Moxy   Author: Arello-Mobile   File: InjectViewStateProcessor.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example #8
Source Project: Moxy   Author: Arello-Mobile   File: InjectViewStateProcessor.java    License: MIT License 6 votes vote down vote up
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;
}
 
Example #9
Source Project: EasyMVP   Author: 6thsolution   File: EasyMVPProcessor.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #10
Source Project: fragmentargs   Author: sockeqwe   File: ArgumentAnnotatedField.java    License: Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example #11
Source Project: auto-parcel   Author: aitorvs   File: AutoParcelProcessor.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #12
Source Project: sundrio   Author: sundrio   File: BuilderUtils.java    License: Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example #13
Source Project: aircon   Author: ironSource   File: LibraryConfigAnnotationParser.java    License: MIT License 5 votes vote down vote up
private TypeMirror getAnnotationJsonType() {
	try {
		((JsonConfig) mConfigAnnotation).type();
	} catch (MirroredTypeException e) {
		return e.getTypeMirror();
	}

	return null;
}
 
Example #14
Source Project: aircon   Author: ironSource   File: CustomConfigAnnotationParser.java    License: MIT License 5 votes vote down vote up
private TypeMirror getConfigTypeResolverTypeMirror(final ConfigType configTypeAnnotation) {
	try {
		configTypeAnnotation.value();
	} catch (MirroredTypeException e) {
		return e.getTypeMirror();
	}
	// Should never happen
	return null;
}
 
Example #15
Source Project: aircon   Author: ironSource   File: ConfigFieldParser.java    License: MIT License 5 votes vote down vote up
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;
}
 
Example #16
Source Project: AnnotatedAdapter   Author: sockeqwe   File: ViewInfo.java    License: Apache License 2.0 5 votes vote down vote up
public ViewInfo(ViewField viewField){
  fieldName = viewField.name();
  id = viewField.id();

  try
  {
    qualifiedClassName = viewField.type().getCanonicalName();
  }
  catch( MirroredTypeException mte )
  {
    qualifiedClassName = mte.getTypeMirror().toString();
  }

}
 
Example #17
Source Project: nalu   Author: NaluKit   File: PopUpControllerAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getComponentTypeElement(PopUpController annotation) {
  try {
    annotation.component();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #18
Source Project: nalu   Author: NaluKit   File: PopUpControllerAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getComponentInterfaceTypeElement(PopUpController annotation) {
  try {
    annotation.componentInterface();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #19
Source Project: nalu   Author: NaluKit   File: TrackerAnnotationValidator.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getTracker(Tracker trackerAnnotation) {
  try {
    trackerAnnotation.value();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #20
Source Project: nalu   Author: NaluKit   File: DebugAnnotationValidator.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getLogger(Debug debugAnnotation) {
  try {
    debugAnnotation.logger();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #21
Source Project: nalu   Author: NaluKit   File: ControllerAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getComponentTypeElement(Controller annotation) {
  try {
    annotation.component();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #22
Source Project: nalu   Author: NaluKit   File: ControllerAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getComponentInterfaceTypeElement(Controller annotation) {
  try {
    annotation.componentInterface();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #23
Source Project: nalu   Author: NaluKit   File: ApplicationAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getApplicationLoaderTypeElement(Application applicationAnnotation) {
  try {
    applicationAnnotation.loader();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #24
Source Project: nalu   Author: NaluKit   File: ApplicationAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getCustomAlertPresenterTypeElement(Application applicationAnnotation) {
  try {
    applicationAnnotation.alertPresenter();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #25
Source Project: nalu   Author: NaluKit   File: ApplicationAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getCustomConfirmPresenterTypeElement(Application applicationAnnotation) {
  try {
    applicationAnnotation.confirmPresenter();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #26
Source Project: nalu   Author: NaluKit   File: ApplicationAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getContextTypeElement(Application applicationAnnotation) {
  try {
    applicationAnnotation.context();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #27
Source Project: nalu   Author: NaluKit   File: CompositesAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getCompositeTypeElement(Composite annotation) {
  try {
    annotation.compositeController();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #28
Source Project: nalu   Author: NaluKit   File: CompositesAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getCompositeConditionElement(Composite annotation) {
  try {
    annotation.condition();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #29
Source Project: nalu   Author: NaluKit   File: DebugAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getLogger(Debug debugAnnotation) {
  try {
    debugAnnotation.logger();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}
 
Example #30
Source Project: nalu   Author: NaluKit   File: ErrorPopUpControllerAnnotationScanner.java    License: Apache License 2.0 5 votes vote down vote up
private TypeElement getComponentTypeElement(ErrorPopUpController annotation) {
  try {
    annotation.component();
  } catch (MirroredTypeException exception) {
    return (TypeElement) this.processingEnvironment.getTypeUtils()
                                                   .asElement(exception.getTypeMirror());
  }
  return null;
}