All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kohsuke.stapler.jelly.AnnotationProcessorImpl Maven / Gradle / Ivy

The newest version!
/*******************************************************************************
 *
 * Copyright (c) 2004-2010 Oracle Corporation.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors: 
 *
 *    Kohsuke Kawaguchi
 *     
 *******************************************************************************/ 

package org.kohsuke.stapler.jelly;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.lang.model.element.Modifier;
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.DeclaredType;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.ElementFilter;
import javax.tools.Diagnostic.Kind;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author Kohsuke Kawaguchi
 */
@SuppressWarnings({"Since15"})
//@MetaInfServices(Processor.class)
public class AnnotationProcessorImpl extends AbstractProcessor {
    private final Map missingViews = new HashMap();

    private static class MissingViews extends HashSet {}

    @Override
    public Set getSupportedAnnotationTypes() {
        return Collections.singleton("*");
    }

    @Override
    public boolean process(Set annotations, RoundEnvironment roundEnv) {
        if (roundEnv.processingOver())      return false;

        missingViews.clear();
        for (TypeElement t : ElementFilter.typesIn(roundEnv.getRootElements())) {
            check(t);
        }
        missingViews.clear();
        return false;
    }

    private MissingViews check(TypeElement t) {
        MissingViews r = missingViews.get(t);
        if (r==null) {
            r = new MissingViews();
            missingViews.put(t,r);

            r.addAll(check(t.getSuperclass()));
            for (TypeMirror i : t.getInterfaces())
                r.addAll(check(i));

            RequiresView a = t.getAnnotation(RequiresView.class);
            if (a!=null)
                r.addAll(Arrays.asList(a.value()));

            if (!r.isEmpty() && !t.getModifiers().contains(Modifier.ABSTRACT)) {
                processingEnv.getMessager().printMessage(Kind.ERROR, t.getQualifiedName()+" is missing views: "+r,t);
            }
        }
        return r;
    }

    private MissingViews check(TypeMirror t) {
        if (t.getKind()== TypeKind.DECLARED)
            return check((TypeElement)((DeclaredType)t).asElement());
        return EMPTY;
    }

    private static final MissingViews EMPTY = new MissingViews();
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy