當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。