Examples of Messager


Examples of javax.annotation.processing.Messager

        return fo.getName();
    }

    private void validateDAG(final String graphVizFile) throws GenerationException {
        boolean cyclesFound = false;
        final Messager messager = processingEnv.getMessager();
        for (Map.Entry<String, Multimap<String, String>> entry : dagValidation.entrySet()) {
            String payload = entry.getKey();
            Multimap<String, String> dependencies = entry.getValue();
            messager.printMessage(NOTE, "Check cyclic dependencies for action [" + payload + "]");
            DirectedGraph<String, DefaultEdge> dg = new DefaultDirectedGraph<>(DefaultEdge.class);

            // vertices
            for (String store : dependencies.keySet()) {
                dg.addVertex(store);
            }
            for (String store : dependencies.values()) {
                dg.addVertex(store);
            }

            // edges
            for (String store : dependencies.keySet()) {
                Collection<String> storeDependencies = dependencies.get(store);
                for (String storeDependency : storeDependencies) {
                    dg.addEdge(store, storeDependency);
                }
            }

            // cycles?
            CycleDetector<String, DefaultEdge> detector = new CycleDetector<>(dg);
            List<String> cycles = new LinkedList<>(detector.findCycles());
            if (!cycles.isEmpty()) {
                cyclesFound = true;
                StringBuilder cycleInfo = new StringBuilder();
                for (String cycle : cycles) {
                    cycleInfo.append(cycle).append(" -> ");
                }
                cycleInfo.append(cycles.get(0));
                messager.printMessage(ERROR,
                        "Cyclic dependencies detected for action [" + payload + "]: " + cycleInfo);
                messager.printMessage(ERROR, "Please review [" + graphVizFile + "] for more details.");
            }
            if (!cyclesFound) {
                messager.printMessage(NOTE, "No cyclic dependencies found for action [" + payload + "]");
            }
        }
    }
View Full Code Here

Examples of javax.annotation.processing.Messager

    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        if (annotations.isEmpty()) {
            return true;
        }

        Messager messager = processingEnv.getMessager();

        messager.printMessage(Diagnostic.Kind.NOTE, "PathAnnotationProcessor now in processing.");
        try {
            List<PathInfo> pathList = new ArrayList<PathInfo>(annotations.size());
            List<Element> elementList = new ArrayList<Element>();
            for (TypeElement type : annotations) {
                Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(type);
                for (Element target : elements) {
                    Path ann = target.getAnnotation(Path.class);
                    if (target.getKind().isClass()) {
                        TypeElement targetAsTypeElement = (TypeElement) target;
                        pathList.add(new PathInfo(ann, targetAsTypeElement.getQualifiedName().toString()));
                        elementList.add(target);
                    }
                }
            }

            Filer filer = processingEnv.getFiler();

            JAXBContext context = JAXBContext.newInstance(MountPoint.class);
            MountPoint mountPoint = readExistingData(filer, context);

            FileObject file = createXmlFile(filer, messager, elementList);
            setupMountPoint(mountPoint, pathList);
            writeMountPoint(context, file, mountPoint);
        } catch (JAXBException ex) {
            messager.printMessage(Diagnostic.Kind.ERROR, "Can not create a java source file");
            LOGGER.error("Can not create a java source file", ex);
        } catch (IOException ex) {
            messager.printMessage(Diagnostic.Kind.ERROR, "Can not create a java source file");
            LOGGER.error("Can not create a java source file", ex);
        }
        return true;
    }
View Full Code Here

Examples of javax.annotation.processing.Messager

    // ------------------------------------------------------ collect methods

    private void collectData(final RoundEnvironment roundEnv) throws Exception {

        final Messager messager = processingEnv.getMessager();
        final Types typeUtils = processingEnv.getTypeUtils();
        final Elements elementUtils = processingEnv.getElementUtils();

        for (Element e : roundEnv.getElementsAnnotatedWith(Store.class)) {
            TypeElement storeElement = (TypeElement) e;
            PackageElement packageElement = (PackageElement) storeElement.getEnclosingElement();

            final String packageName = packageElement.getQualifiedName().toString();
            final String storeDelegate = storeElement.getSimpleName().toString();
            final boolean changeSupport = typeUtils.isAssignable(storeElement.asType(),
                    elementUtils.getTypeElement(ChangeSupport.class.getName()).asType());
            final String storeClassName = GenerationUtil.storeImplementation(storeDelegate);
            messager.printMessage(NOTE,
                    String.format("Discovered annotated store [%s]", storeElement.getQualifiedName()));

            List<ExecutableElement> processMethods = new ArrayList<>();
            if (findValidProcessMethods(messager, typeUtils, storeElement, processMethods)) {
                Collection<ProcessInfo> processInfos = getProcessInfos(messager, typeUtils, storeElement,
                        processMethods);

                metadata.add(new StoreDelegateMetadata(packageName, storeClassName, storeDelegate, changeSupport,
                        processInfos));
            } else {
                // no valid process methods!
                messager.printMessage(ERROR,
                        String.format("%s does not contain suitable methods annotated with %s.",
                                storeElement.getQualifiedName(), Process.class.getName()));
                break;
            }
        }
View Full Code Here

Examples of javax.annotation.processing.Messager


    // ------------------------------------------------------ generate methods

    private void generateFiles() throws Exception {
        final Messager messager = processingEnv.getMessager();

        // store delegates
        for (StoreDelegateMetadata md : metadata) {
            try {
                messager.printMessage(NOTE, String.format("Generating code for [%s]", md.storeClassName));
                StoreGenerator generator = new StoreGenerator();
                final StringBuffer code = generator.generate(md);
                writeCode(md.packageName, md.storeClassName, code);

                messager.printMessage(NOTE,
                        String.format("Successfully generated store implementation [%s]", md.storeClassName));
            } catch (GenerationException ge) {
                final String msg = ge.getMessage();
                messager.printMessage(Diagnostic.Kind.ERROR, msg/* , storeElement*/);
            }
        }

        // GraphVIZ
        String graphVizFile = writeGraphViz();
View Full Code Here

Examples of javax.annotation.processing.Messager

        String graphVizFile = writeGraphViz();
        validateDAG(graphVizFile);
    }

    private String writeGraphViz() throws GenerationException, IOException {
        final Messager messager = processingEnv.getMessager();
        GraphVizGenerator generator = new GraphVizGenerator();
        StringBuffer code = generator.generate(graphVizInfos.values());
        messager.printMessage(NOTE,
                "Generating GraphViz file to visualize store dependencies [" + GRAPH_VIZ_OUTPUT + "]");
        FileObject fo = processingEnv.getFiler()
                .createResource(StandardLocation.SOURCE_OUTPUT, "", GRAPH_VIZ_OUTPUT);
        Writer w = fo.openWriter();
        BufferedWriter bw = new BufferedWriter(w);
        bw.append(code);
        bw.close();
        w.close();
        messager.printMessage(NOTE, "Successfully generated GraphViz file [" + GRAPH_VIZ_OUTPUT + "]");
        return fo.getName();
    }
View Full Code Here

Examples of javax.annotation.processing.Messager

        return fo.getName();
    }

    private void validateDAG(final String graphVizFile) throws GenerationException {
        boolean cyclesFound = false;
        final Messager messager = processingEnv.getMessager();
        for (Map.Entry<String, Multimap<String, String>> entry : dagValidation.entrySet()) {
            String payload = entry.getKey();
            Multimap<String, String> dependencies = entry.getValue();
            messager.printMessage(NOTE, "Check cyclic dependencies for action [" + payload + "]");
            DirectedGraph<String, DefaultEdge> dg = new DefaultDirectedGraph<>(DefaultEdge.class);

            // vertices
            for (String store : dependencies.keySet()) {
                dg.addVertex(store);
            }
            for (String store : dependencies.values()) {
                dg.addVertex(store);
            }

            // edges
            for (String store : dependencies.keySet()) {
                Collection<String> storeDependencies = dependencies.get(store);
                for (String storeDependency : storeDependencies) {
                    dg.addEdge(store, storeDependency);
                }
            }

            // cycles?
            CycleDetector<String, DefaultEdge> detector = new CycleDetector<>(dg);
            List<String> cycles = new LinkedList<>(detector.findCycles());
            if (!cycles.isEmpty()) {
                cyclesFound = true;
                StringBuilder cycleInfo = new StringBuilder();
                for (String cycle : cycles) {
                    cycleInfo.append(cycle).append(" -> ");
                }
                cycleInfo.append(cycles.get(0));
                messager.printMessage(ERROR,
                        "Cyclic dependencies detected for action [" + payload + "]: " + cycleInfo);
                messager.printMessage(ERROR, "Please review [" + graphVizFile + "] for more details.");
            }
            if (!cyclesFound) {
                messager.printMessage(NOTE, "No cyclic dependencies found for action [" + payload + "]");
            }
        }
    }
View Full Code Here

Examples of javax.annotation.processing.Messager

            }
        } else {
            _verbosity = MANDATORY_WARNING;
        }

        Messager msgr = _pe.getMessager();

        _log = new I18NProcessorMessages(msgr, _locale, _verbosity);
        if (localeError) {
            _log.format(WARNING, ERROR_SETTING_OPTION, _LANGUAGE, locale);
        }
View Full Code Here

Examples of javax.annotation.processing.Messager

        if ( elts.isEmpty() )
        {
            return true;
        }

        final Messager messager = this.processingEnv.getMessager();

        for ( final Kind kind : Kind.values() )
        {
            if ( Kind.ERROR == kind )
            {
                continue;
            }

            System.out.println( "Testing message for: " + kind );
            messager.printMessage( kind, kind + " Test message." );
        }

        return true;
    }
View Full Code Here

Examples of javax.annotation.processing.Messager

  @Override
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    // some utilities
    Elements elementUtils = processingEnv.getElementUtils();
    Messager messager = processingEnv.getMessager();

    // get elements annotated with @Path
    Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(Path.class);
    for (Element element : elements) {
      Path annotation = element.getAnnotation(Path.class);

      // make sure we only work on classes or interfaces @Path annotated
      if (annotation != null && (element.getKind() == ElementKind.CLASS || element.getKind() == ElementKind.INTERFACE)) {
        messager.printMessage(Kind.NOTE, "Generating documentation class for : " + element);
        // extract some names
        Name name = element.getSimpleName();
        PackageElement elementPackage = elementUtils.getPackageOf(element);
        // the javadoc
        String doc = elementUtils.getDocComment(element);
        // build a new class name
        String className = elementPackage.getQualifiedName() + "." + name + "_Doc";
        messager.printMessage(Kind.NOTE, "Class: " + className);
        try {
          // now write the new class which will be compiled in the
          // same run
          JavaFileObject sourceFile = processingEnv.getFiler().createSourceFile(className, element);
          Writer writer = sourceFile.openWriter();
View Full Code Here

Examples of javax.annotation.processing.Messager

*/
@SupportedAnnotationTypes("org.glassfish.admin.rest.composite.RestModelExtension")
public class RestModelExtensionProcessor extends AbstractProcessor {
    @Override
    public boolean process(Set<? extends TypeElement> elements, RoundEnvironment env) {
        Messager messager = processingEnv.getMessager();
        BufferedWriter bw = null;
        try {
            Map<String, List<String>> classes = new HashMap<String, List<String>>();

            for (TypeElement te : elements) {
                for (Element e : env.getElementsAnnotatedWith(te)) {
                    final RestModelExtension annotation = e.getAnnotation(RestModelExtension.class);
                    final String parent = annotation.parent();
                    List<String> list = classes.get(parent);
                    if (list == null) {
                        list = new ArrayList<String>();
                        classes.put(parent, list);
                    }
                    list.add(e.toString());
                }
            }

            if (!classes.isEmpty()) {
                final Filer filer = processingEnv.getFiler();
                FileObject fo = filer.createResource(StandardLocation.CLASS_OUTPUT, "", "META-INF/restmodelextensions");
                bw = new BufferedWriter(fo.openWriter());
                // parent model:model extension
                for (Map.Entry<String, List<String>> entry : classes.entrySet()) {
                    final String key = entry.getKey();
                    for (String ext : entry.getValue()) {
                        bw.write(key + ":" + ext + "\n");
                    }
                }
                bw.close();
            }
        } catch (IOException ex) {
            messager.printMessage(Kind.ERROR, ex.getLocalizedMessage());
            if (bw != null) {
                try {
                    bw.close();
                } catch (Exception e) {
                   
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.