当前位置: 首页>>代码示例>>Java>>正文


Java ElementType类代码示例

本文整理汇总了Java中java.lang.annotation.ElementType的典型用法代码示例。如果您正苦于以下问题:Java ElementType类的具体用法?Java ElementType怎么用?Java ElementType使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ElementType类属于java.lang.annotation包,在下文中一共展示了ElementType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: use

import java.lang.annotation.ElementType; //导入依赖的package包/类
void use() {
  // this immutable type (package style used)
  ImIncludeTypes.builder().build();
  // included on this type (package style used)
  ImSerializable.builder().build();
  // included on package (package style used)
  ImTicker.builder().read(1).build();

  // included in IncludeNestedTypes
  ImmutableIncludeNestedTypes.Retention retention =
      ImmutableIncludeNestedTypes.Retention.builder()
          .value(RetentionPolicy.CLASS)
          .build();

  // included in IncludeNestedTypes
  ImmutableIncludeNestedTypes.Target target =
      ImmutableIncludeNestedTypes.Target.builder()
          .value(ElementType.CONSTRUCTOR, ElementType.ANNOTATION_TYPE)
          .build();

  // package applied style "copyWith*" test
  // see PackageStyle
  retention.copyWithValue(RetentionPolicy.RUNTIME);
  target.copyWithValue(ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:IncludeTypes.java

示例2: annotationMatchesTarget

import java.lang.annotation.ElementType; //导入依赖的package包/类
static boolean annotationMatchesTarget(Element annotationElement, ElementType elementType) {
  @Nullable Target target = annotationElement.getAnnotation(Target.class);
  if (target != null) {
    ElementType[] targetTypes = target.value();
    if (targetTypes.length == 0) {
      return false;
    }
    boolean found = false;
    for (ElementType t : targetTypes) {
      if (t == elementType) {
        found = true;
      }
    }
    if (!found) {
      return false;
    }
  }
  return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:Annotations.java

示例3: getBuilderAttributeAnnotation

import java.lang.annotation.ElementType; //导入依赖的package包/类
public List<CharSequence> getBuilderAttributeAnnotation() {
  if (containingType.isGenerateJacksonProperties()
      && protoclass().isJacksonDeserialized()) {
    List<CharSequence> jacksonPropertyAnnotation = Annotations.getAnnotationLines(element,
        Collections.singleton(Annotations.JACKSON_PROPERTY),
        false,
        ElementType.METHOD,
        importsResolver,
        nullability);
    List<CharSequence> annotations = Lists.newArrayList();
    if (jacksonPropertyAnnotation.isEmpty()) {
      annotations.add(jacksonPropertyAnnotation());
    }
    annotations.addAll(Annotations.getAnnotationLines(element,
        Collections.<String>emptySet(),
        protoclass().environment().hasJacksonLib(),
        ElementType.METHOD,
        importsResolver,
        nullability));
    return annotations;
  }
  return ImmutableList.of();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:ValueAttribute.java

示例4: extractAnnotationsForElement

import java.lang.annotation.ElementType; //导入依赖的package包/类
private List<CharSequence> extractAnnotationsForElement(ElementType elementType, Set<String> additionalAnnotations) {
  List<CharSequence> allAnnotations = Lists.newArrayListWithCapacity(1);

  boolean dontHaveJsonPropetyAnnotationAlready = Annotations.getAnnotationLines(element,
      Collections.singleton(Annotations.JACKSON_PROPERTY),
      false,
      elementType,
      importsResolver,
      nullability).isEmpty();

  if (dontHaveJsonPropetyAnnotationAlready) {
    allAnnotations.add(jacksonPropertyAnnotation());
  }

  allAnnotations.addAll(
      Annotations.getAnnotationLines(element,
          Sets.union(additionalAnnotations,
              protoclass().styles().style().additionalJsonAnnotationsNames()),
          protoclass().environment().hasJacksonLib(),
          elementType,
          importsResolver,
          nullability));

  return allAnnotations;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:ValueAttribute.java

示例5: ttlOnPropertyLevel

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
public void ttlOnPropertyLevel() throws Exception {
	Map<String, Object> settings = new HashMap<String, Object>();

	TestHelper.configureOptionsFor( settings, Redis.class )
			.associationStorage( AssociationStorageType.ASSOCIATION_DOCUMENT )
			.entity( Cloud.class )
			.property( "backupSnowFlakes", ElementType.METHOD )
			.ttl( 1, TimeUnit.DAYS );

	setupSessionFactory( settings );
	createCloudWithTwoProducedAndOneBackupSnowflake();

	// property-level options are applied to the type as well.
	// not sure, whether this is a good idea.
	assertThat( cloudTtl() ).isGreaterThan( TimeUnit.HOURS.toMillis( 23 ) )
			.isLessThanOrEqualTo( TimeUnit.HOURS.toMillis( 24 ) );

	assertThat( associationTtl() ).isGreaterThan( TimeUnit.HOURS.toMillis( 23 ) )
			.isLessThanOrEqualTo( TimeUnit.HOURS.toMillis( 24 ) );
}
 
开发者ID:hibernate,项目名称:hibernate-ogm-redis,代码行数:22,代码来源:TTLConfiguredProgrammaticallyTest.java

示例6: buildTemplateConstraint

import java.lang.annotation.ElementType; //导入依赖的package包/类
private JDefinedClass buildTemplateConstraint(String name) {
    try {
        JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
        tplConstraint.annotate(Documented.class);
        tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
        tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
        
        // Using direct as I don't know how to build default { } with code model
        tplConstraint.direct("\n" + "    Class<?>[] groups() default {};\n" + "    String message() default \"Invalid value\";\n" + "    Class<? extends Payload>[] payload() default {};\n");
        
        // Hack to force the import of javax.validation.Payload
        tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
        
        return tplConstraint;
    } catch (JClassAlreadyExistsException e) {
        throw new RuntimeException("Tried to create an already existing class: " + name, e);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:19,代码来源:Jsr303Annotator.java

示例7: testGetEnumInvalid

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
public void testGetEnumInvalid() {
    args.put("key", "CONSTRUCTOR");
    Set<ElementType> all = EnumSet.noneOf(ElementType.class);
    all.add(ElementType.FIELD);
    all.add(ElementType.METHOD);
    System.out.print(all);
    try {
        ctx.getEnum("key", all);
        fail("IllegalArgumentException expected.");
    } catch (IllegalArgumentException e) {
        assertEquals(
                "Invalid parameter value 'CONSTRUCTOR' for key. Valid values are [FIELD, METHOD].",
                e.getMessage());
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:17,代码来源:CommandContextTest.java

示例8: visitClassAnnotation

import java.lang.annotation.ElementType; //导入依赖的package包/类
/**
 * Inspects a class annotation.
 *
 * @param cf {@code non-null;} class file
 * @param ann {@code non-null;} annotation
 */
private void visitClassAnnotation(DirectClassFile cf,
        BaseAnnotations ann) {

    if (!args.eTypes.contains(ElementType.TYPE)) {
        return;
    }

    for (Annotation anAnn : ann.getAnnotations().getAnnotations()) {
        String annClassName
                = anAnn.getType().getClassType().getClassName();
        if (args.aclass.equals(annClassName)) {
            printMatch(cf);
        }
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:22,代码来源:AnnotationLister.java

示例9: testConstraintViolationExceptionParameter

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
public void testConstraintViolationExceptionParameter() {
	final Wine bean = new Wine();
	final Set<ConstraintViolation<?>> violations = new LinkedHashSet<>();

	final ConstraintHelper helper = new ConstraintHelper();

	final ConstraintDescriptor<NotEmpty> notEmptyNameDescriptor = new ConstraintDescriptorImpl<>(helper, (Member) null,
			getAnnotation("name", NotEmpty.class), ElementType.FIELD);
	PathImpl path = PathImpl.createPathFromString("name");
	violations.add(ConstraintViolationImpl.<Wine> forParameterValidation("name-Empty", null, null, "interpolated", Wine.class, bean, new Object(),
			"value", path, notEmptyNameDescriptor, ElementType.PARAMETER, null, null));
	path.addParameterNode("parameter1", 0);

	final ConstraintViolationException violationException = Mockito.mock(ConstraintViolationException.class);
	Mockito.when(violationException.getConstraintViolations()).thenReturn(violations);

	final ValidationJsonException validationJsonException = new ValidationJsonException(violationException);
	Assert.assertFalse(validationJsonException.getErrors().isEmpty());
	Assert.assertEquals("{parameter1=[{rule=name-Empty}]}", validationJsonException.getErrors().toString());
}
 
开发者ID:ligoj,项目名称:bootstrap,代码行数:22,代码来源:ValidationJsonExceptionTest.java

示例10: getAnnotationTargets

import java.lang.annotation.ElementType; //导入依赖的package包/类
public Set<ElementType> getAnnotationTargets(JvmAnnotationType annotation) {
	EList<JvmAnnotationReference> annotations = annotation.getAnnotations();
	for (JvmAnnotationReference annoRef : annotations) {
		if (Target.class.getName().equals(annoRef.getAnnotation().getIdentifier())) {
			EList<JvmAnnotationValue> values = annoRef.getValues();
			JvmAnnotationValue value = values.isEmpty() ? null : values.get(0);
			if (value instanceof JvmEnumAnnotationValue) {
				Set<ElementType> result = newHashSet();
				for (JvmEnumerationLiteral elementType : ((JvmEnumAnnotationValue) value).getValues()) {
					final String simpleName = elementType.getSimpleName();
					result.add(ElementType.valueOf(simpleName));
				}
				return result;
			}
		}
	}
	return emptySet();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:XAnnotationUtil.java

示例11: toName

import java.lang.annotation.ElementType; //导入依赖的package包/类
/** Return simple name representation of this type declaration. */
public Name toName() {
  String packageName = "";
  if (getCompilationUnit() != null) {
    packageName = getCompilationUnit().getPackageName();
  }
  List<String> simpleNames = new ArrayList<>();
  TypeDeclaration current = this;
  while (current != null) {
    simpleNames.add(0, current.getName());
    current = current.getEnclosingDeclaration();
  }
  Name name = new Name(packageName, simpleNames);
  name.getModifiers().addAll(getModifiers());
  name.setTarget(ElementType.TYPE);
  return name;
}
 
开发者ID:sormuras,项目名称:listing,代码行数:18,代码来源:TypeDeclaration.java

示例12: of

import java.lang.annotation.ElementType; //导入依赖的package包/类
/** Create new Name based on the array of Strings, with the first denoting the package name. */
public static Name of(String... names) {
  requireNonNull(names, "names");
  if (names.length == 0) {
    throw new IllegalArgumentException("non-empty names array expected");
  }
  List<String> simples = new ArrayList<>(Arrays.asList(names));
  Iterator<String> iterator = simples.iterator();
  String packageName = iterator.next();
  iterator.remove();
  if (!simples.stream().allMatch(SourceVersion::isIdentifier)) {
    throw new IllegalArgumentException("non-name in: " + simples);
  }
  Name name = new Name(packageName, simples);
  if (names.length == 1) {
    name.setTarget(ElementType.PACKAGE);
  } else if (names.length == 2) {
    name.setTarget(ElementType.TYPE);
  }
  return name;
}
 
开发者ID:sormuras,项目名称:listing,代码行数:22,代码来源:Name.java

示例13: singleStaticImport

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
void singleStaticImport() throws Exception {
  Member micros = TimeUnit.class.getField("MICROSECONDS");
  Name parameter = Name.of("java.lang.annotation", "ElementType", "PARAMETER");

  parameter.setTarget(ElementType.FIELD);
  parameter.setModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL);
  check(
      imports ->
          imports
              .addSingleStaticImport(Thread.State.NEW)
              .addSingleStaticImport(micros)
              .addSingleStaticImport(parameter),
      "import static java.lang.Thread.State.NEW;",
      "import static java.lang.annotation.ElementType.PARAMETER;",
      "import static java.util.concurrent.TimeUnit.MICROSECONDS;");
}
 
开发者ID:sormuras,项目名称:listing,代码行数:18,代码来源:ImportDeclarationsTest.java

示例14: simple

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
void simple() {
  assertEquals("int i", MethodParameter.of(int.class, "i").list());
  assertEquals("int... ia1", MethodParameter.of(int[].class, "ia1").setVariable(true).list());
  assertEquals("int[]... ia2", MethodParameter.of(int[][].class, "ia2").setVariable(true).list());
  MethodParameter parameter =
      new MethodParameter().setType(new TypeVariable()).setName("t").setFinal(true);
  parameter.addAnnotation(new Annotation(Name.of("", "A")));
  assertEquals("final @A T t", parameter.list());
  assertEquals(ElementType.PARAMETER, new MethodParameter().getAnnotationTarget());
  IllegalStateException expected =
      expectThrows(
          IllegalStateException.class,
          () -> MethodParameter.of(int.class, "i").setVariable(true));
  assertEquals(true, expected.toString().contains("array type expected"));
}
 
开发者ID:sormuras,项目名称:listing,代码行数:17,代码来源:MethodParameterTest.java

示例15: testToString

import java.lang.annotation.ElementType; //导入依赖的package包/类
@Test
void testToString() {
  assertEquals("Name{a.b.X, target=Optional[TYPE], modifiers=[]}", of("a.b", "X").toString());
  testToString(of(Object.class), "java.lang.Object", "public");
  testToString(of(byte.class), "byte", "public, abstract, final");
  testToString(of(Object[].class), "Object[]", "public, abstract, final");
  testToString(of(Object[][].class), "Object[][]", "public, abstract, final");
  testToString(of(Name.class), Name.class.getCanonicalName(), "public");
  testToString(of(Character.Subset.class), "java.lang.Character.Subset", "public, static");
  testToString(of(Thread.State.class), "java.lang.Thread.State", "public, static, final");
  testToString(
      of(Thread.State.NEW),
      "java.lang.Thread.State.NEW",
      ElementType.FIELD,
      "public, static, final");
  testToString(NormalClassDeclaration.of("Abc").toName(), "Abc", "");
  testToString(CompilationUnit.of("abc").declareClass("Abc").toName(), "abc.Abc", "");
}
 
开发者ID:sormuras,项目名称:listing,代码行数:19,代码来源:NameTest.java


注:本文中的java.lang.annotation.ElementType类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。