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); }
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 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 static TypeMirror fillInGenericWildcards(TypeMirror type) { if (type.getKind() != TypeKind.DECLARED) { return type; } DeclaredType declaredType = (DeclaredType) type; TypeElement element = (TypeElement) declaredType.asElement(); if (element == null) { return type; } int typeParameters = element.getTypeParameters().size(); if (typeParameters > 0 && declaredType.getTypeArguments().size() != typeParameters) { return ProcessorContext.getInstance().getEnvironment().getTypeUtils().erasure(type); } return type; }
public static TypeMirror fillInGenericWildcards(TypeMirror type) { if (type.getKind() != TypeKind.DECLARED) { return type; } DeclaredType declaredType = (DeclaredType) type; TypeElement element = (TypeElement) declaredType.asElement(); if (element == null) { return type; } int typeParameters = element.getTypeParameters().size(); if (typeParameters > 0 && declaredType.getTypeArguments().size() != typeParameters) { return ProcessorContext.getInstance().getEnvironment().getTypeUtils().erasure(type); } return type; }
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 static void setFieldCompilationFinal(CodeVariableElement field, int dimensions) { if (field.getModifiers().contains(Modifier.FINAL) && dimensions <= 0) { // no need for the compilation final annotation. return; } CodeAnnotationMirror annotation = new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(CompilationFinal.class)); if (dimensions > 0 || field.getType().getKind() == TypeKind.ARRAY) { annotation.setElementValue(annotation.findExecutableElement("dimensions"), new CodeAnnotationValue(dimensions < 0 ? 0 : dimensions)); } field.getAnnotationMirrors().add(annotation); }
private void generateOptionDescriptor(OptionsInfo info) { Element element = info.type; ProcessorContext context = ProcessorContext.getInstance(); CodeTypeElement unit = generateDescriptors(context, element, info); DeclaredType overrideType = (DeclaredType) context.getType(Override.class); DeclaredType unusedType = (DeclaredType) context.getType(SuppressWarnings.class); unit.accept(new GenerateOverrideVisitor(overrideType), null); unit.accept(new FixWarningsVisitor(context.getEnvironment(), unusedType, overrideType), null); try { unit.accept(new CodeWriter(context.getEnvironment(), element), null); } catch (RuntimeException e) { if (e.getCause() instanceof FilerException) { // ignore spurious errors of source file already created in Eclipse. if (e.getCause().getMessage().startsWith("Source file already created")) { return; } } } }
private static CodeVariableElement createNodeField(Modifier visibility, TypeMirror type, String name, Class<?> annotationClass, Modifier... modifiers) { CodeVariableElement childField = new CodeVariableElement(modifiers(modifiers), type, name); if (annotationClass != null) { if (annotationClass == CompilationFinal.class) { setFieldCompilationFinal(childField, 0); } else { childField.getAnnotationMirrors().add(new CodeAnnotationMirror(ProcessorContext.getInstance().getDeclaredType(annotationClass))); } } setVisibility(childField.getModifiers(), visibility); return childField; }
public static boolean isAssignable(TypeMirror from, TypeMirror to) { if (typeEquals(from, to)) { return true; } else if (isVoid(to)) { return true; } else if (isObject(to)) { return true; } ProcessorContext context = ProcessorContext.getInstance(); if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) { return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to)); } else { return isAssignableImpl(from, to); } }
public static boolean isAssignable(TypeMirror from, TypeMirror to) { if (typeEquals(from, to)) { return true; } else if (isVoid(to)) { return true; } else if (isObject(to)) { return true; } ProcessorContext context = ProcessorContext.getInstance(); if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) { return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to)); } else { return isAssignableImpl(from, to); } }
static CodeTree createTransferToInterpreterAndInvalidate() { ProcessorContext context = ProcessorContext.getInstance(); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); return builder.build(); }
public static CodeTree createTransferToInterpreterAndInvalidate() { ProcessorContext context = ProcessorContext.getInstance(); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); return builder.build(); }
static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) { TypeElement templateType = sourceModel.getTemplateType(); ProcessorContext context = ProcessorContext.getInstance(); PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType); CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName); TypeMirror resolvedSuperType = superType; if (resolvedSuperType == null) { resolvedSuperType = context.getType(Object.class); } clazz.setSuperClass(resolvedSuperType); CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class)); generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType())); if (sourceMethod != null && sourceMethod.getMethod() != null) { generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName())); } clazz.addAnnotationMirror(generatedByAnnotation); return clazz; }
public static CodeTypeElement createClass(Template sourceModel, TemplateMethod sourceMethod, Set<Modifier> modifiers, String simpleName, TypeMirror superType) { TypeElement templateType = sourceModel.getTemplateType(); ProcessorContext context = ProcessorContext.getInstance(); PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(templateType); CodeTypeElement clazz = new CodeTypeElement(modifiers, ElementKind.CLASS, pack, simpleName); TypeMirror resolvedSuperType = superType; if (resolvedSuperType == null) { resolvedSuperType = context.getType(Object.class); } clazz.setSuperClass(resolvedSuperType); CodeAnnotationMirror generatedByAnnotation = new CodeAnnotationMirror((DeclaredType) context.getType(GeneratedBy.class)); generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("value"), new CodeAnnotationValue(templateType.asType())); if (sourceMethod != null && sourceMethod.getMethod() != null) { generatedByAnnotation.setElementValue(generatedByAnnotation.findExecutableElement("methodName"), new CodeAnnotationValue(sourceMethod.createReferenceName())); } clazz.addAnnotationMirror(generatedByAnnotation); return clazz; }