Example usage for javax.annotation.processing Messager printMessage

List of usage examples for javax.annotation.processing Messager printMessage

Introduction

In this page you can find the example usage for javax.annotation.processing Messager printMessage.

Prototype

void printMessage(Diagnostic.Kind kind, CharSequence msg);

Source Link

Document

Prints a message of the specified kind.

Usage

From source file:org.shredzone.commons.taglib.processor.TaglibProcessor.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    taglib = new TaglibBean();

    try {/*w  w w.  j  ava 2  s .  c o  m*/
        for (Element e : roundEnv.getElementsAnnotatedWith(Tag.class)) {
            processTag(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagInfo.class)) {
            processTagInfo(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(BeanFactoryReference.class)) {
            processBeanFactoryReference(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagParameter.class)) {
            processTagParameter(e);
        }

        for (Element e : roundEnv.getElementsAnnotatedWith(TagLib.class)) {
            processTagLib(e);
        }

        if (!taglib.getTags().isEmpty()) {
            for (TagBean tag : taglib.getTags()) {
                generateProxyClass(tag);
            }
            generateTaglibTld(taglib.getTldName());
        }

    } catch (ProcessorException | IOException ex) {
        Messager messager = processingEnv.getMessager();
        messager.printMessage(Diagnostic.Kind.ERROR, ex.getMessage());
        return false;

    } finally {
        taglib = null;
        taglibSet = false;
    }

    return true;
}

From source file:org.jdto.tools.AnnotationConfigVerifier.java

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
    super.init(processingEnv);
    Messager messager = processingEnv.getMessager();
    messager.printMessage(Diagnostic.Kind.NOTE, "Starting jDTO Binder Configuration verifier...");
}

From source file:org.jdto.tools.AnnotationConfigVerifier.java

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {

    Messager messager = processingEnv.getMessager();

    if (annotations.isEmpty()) {
        return false;
    }/*from  ww w  .  ja va 2s . c  o  m*/

    TypeElement annotationElement = annotations.iterator().next();

    Set<? extends Element> elms = roundEnv.getElementsAnnotatedWith(annotationElement);

    //at this point we have all the DTO's annotated with @DTOVerify
    for (Element element : elms) {
        messager.printMessage(Diagnostic.Kind.NOTE, "Validating: " + element.toString());

        TypeElement targetType = extractTargetType(element, annotationElement, messager);

        validateDTO((TypeElement) element, targetType, messager);
    }

    return true;
}

From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionGenerator.java

protected void processFormDefinition(TypeElement formElement) throws Exception {
    final Messager messager = context.getMessager();

    messager.printMessage(Diagnostic.Kind.NOTE,
            "Discovered FormDefintion class [" + formElement.getSimpleName() + "]");

    boolean checkInheritance = false;

    FormDefinition definition = formElement.getAnnotation(FormDefinition.class);

    String modelClassName = formElement.getQualifiedName().toString();
    String builderClassName = FormGenerationUtils.fixClassName(formElement.getQualifiedName().toString())
            + FORM_BUILDER_SUFFIX;/* ww w  . j av a  2 s.c  om*/

    FormDefinitionData form = new FormDefinitionData(modelClassName, builderClassName);

    form.setStartElement(definition.startElement());
    form.setI18nBundle(StringUtils.isEmpty(definition.i18n().bundle()) ? formElement.asType().toString()
            : definition.i18n().bundle());

    Column[] columns = definition.layout().value();

    List<String> layoutColumns = new ArrayList<>();
    if (columns.length == 0) {
        layoutColumns.add(ColSpan.SPAN_12.getName());
    } else {
        for (Column column : columns) {
            layoutColumns.add(column.value().getName());
        }
    }

    form.setLayoutColumns(layoutColumns);

    checkInheritance = definition.allowInheritance();

    Map<String, String> defaultFieldSettings = new HashMap<>();

    for (FieldParam param : definition.defaultFieldSettings()) {
        defaultFieldSettings.put(param.name(), param.value());
    }

    List<FormDefinitionFieldData> formElements = new ArrayList<>();

    if (checkInheritance) {
        TypeElement parent = getParent(formElement);
        formElements.addAll(
                extractParentFormFields(parent, definition.policy(), definition.i18n(), defaultFieldSettings));
    }

    formElements.addAll(
            extracFormFields(formElement, definition.policy(), definition.i18n(), defaultFieldSettings));

    FormGenerationUtils.sort(definition.startElement(), formElements);

    messager.printMessage(Diagnostic.Kind.NOTE, "Discovered " + formElements.size() + " elements for form ["
            + formElement.getQualifiedName().toString() + "]");

    form.getElements().addAll(formElements);

    context.getForms().add(form);
}

From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionsProcessor.java

private void processFieldDefinition(TypeElement fieldDefinitionElement) throws Exception {
    final Messager messager = processingEnv.getMessager();

    messager.printMessage(Diagnostic.Kind.NOTE,
            "Discovered FieldDefinition class [" + fieldDefinitionElement.getSimpleName() + "]");

    Collection<FieldInfo> fieldInfos = extractFieldInfos(fieldDefinitionElement, null);

    String modelClassName = fieldDefinitionElement.getQualifiedName().toString();

    String fieldModifierName = fixClassName(modelClassName) + "_FieldStatusModifier";

    Map<String, String> fieldDefinition = new HashMap<>();

    fieldDefinition.put("className", modelClassName);
    fieldDefinition.put("fieldModifierName", fieldModifierName);

    Map<String, Object> templateContext = new HashMap<>();

    templateContext.put("modelClassName", modelClassName);
    templateContext.put("fieldModifierName", fieldModifierName);

    FieldDefinition fieldDefinitionAnnotation = fieldDefinitionElement.getAnnotation(FieldDefinition.class);

    for (FieldInfo fieldInfo : fieldInfos) {
        AnnotationMirror annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement,
                FieldValue.class.getName());

        if (annotation != null) {
            if (fieldDefinition.containsKey("value")) {
                throw new Exception("Problem processing FieldDefinition [" + modelClassName
                        + "]: it should have only one @FieldValue");
            }//from ww w  .j  av a  2 s  . co m

            if (fieldInfo.getter == null || fieldInfo.setter == null) {
                throw new Exception("Problem processing FieldDefinition [" + modelClassName
                        + "]: field marked as @FieldValue should have setter & getter");
            }

            fieldDefinition.put("value", fieldInfo.fieldElement.getSimpleName().toString());
        } else {
            annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement,
                    FieldReadOnly.class.getName());

            if (annotation != null) {
                if (templateContext.containsKey("readOnly")) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: it should have only one @FieldReadOnly");
                }

                if (!fieldInfo.fieldElement.asType().getKind().equals(TypeKind.BOOLEAN)
                        && !fieldInfo.fieldElement.asType().toString().equals(Boolean.class.getName())) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: field marked as @FieldReadOnly must be boolean or Boolean");
                }

                if (fieldInfo.getter == null) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: field marked as @FieldReadOnly should have getter");
                }

                templateContext.put("readOnly", fieldInfo.getter);
            }

            annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement,
                    FieldRequired.class.getName());

            if (annotation != null) {
                if (templateContext.containsKey("required")) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: it should have only one @FieldRequired");
                }

                if (!fieldInfo.fieldElement.asType().getKind().equals(TypeKind.BOOLEAN)
                        && !fieldInfo.fieldElement.asType().toString().equals(Boolean.class.getName())) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: field marked as @FieldRequired must be boolean or Boolean");
                }

                if (fieldInfo.getter == null) {
                    throw new Exception("Problem processing FieldDefinition [" + modelClassName
                            + "]: field marked as @FieldRequired should have getter");
                }

                templateContext.put("required", fieldInfo.getter);
            }

            if (fieldDefinitionAnnotation.labelMode().equals(LabelMode.OVERRIDE)) {

                annotation = GeneratorUtils.getAnnotation(elementUtils, fieldInfo.fieldElement,
                        FieldLabel.class.getName());

                if (annotation != null) {
                    if (templateContext.containsKey("label")) {
                        throw new Exception("Problem processing FieldDefinition [" + modelClassName
                                + "]: it should have only one @FieldLabel");
                    }

                    if (!fieldInfo.fieldElement.asType().toString().equals(String.class.getName())) {
                        throw new Exception("Problem processing FieldDefinition [" + modelClassName
                                + "]: field marked as @FieldLabel must be a String");
                    }

                    if (fieldInfo.getter == null) {
                        throw new Exception("Problem processing FieldDefinition [" + modelClassName
                                + "]: field marked as @FieldLabel should have getter");
                    }
                    templateContext.put("label", fieldInfo.getter);
                }
            }
        }
    }

    StringBuffer source = writeTemplate("templates/FieldDefinitionModifier.ftl", templateContext);

    fieldDefinition.put("sourceCode", source.toString());

    context.getFieldDefinitions().add(fieldDefinition);
}

From source file:org.kie.workbench.common.forms.adf.processors.FormDefinitionsProcessor.java

protected void processFormDefinition(TypeElement formElement) throws Exception {
    final Messager messager = processingEnv.getMessager();

    messager.printMessage(Diagnostic.Kind.NOTE,
            "Discovered FormDefintion class [" + formElement.getSimpleName() + "]");

    boolean checkInheritance = false;

    FormDefinition defintion = formElement.getAnnotation(FormDefinition.class);

    checkInheritance = defintion.allowInheritance();

    List<Map<String, String>> formElements = new ArrayList<>();

    if (checkInheritance) {
        TypeElement parent = getParent(formElement);
        formElements.addAll(extractParentFormFields(parent, defintion.policy(), defintion.i18n()));
    }/*w  w w . j  a v  a  2  s . co m*/

    formElements.addAll(extracFormFields(formElement, defintion.policy(), defintion.i18n()));

    FormGenerationUtils.sort(defintion.startElement(), formElements);

    messager.printMessage(Diagnostic.Kind.NOTE, "Discovered " + formElements.size() + " elements for form ["
            + formElement.getQualifiedName().toString() + "]");

    String modelClassName = formElement.getQualifiedName().toString();
    String builderClassName = fixClassName(formElement.getQualifiedName().toString()) + "FormBuilder";

    Map<String, Object> templateContext = new HashMap<>();
    templateContext.put("modelClass", modelClassName);
    templateContext.put("builderClassName", builderClassName);
    templateContext.put("startElement", defintion.startElement());

    templateContext.put("i18n_bundle",
            StringUtils.isEmpty(defintion.i18n().bundle()) ? formElement.asType().toString()
                    : defintion.i18n().bundle());

    Column[] columns = defintion.layout().value();

    List<String> layoutColumns = new ArrayList<>();
    if (columns.length == 0) {
        layoutColumns.add(ColSpan.SPAN_12.getName());
    } else {
        for (Column column : columns) {
            layoutColumns.add(column.value().getName());
        }
    }

    templateContext.put("layout_columns", layoutColumns);

    templateContext.put("elements", formElements);

    StringBuffer builder = writeTemplate("templates/FormDefinitionSettingsBuilder.ftl", templateContext);

    Map<String, String> form = new HashMap<>();

    form.put("package", ((PackageElement) formElement.getEnclosingElement()).getQualifiedName().toString());
    form.put("modelClass", modelClassName);
    form.put("builderClass", builderClassName);
    form.put("builderCode", builder.toString());

    context.getForms().add(form);
}

From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java

private boolean processDefinitionSets(final Set<? extends TypeElement> set, final Element e,
        final RoundEnvironment roundEnv) throws Exception {
    final Messager messager = processingEnv.getMessager();
    final boolean isClass = e.getKind() == ElementKind.CLASS;
    if (isClass) {
        TypeElement classElement = (TypeElement) e;
        PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
        messager.printMessage(Diagnostic.Kind.NOTE,
                "Discovered definition set class [" + classElement.getSimpleName() + "]");
        final String packageName = packageElement.getQualifiedName().toString();
        final String className = classElement.getSimpleName().toString();
        processingContext.setDefinitionSet(packageName, className);
        String defSetClassName = packageName + "." + className;
        // Description fields.
        processFieldName(classElement, defSetClassName, ANNOTATION_DESCRIPTION,
                processingContext.getDefSetAnnotations().getDescriptionFieldNames(), true);
        // Definitions identifiers.
        DefinitionSet definitionSetAnn = e.getAnnotation(DefinitionSet.class);
        List<? extends TypeMirror> mirrors = null;
        try {//from  w  w w  .ja  v a  2 s  .c o  m
            Class<?>[] defsClasses = definitionSetAnn.definitions();
        } catch (MirroredTypesException mte) {
            mirrors = mte.getTypeMirrors();
        }
        if (null == mirrors) {
            throw new RuntimeException("No graph class class specifyed for the @DefinitionSet.");
        }
        Set<String> defIds = new LinkedHashSet<>();
        for (TypeMirror mirror : mirrors) {
            if (mirror.getKind().equals(TypeKind.DECLARED)) {
                final TypeElement t = (TypeElement) ((DeclaredType) mirror).asElement();
                processingContext.getDefinitionElements().add(t);
            }
            String fqcn = mirror.toString();
            defIds.add(fqcn);
        }
        processingContext.getDefSetAnnotations().getDefinitionIds().addAll(defIds);
        // Builder class.
        processDefinitionSetModelBuilder(e, defSetClassName,
                processingContext.getDefSetAnnotations().getBuilderFieldNames());
        // Graph factory type.
        TypeMirror mirror = null;
        try {
            Class<?> graphClass = definitionSetAnn.graphFactory();
        } catch (MirroredTypeException mte) {
            mirror = mte.getTypeMirror();
        }
        if (null == mirror) {
            throw new RuntimeException("No graph factory class specifyed for the @DefinitionSet.");
        }
        String fqcn = mirror.toString();
        processingContext.getDefSetAnnotations().getGraphFactoryTypes().put(defSetClassName, fqcn);
        // Definition Set's qualifier.
        try {
            Class<?> qualifierClass = definitionSetAnn.qualifier();
        } catch (MirroredTypeException mte) {
            mirror = mte.getTypeMirror();
        }
        if (null == mirror) {
            throw new RuntimeException("No qualifier class specifyed for the @DefinitionSet.");
        }
        processingContext.getDefSetAnnotations().getQualifiers().put(defSetClassName, mirror.toString());
    }
    return true;
}

From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java

private void processMorphProperties(final TypeElement classElement, final String definitionClassName) {
    final Messager messager = processingEnv.getMessager();
    final Elements elementUtils = processingEnv.getElementUtils();
    List<VariableElement> variableElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
    for (VariableElement variableElement : variableElements) {
        if (GeneratorUtils.getAnnotation(elementUtils, variableElement, ANNOTATION_MORPH_PROPERTY) != null) {
            final TypeMirror fieldReturnType = variableElement.asType();
            final String fieldReturnTypeName = GeneratorUtils.getTypeMirrorDeclaredName(fieldReturnType);
            final String fieldName = variableElement.getSimpleName().toString();
            messager.printMessage(Diagnostic.Kind.NOTE,
                    "Discovered Morph Property " + "for class [" + classElement.getSimpleName() + "] "
                            + "at field [" + fieldName + "] " + "of return type [" + fieldReturnTypeName + "]");
            // MorphBase - defaultType
            MorphProperty morphBaseAnn = variableElement.getAnnotation(MorphProperty.class);
            TypeMirror morphDefaultTypeMirror = null;
            try {
                Class<?> defaultTypeClass = morphBaseAnn.binder();
            } catch (MirroredTypeException mte) {
                morphDefaultTypeMirror = mte.getTypeMirror();
            }//from  ww  w  . j  a  v  a  2s .co  m
            if (null == morphDefaultTypeMirror) {
                throw new RuntimeException("No binder class specifyed for the @MorphProperty.");
            }
            String binderClassName = morphDefaultTypeMirror.toString();
            ProcessingMorphProperty morphProperty = new ProcessingMorphProperty(fieldReturnTypeName,
                    StringUtils.capitalize(fieldName), binderClassName);
            List<ProcessingMorphProperty> morphProperties = processingContext.getMorphingAnnotations()
                    .getBaseMorphProperties().get(definitionClassName);
            if (null == morphProperties) {
                morphProperties = new LinkedList<>();
                processingContext.getMorphingAnnotations().getBaseMorphProperties().put(definitionClassName,
                        morphProperties);
            }
            morphProperties.add(morphProperty);
        }
    }
}

From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java

private Map<String, Element> getFieldNames(TypeElement classElement, String annotation) {
    final Messager messager = processingEnv.getMessager();
    final Elements elementUtils = processingEnv.getElementUtils();
    Map<String, Element> result = new LinkedHashMap<>();
    while (!classElement.toString().equals(Object.class.getName())) {
        List<VariableElement> variableElements = ElementFilter.fieldsIn(classElement.getEnclosedElements());
        for (VariableElement variableElement : variableElements) {
            if (GeneratorUtils.getAnnotation(elementUtils, variableElement, annotation) != null) {
                final TypeMirror fieldReturnType = variableElement.asType();
                final TypeElement t = (TypeElement) ((DeclaredType) fieldReturnType).asElement();
                final String fieldReturnTypeName = GeneratorUtils.getTypeMirrorDeclaredName(fieldReturnType);
                final String fieldName = variableElement.getSimpleName().toString();
                result.put(fieldName, t);
                messager.printMessage(Diagnostic.Kind.NOTE,
                        "Discovered property value " + "for class [" + classElement.getSimpleName() + "] "
                                + "at field [" + fieldName + "] " + "of return type [" + fieldReturnTypeName
                                + "]");
            }//from   ww w .  ja  va 2s .  c  o m
        }
        classElement = getParent(classElement);
    }
    return result;
}

From source file:org.kie.workbench.common.stunner.core.processors.MainProcessor.java

private boolean processContainmentRules(final Element e) throws Exception {
    final Messager messager = processingEnv.getMessager();
    final boolean isIface = e.getKind() == ElementKind.INTERFACE;
    final boolean isClass = e.getKind() == ElementKind.CLASS;
    if (isIface || isClass) {
        TypeElement classElement = (TypeElement) e;
        PackageElement packageElement = (PackageElement) classElement.getEnclosingElement();
        messager.printMessage(Diagnostic.Kind.NOTE,
                "Discovered containment rule for class [" + classElement.getSimpleName() + "]");
        final String classNameActivity = classElement.getSimpleName() + RULE_CONTAINMENT_SUFFIX_CLASSNAME;
        generateRuleCode(containmentRuleGenerator, messager, classElement, packageElement, classNameActivity);
    }// w w w . java  2  s.  c o m
    return true;
}