001package ball.annotation.processing;
002/*-
003 * ##########################################################################
004 * Utilities
005 * $Id: AntTaskAttributeConstraintProcessor.java 5898 2020-05-08 18:37:19Z ball $
006 * $HeadURL: svn+ssh://svn.hcf.dev/var/spool/scm/repository.svn/ball-util/trunk/src/main/java/ball/annotation/processing/AntTaskAttributeConstraintProcessor.java $
007 * %%
008 * Copyright (C) 2008 - 2020 Allen D. Ball
009 * %%
010 * Licensed under the Apache License, Version 2.0 (the "License");
011 * you may not use this file except in compliance with the License.
012 * You may obtain a copy of the License at
013 *
014 *      http://www.apache.org/licenses/LICENSE-2.0
015 *
016 * Unless required by applicable law or agreed to in writing, software
017 * distributed under the License is distributed on an "AS IS" BASIS,
018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
019 * See the License for the specific language governing permissions and
020 * limitations under the License.
021 * ##########################################################################
022 */
023import ball.annotation.ServiceProviderFor;
024import ball.util.ant.taskdefs.AntTaskAttributeConstraint;
025import ball.util.ant.taskdefs.NotEmpty;
026import ball.util.ant.taskdefs.NotNull;
027import javax.annotation.processing.Processor;
028import javax.annotation.processing.RoundEnvironment;
029import javax.lang.model.element.Element;
030import javax.lang.model.element.ExecutableElement;
031import javax.lang.model.element.TypeElement;
032import lombok.NoArgsConstructor;
033import lombok.ToString;
034
035import static javax.tools.Diagnostic.Kind.ERROR;
036
037/**
038 * {@link AntTaskAttributeConstraint} {@link Processor}
039 *
040 * @author {@link.uri mailto:ball@hcf.dev Allen D. Ball}
041 * @version $Revision: 5898 $
042 */
043@ServiceProviderFor({ Processor.class })
044@For({ AntTaskAttributeConstraint.class, NotEmpty.class, NotNull.class })
045@NoArgsConstructor @ToString
046public class AntTaskAttributeConstraintProcessor extends AnnotatedProcessor {
047    @Override
048    public void process(RoundEnvironment roundEnv,
049                        TypeElement annotation, Element element) {
050        super.process(roundEnv, annotation, element);
051
052        switch (element.getKind()) {
053        case ANNOTATION_TYPE:
054        case FIELD:
055        default:
056            break;
057
058        case METHOD:
059            if (! isGetterMethod((ExecutableElement) element)) {
060                print(ERROR, element,
061                      "@%s: %s is not a property getter",
062                      annotation.getSimpleName(), element.getKind());
063            }
064            break;
065        }
066    }
067}