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

ch.powerunit.extensions.matchers.provideprocessor.ProvidesMatchersElementVisitor Maven / Gradle / Ivy

Go to download

This is a test framework for the JDK 1.8 - Extension to provide matchers based on annotation. - Factory Support

There is a newer version: 0.1.6
Show newest version
package ch.powerunit.extensions.matchers.provideprocessor;

import java.util.Optional;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.util.SimpleElementVisitor8;
import javax.tools.Diagnostic.Kind;

class ProvidesMatchersElementVisitor extends SimpleElementVisitor8, Void>
		implements RoundMirrorSupport {

	private final RoundMirror roundMirror;

	public ProvidesMatchersElementVisitor(RoundMirror roundMirror) {
		this.roundMirror = roundMirror;
	}

	@Override
	public Optional visitType(TypeElement e, Void p) {
		switch (e.getKind()) {
		case ENUM:
			warningForType(e, "enum");
			return Optional.empty();
		case INTERFACE:
			warningForType(e, "interface");
			return Optional.empty();
		default:
			return Optional.of(e);
		}
	}

	@Override
	protected Optional defaultAction(Element e, Void p) {
		warningForType(e, "unexpected element");
		return Optional.empty();
	}

	private void warningForType(Element e, String type) {
		roundMirror.getProcessingEnv().getMessager().printMessage(Kind.MANDATORY_WARNING,
				"The annotation `ProvideMatchers` is used on an " + type + ", which is not supported", e,
				roundMirror.getProvideMatchersAnnotation(e));
	}

	@Override
	public RoundMirror getRoundMirror() {
		return roundMirror;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy