private CodeTypeElement generateWrapperOnly(ProcessorContext context, Element e) { CodeTypeElement wrapper = generateWrapper(context, e, true); if (wrapper == null) { return null; } assertNoErrorExpected(e); return wrapper; }
emitError(e, "Class must not be private to generate a wrapper."); return null; emitError(e, "Class must not be final to generate a wrapper."); return null; emitError(e, "Inner class must be static to generate a wrapper."); return null; emitError(sourceType, "No suiteable constructor found for wrapper factory generation. At least one default or copy constructor must be visible."); return null; String wrapperClassName = createWrapperClassName(sourceType); if (topLevelClass) { typeModifiers = ElementUtils.modifiers(Modifier.FINAL); addGeneratedBy(context, wrapperType, sourceType); wrapperType.add(createNodeChild(context, sourceType.asType(), FIELD_DELEGATE)); wrapperType.add(createNodeChild(context, context.getType(ProbeNode.class), FIELD_PROBE)); if (isOverrideableOrUndeclared(sourceType, METHOD_GET_NODE_COST)) { TypeMirror returnType = context.getType(NodeCost.class); CodeExecutableElement getInstrumentationTags = new CodeExecutableElement(ElementUtils.modifiers(Modifier.PUBLIC), returnType, METHOD_GET_NODE_COST); VariableElement firstParam = method.getParameters().isEmpty() ? null : method.getParameters().get(0); if (topLevelClass && (firstParam == null || !ElementUtils.isAssignable(firstParam.asType(), context.getType(VirtualFrame.class)))) { emitError(e, String.format("Wrapped execute method %s must have VirtualFrame as first parameter.", method.getSimpleName().toString())); return null;
emitError(element, String.format("Only classes can be annotated with %s.", GenerateWrapper.class.getSimpleName())); continue; emitError(element, String.format("Fatal %s.%s not found.", InstrumentableNode.class.getSimpleName(), CREATE_WRAPPER_NAME)); continue; emitError(element, String.format("Classes annotated with @%s must implement %s.", GenerateWrapper.class.getSimpleName(), InstrumentableNode.class.getSimpleName())); continue; } else { emitError(element, String.format("Classes annotated with @%s must declare/override %s.%s and return a new instance of the generated wrapper class called %s." + " You may copy the following generated implementation: %n" + " @Override public %s createWrapper(%s probeNode) {%n" + InstrumentableNode.class.getSimpleName(), CREATE_WRAPPER_NAME, createWrapperClassName((TypeElement) element), com.oracle.truffle.api.instrumentation.InstrumentableNode.WrapperNode.class.getSimpleName(), ProbeNode.class.getSimpleName(), createWrapperClassName((TypeElement) element))); continue; emitError(element, String.format("Classes annotated with @%s must extend %s.", GenerateWrapper.class.getSimpleName(), Node.class.getSimpleName())); continue; CodeTypeElement unit = generateWrapperOnly(context, element); handleThrowable(e, element);
private CodeTypeElement generateWrapperAndFactory(ProcessorContext context, Element e) { CodeTypeElement wrapper = generateWrapper(context, e, false); if (wrapper == null) { return null; } CodeTypeElement factory = generateFactory(context, e, wrapper); // add @SuppressWarnings("deprecation") DeclaredType suppressWarnings = context.getDeclaredType(SuppressWarnings.class); CodeAnnotationMirror suppressWarningsAnnotation = new CodeAnnotationMirror(suppressWarnings); suppressWarningsAnnotation.setElementValue(ElementUtils.findExecutableElement(suppressWarnings, "value"), new CodeAnnotationValue(Arrays.asList(new CodeAnnotationValue("deprecation")))); factory.getAnnotationMirrors().add(suppressWarningsAnnotation); wrapper.getModifiers().add(Modifier.STATIC); factory.add(wrapper); assertNoErrorExpected(e); return factory; }
emitError(element, String.format("Only classes can be annotated with %s.", com.oracle.truffle.api.instrumentation.Instrumentable.class.getSimpleName())); continue; CodeTypeElement unit = generateWrapperAndFactory(context, element); handleThrowable(e, element);
PackageElement pack = context.getEnvironment().getElementUtils().getPackageOf(sourceType); Set<Modifier> typeModifiers = ElementUtils.modifiers(Modifier.PUBLIC, Modifier.FINAL); CodeTypeElement factory = new CodeTypeElement(typeModifiers, ElementKind.CLASS, pack, createWrapperClassName(sourceType)); addGeneratedBy(context, factory, sourceType);