Java 8 ElementKind - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ElementKind class.

This code example shows how to use the following methods:ordinal
import javax.lang.model.util.SimpleTypeVisitor6;
 
/** 
 * Utilities for handling types in annotation processors 
 */ 
final class Util { 
  private Util() { 
  } 
 
  public static PackageElement getPackage(Element type) {
    while (type.getKind() != ElementKind.PACKAGE) {
      type = type.getEnclosingElement();
    } 
    return (PackageElement) type;
  } 
 
  /** 
   * Returns the supertype, or {@code null} if the supertype is a platform 
   * class. This is intended for annotation processors that assume platform 
   * classes will never be annotated with application annotations. 
5
CodeRank
This code example shows how to use the following methods:ordinal
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.TypeParameterElement;
import javax.lang.model.type.TypeMirror;
 
class TypeSummary implements Renderable { 
 
  private String summary;
 
  public TypeSummary(RenderableTypes renderables, TypeElement element) {
    StringBuilder builder = new StringBuilder();
 
    appendTypeSignature(builder, element);
 
    Set<String> nestedTypes = new TreeSet<>();
    Set<String> contained = new TreeSet<>();
    // Ordering matters for enum constants. 
    Set<String> enumValues = new LinkedHashSet<>();
 
    // Collect the enclosed elements, keeping enclosed types separately. 
5
CodeRank
This code example shows how to use the following methods:ordinal
 * Evaluates usage of the ErraiUI DataField annotation and emits errors and warnings when 
 * the annotation is not being used correctly. 
 */ 
@SupportedAnnotationTypes(TypeNames.BOUND) 
@SupportedSourceVersion(SourceVersion.RELEASE_6)
public class BoundAnnotationChecker extends AbstractProcessor {
 
  @Override 
  public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    final Types types = processingEnv.getTypeUtils();
    final Elements elements = processingEnv.getElementUtils();
    final TypeMirror gwtWidgetType = elements.getTypeElement(TypeNames.GWT_WIDGET).asType();
    final TypeMirror gwtElementType = elements.getTypeElement(TypeNames.GWT_ELEMENT).asType();
 
    Map<TypeElement, List<Element>> classesWithBoundThings = new HashMap<TypeElement, List<Element>>();
    for (TypeElement annotation : annotations) {
      for (Element target : roundEnv.getElementsAnnotatedWith(annotation)) {
        TypeMirror targetType;
        if (target.getKind() == ElementKind.METHOD) {
          targetType = ((ExecutableElement) target).getReturnType();
4
CodeRank
This code example shows how to use the following methods:ordinal
 * @since 3.3 
 */ 
@SupportedAnnotationTypes("*") 
@SupportedSourceVersion(SourceVersion.RELEASE_6)
@SupportedOptions("org.eclipse.jdt.compiler.apt.tests.processors.messager.MessagerProc") 
public class MessagerProc extends AbstractProcessor {
	 
	private static final String CLASSNAME = MessagerProc.class.getName();
	 
	/** 
	 * Report an error to the test case code.   
	 * This is not the same as reporting via Messager!  Use this if some API fails. 
	 * @param value will be displayed in the test output, in the event of failure. 
	 * Can be anything except "succeeded". 
	 */ 
	public static void reportError(String value) {
		// Uncomment for processor debugging - don't report error 
		// value = "succeeded"; 
		System.setProperty(CLASSNAME, value);
	} 
4
CodeRank
This code example shows how to use the following methods:ordinal
 * </ul> 
 * 
 * @author Sam Harwell 
 */ 
@SupportedAnnotationTypes({NullUsageProcessor.NotNullClassName, NullUsageProcessor.NullableClassName})
public class NullUsageProcessor extends AbstractProcessor {
	public static final String NotNullClassName = "org.antlr.v4.runtime.misc.NotNull";
	public static final String NullableClassName = "org.antlr.v4.runtime.misc.Nullable";
 
	private TypeElement notNullType;
	private TypeElement nullableType;
 
	public NullUsageProcessor() { 
	} 
 
	@Override 
	public SourceVersion getSupportedSourceVersion() {
		SourceVersion latestSupported = SourceVersion.latestSupported();
 
		if (latestSupported.ordinal() <= 6) {
3
CodeRank
This code example shows how to use the following methods:ordinal
import javax.lang.model.element.TypeElement;
import javax.lang.model.type.TypeKind;
import javax.lang.model.type.TypeMirror;
 
 
public class ElementExt implements Element
{ 
	protected final Element e;
 
	protected ElementExt(Element e)
	{ 
		this.e = e;
	} 
 
	@Override 
	public TypeMirror asType()
	{ 
		return e.asType();
	} 
 
3
CodeRank
This code example shows how to use the following methods:equals
		} 
	} 
 
	@Override 
	public AnnotationMetaAttribute visitExecutable(ExecutableType t, Element p) {
		if ( !p.getKind().equals( ElementKind.METHOD ) ) {
			return null; 
		} 
 
		String string = p.getSimpleName().toString();
		if ( !StringUtil.isPropertyName( string ) ) {
			return null; 
		} 
 
		TypeMirror returnType = t.getReturnType();
		return returnType.accept( this, p );
	} 
 
	private boolean isBasicAttribute(Element element, Element returnedElement) {
		if ( TypeUtils.containsAnnotation( element, Constants.BASIC )
4
CodeRank
This code example shows how to use the following methods:equals
        return ""; 
    } 
 
    /** Returns true if the given element is a package */ 
    public static boolean isPackage(Element elem) {
        return elem.getKind().equals(ElementKind.PACKAGE);
    } 
 
    /** Returns true if the given element is a package */ 
    public static boolean isPublicOrProtectedMethod(Element elem) {
        return isMethod(elem) && !elem.getModifiers().contains(PRIVATE);
    } 
 
    /** 
     * Get the method parameters in the form of 
     * "type1", "name1", "type2", "name2", etc... 
     */ 
    public static List<String> formatParameters(ExecutableElement method, boolean useFinal) {
        List<String> out = new ArrayList<String>();
        for (VariableElement var : method.getParameters()) {
3
CodeRank
This code example shows how to use the following methods:equals
		return Optional.of((TypeElement)e);
	} 
 
	public static boolean isTopLevelType(Element e)
	{ 
		if (!ElementKind.CLASS.equals(e.getKind()))
		{ 
			return false; 
		} 
 
		TypeElement te = (TypeElement)e;
		if (!NestingKind.TOP_LEVEL.equals(te.getNestingKind()))
		{ 
			return false; 
		} 
 
		return true; 
	} 
} 
3
CodeRank
See Code Examples for Java 8 ElementKind Methods: