< prev index next >

test/langtools/tools/javac/processing/model/element/TestElementKindPredicates.java

Print this page




  24 /*
  25  * @test
  26  * @bug 8222430
  27  * @summary Test various predicates of ElementKind.
  28  */
  29 
  30 import java.util.Set;
  31 import java.util.function.Predicate;
  32 import javax.lang.model.element.ElementKind;
  33 
  34 /**
  35  * Test the isClass, isField, and isInterface predicates of ElementKind.
  36  */
  37 public class TestElementKindPredicates {
  38     public static void main(String... args) {
  39         Set<ElementKind> ALL_KINDS = Set.of(ElementKind.values());
  40 
  41         // isClass: Returns true if this is a kind of class: either CLASS or ENUM.
  42         test(ALL_KINDS,
  43              (ElementKind k) -> Set.of(ElementKind.CLASS,
  44                                        ElementKind.ENUM).contains(k),

  45              (ElementKind k) -> k.isClass(), "isClass");
  46 
  47         // isField: Returns true if this is a kind of field: either FIELD or ENUM_CONSTANT.
  48         test(ALL_KINDS,
  49              (ElementKind k) -> Set.of(ElementKind.FIELD,
  50                                        ElementKind.ENUM_CONSTANT).contains(k),
  51              (ElementKind k) -> k.isField(), "isField");
  52 
  53         // isInterface: Returns true if this is a kind of interface: either INTERFACE or ANNOTATION_TYPE.
  54         test(ALL_KINDS,
  55              (ElementKind k) -> Set.of(ElementKind.INTERFACE,
  56                                        ElementKind.ANNOTATION_TYPE).contains(k),
  57              (ElementKind k) -> k.isInterface(), "isInterface");
  58     }
  59 
  60     private static void test(Set<ElementKind> kinds,
  61                              Predicate<ElementKind> expectedPred,
  62                              Predicate<ElementKind> actualPred,
  63                              String errorMessage) {
  64         for(ElementKind kind : kinds) {


  24 /*
  25  * @test
  26  * @bug 8222430
  27  * @summary Test various predicates of ElementKind.
  28  */
  29 
  30 import java.util.Set;
  31 import java.util.function.Predicate;
  32 import javax.lang.model.element.ElementKind;
  33 
  34 /**
  35  * Test the isClass, isField, and isInterface predicates of ElementKind.
  36  */
  37 public class TestElementKindPredicates {
  38     public static void main(String... args) {
  39         Set<ElementKind> ALL_KINDS = Set.of(ElementKind.values());
  40 
  41         // isClass: Returns true if this is a kind of class: either CLASS or ENUM.
  42         test(ALL_KINDS,
  43              (ElementKind k) -> Set.of(ElementKind.CLASS,
  44                                        ElementKind.ENUM,
  45                                        ElementKind.RECORD).contains(k),
  46              (ElementKind k) -> k.isClass(), "isClass");
  47 
  48         // isField: Returns true if this is a kind of field: either FIELD or ENUM_CONSTANT.
  49         test(ALL_KINDS,
  50              (ElementKind k) -> Set.of(ElementKind.FIELD,
  51                                        ElementKind.ENUM_CONSTANT).contains(k),
  52              (ElementKind k) -> k.isField(), "isField");
  53 
  54         // isInterface: Returns true if this is a kind of interface: either INTERFACE or ANNOTATION_TYPE.
  55         test(ALL_KINDS,
  56              (ElementKind k) -> Set.of(ElementKind.INTERFACE,
  57                                        ElementKind.ANNOTATION_TYPE).contains(k),
  58              (ElementKind k) -> k.isInterface(), "isInterface");
  59     }
  60 
  61     private static void test(Set<ElementKind> kinds,
  62                              Predicate<ElementKind> expectedPred,
  63                              Predicate<ElementKind> actualPred,
  64                              String errorMessage) {
  65         for(ElementKind kind : kinds) {
< prev index next >