private static TypeElement getOptional(ProcessorContext context, String name) { return context.getEnvironment().getElementUtils().getTypeElement(name); }
private static void error(Element element, AnnotationMirror annotation, String message, Object... args) { ProcessingEnvironment processingEnv = ProcessorContext.getInstance().getEnvironment(); String formattedMessage = String.format(message, args); if (ExpectError.isExpectedError(processingEnv, element, formattedMessage)) { return; } processingEnv.getMessager().printMessage(Kind.ERROR, formattedMessage, element, annotation); }
public static List<AnnotationMirror> collectAnnotations(ProcessorContext context, AnnotationMirror markerAnnotation, String elementName, Element element, Class<? extends Annotation> annotationClass) { List<AnnotationMirror> result = new ArrayList<>(); if (markerAnnotation != null) { result.addAll(ElementUtils.getAnnotationValueList(AnnotationMirror.class, markerAnnotation, elementName)); } AnnotationMirror explicit = ElementUtils.findAnnotationMirror(context.getEnvironment(), element, annotationClass); if (explicit != null) { result.add(explicit); } return result; }
public static TypeMirror boxType(ProcessorContext context, TypeMirror primitiveType) { if (primitiveType == null) { return null; } TypeMirror boxedType = primitiveType; if (boxedType.getKind().isPrimitive()) { boxedType = context.getEnvironment().getTypeUtils().boxedClass((PrimitiveType) boxedType).asType(); } return boxedType; }
public static List<AnnotationMirror> collectAnnotations(ProcessorContext context, AnnotationMirror markerAnnotation, String elementName, Element element, Class<? extends Annotation> annotationClass) { List<AnnotationMirror> result = new ArrayList<>(); if (markerAnnotation != null) { result.addAll(ElementUtils.getAnnotationValueList(AnnotationMirror.class, markerAnnotation, elementName)); } AnnotationMirror explicit = ElementUtils.findAnnotationMirror(context.getEnvironment(), element, annotationClass); if (explicit != null) { result.add(explicit); } return result; }
private void handleThrowable(Throwable t, Element e) { String message = "Uncaught error in " + getClass().getSimpleName() + " while processing " + e + " "; ProcessorContext.getInstance().getEnvironment().getMessager().printMessage(Kind.ERROR, message + ": " + ElementUtils.printException(t), e); }
private static void handleThrowable(AnnotationProcessor<?> generator, Throwable t, Element e) { String message = "Uncaught error in " + generator.getClass().getSimpleName() + " while processing " + e + " "; ProcessorContext.getInstance().getEnvironment().getMessager().printMessage(Kind.ERROR, message + ": " + ElementUtils.printException(t), e); }
public static TypeMirror boxType(ProcessorContext context, TypeMirror primitiveType) { if (primitiveType == null) { return null; } TypeMirror boxedType = primitiveType; if (boxedType.getKind().isPrimitive()) { boxedType = context.getEnvironment().getTypeUtils().boxedClass((PrimitiveType) boxedType).asType(); } return boxedType; }
public static boolean isSubtype(TypeMirror type1, TypeMirror type2) { if (type1 instanceof CodeTypeMirror || type2 instanceof CodeTypeMirror) { throw new UnsupportedOperationException(); } return ProcessorContext.getInstance().getEnvironment().getTypeUtils().isSubtype(type1, type2); }
private static void handleThrowable(AnnotationProcessor<?> generator, Throwable t, Element e) { String message = "Uncaught error in " + generator.getClass().getSimpleName() + " while processing " + e + " "; ProcessorContext.getInstance().getEnvironment().getMessager().printMessage(Kind.ERROR, message + ": " + ElementUtils.printException(t), e); }
private void handleThrowable(Throwable t, Element e) { String message = "Uncaught error in " + getClass().getSimpleName() + " while processing " + e + " "; ProcessorContext.getInstance().getEnvironment().getMessager().printMessage(Kind.ERROR, message + ": " + ElementUtils.printException(t), e); }
public static boolean isSubtype(TypeMirror type1, TypeMirror type2) { if (type1 instanceof CodeTypeMirror || type2 instanceof CodeTypeMirror) { throw new UnsupportedOperationException(); } return ProcessorContext.getInstance().getEnvironment().getTypeUtils().isSubtype(type1, type2); }
public AbstractParser() { this.context = ProcessorContext.getInstance(); this.processingEnv = context.getEnvironment(); this.log = context.getLog(); }
public AbstractParser() { this.context = ProcessorContext.getInstance(); this.processingEnv = context.getEnvironment(); this.log = context.getLog(); }
private boolean isPrimitiveWrapper(TypeMirror type) { Types types = context.getEnvironment().getTypeUtils(); for (TypeKind kind : TypeKind.values()) { if (!kind.isPrimitive()) { continue; } if (ElementUtils.typeEquals(type, types.boxedClass(types.getPrimitiveType(kind)).asType())) { return true; } } return false; }
private boolean isPrimitiveWrapper(TypeMirror type) { Types types = context.getEnvironment().getTypeUtils(); for (TypeKind kind : TypeKind.values()) { if (!kind.isPrimitive()) { continue; } if (ElementUtils.typeEquals(type, types.boxedClass(types.getPrimitiveType(kind)).asType())) { return true; } } return false; }
@Override public final boolean isParsable(ExecutableElement method) { return ElementUtils.findAnnotationMirror(getContext().getEnvironment(), method, getAnnotationType()) != null; }
@Override public boolean isParsable(ExecutableElement method) { if (getAnnotationType() != null) { return ElementUtils.findAnnotationMirror(getContext().getEnvironment(), method, getAnnotationType()) != null; } return true; }
@Override public boolean isParsable(ExecutableElement method) { if (getAnnotationType() != null) { return ElementUtils.findAnnotationMirror(getContext().getEnvironment(), method, getAnnotationType()) != null; } return true; }
private Element createGetSuppliedChildrenMethod() { ArrayType nodeArray = context.getEnvironment().getTypeUtils().getArrayType(getType(Node.class)); CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, FINAL), nodeArray, "getSuppliedChildren"); method.getAnnotationMirrors().add(new CodeAnnotationMirror(context.getDeclaredType(Override.class))); CodeTreeBuilder builder = method.createBuilder(); builder.startReturn().tree(createGetSuppliedChildren()).end(); return method; }