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


Java AnnotationMirror类代码示例

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


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

示例1: getJoinColumns

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
public static List<JoinColumn> getJoinColumns(final AnnotationModelHelper helper, Map<String, ? extends AnnotationMirror> annByType) {
    final List<JoinColumn> result = new ArrayList<JoinColumn>();
    AnnotationMirror joinColumnAnn = annByType.get("javax.persistence.JoinColumn"); // NOI18N
    if (joinColumnAnn != null) {
        result.add(new JoinColumnImpl(helper, joinColumnAnn));
    } else {
        AnnotationMirror joinColumnsAnnotation = annByType.get("javax.persistence.JoinColumns"); // NOI18N
        if (joinColumnsAnnotation != null) {
            AnnotationParser jcParser = AnnotationParser.create(helper);
            jcParser.expectAnnotationArray("value", helper.resolveType("javax.persistence.JoinColumn"), new ArrayValueHandler() { // NOI18N
                public Object handleArray(List<AnnotationValue> arrayMembers) {
                    for (AnnotationValue arrayMember : arrayMembers) {
                        AnnotationMirror joinColumnAnnotation = (AnnotationMirror)arrayMember.getValue();
                        result.add(new JoinColumnImpl(helper, joinColumnAnnotation));
                    }
                    return null;
                }
            }, null);
            jcParser.parse(joinColumnsAnnotation);
        }
    }
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:EntityMappingsUtilities.java

示例2: testScanAnnotationsOnFields

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
public void testScanAnnotationsOnFields() throws Exception {
    final AnnotationModelHelper helper = AnnotationModelHelper.create(createClasspathInfoForScanningAnnotations());
    final Set<String> elements = new HashSet<String>();
    
    helper.runJavaSourceTask(new Callable<Void>() {
        public Void call() throws InterruptedException {
            helper.getAnnotationScanner().findAnnotations(
                    "javax.annotation.Resource",
                    EnumSet.of(ElementKind.FIELD),
                    new AnnotationHandler() {
                        public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotationMirror) {
                            assertEquals("foo.MyClass", typeElement.getQualifiedName().toString());
                            elements.add(element.getSimpleName().toString());
                        }
                    });
            return null;
        }
    });
    assertEquals(1, elements.size());
    assertTrue(elements.contains("myDS"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:AnnotationScannerTest.java

示例3: getAllAnnotations

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
/**
 * Gets all the annotations on the given declaration.
 */
private Annotation[] getAllAnnotations(Element decl, Locatable srcPos) {
    List<Annotation> r = new ArrayList<Annotation>();

    for( AnnotationMirror m : decl.getAnnotationMirrors() ) {
        try {
            String fullName = ((TypeElement) m.getAnnotationType().asElement()).getQualifiedName().toString();
            Class<? extends Annotation> type =
                SecureLoader.getClassClassLoader(getClass()).loadClass(fullName).asSubclass(Annotation.class);
            Annotation annotation = decl.getAnnotation(type);
            if(annotation!=null)
                r.add( LocatableAnnotation.create(annotation,srcPos) );
        } catch (ClassNotFoundException e) {
            // just continue
        }
    }

    return r.toArray(new Annotation[r.size()]);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:InlineAnnotationReaderImpl.java

示例4: ManyToManyImpl

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
public ManyToManyImpl(final AnnotationModelHelper helper, final Element element, AnnotationMirror manyToManyAnnotation, String name, Map<String, ? extends AnnotationMirror> annByType) {
    this.name = name;
    AnnotationParser parser = AnnotationParser.create(helper);
    parser.expectClass("targetEntity", new DefaultProvider() { // NOI18N
        public Object getDefaultValue() {
            return EntityMappingsUtilities.getCollectionArgumentTypeName(helper, element);
        }
    });
    parser.expectEnumConstantArray("cascade", helper.resolveType("javax.persistence.CascadeType"), new ArrayValueHandler() { // NOI18N
        public Object handleArray(List<AnnotationValue> arrayMembers) {
            return new CascadeTypeImpl(arrayMembers);
        }
    }, parser.defaultValue(new CascadeTypeImpl()));
    parser.expectEnumConstant("fetch", helper.resolveType("javax.persistence.FetchType"), parser.defaultValue("LAZY")); // NOI18N
    parser.expectString("mappedBy", parser.defaultValue("")); // NOI18N
    parseResult = parser.parse(manyToManyAnnotation);

    joinTable = new JoinTableImpl(helper, annByType.get("javax.persistence.JoinTable")); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:ManyToManyImpl.java

示例5: isDaggerRequired

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
private boolean isDaggerRequired( @Nonnull final TypeElement typeElement,
                                  @Nullable final AnnotationMirror scopeAnnotation )
{
  final VariableElement daggerParameter = (VariableElement)
    ProcessorUtil.getAnnotationValue( processingEnv.getElementUtils(),
                                      typeElement,
                                      Constants.COMPONENT_ANNOTATION_CLASSNAME,
                                      "dagger" ).getValue();
  switch ( daggerParameter.getSimpleName().toString() )
  {
    case "ENABLE":
      return true;
    case "DISABLE":
      return false;
    default:
      return null != scopeAnnotation &&
             null != processingEnv.getElementUtils().getTypeElement( Constants.DAGGER_MODULE_CLASSNAME );
  }
}
 
开发者ID:arez,项目名称:arez,代码行数:20,代码来源:ArezProcessor.java

示例6: testScanAnnotationsOnMethods

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
public void testScanAnnotationsOnMethods() throws Exception {
    final AnnotationModelHelper helper = AnnotationModelHelper.create(createClasspathInfoForScanningAnnotations());
    final Set<String> elements = new HashSet<String>();
    
    helper.runJavaSourceTask(new Callable<Void>() {
        public Void call() throws InterruptedException {
            helper.getAnnotationScanner().findAnnotations(
                    "javax.annotation.Resource",
                    EnumSet.of(ElementKind.METHOD),
                    new AnnotationHandler() {
                        public void handleAnnotation(TypeElement typeElement, Element element, AnnotationMirror annotationMirror) {
                            assertEquals("foo.YourClass", typeElement.getQualifiedName().toString());
                            elements.add(element.getSimpleName().toString());
                        }
                    });
            return null;
        }
    });
    assertEquals(1, elements.size());
    assertTrue(elements.contains("setYourDataSource"));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:AnnotationScannerTest.java

示例7: supplyFor

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
@Override
public MethodSpec supplyFor(final AnnotationMirror anno) {
	final CodeBlock body = CodeBlock
			.builder()
			.addStatement(
					"return $T.getColorStateList($N(), $L)",
					AndroidClassNames.CONTEXT_COMPAT,
					CallerDef.GET_CONTEXT,
					getLiteralFromAnnotation(anno, "resId"))
			.build();

	return getBaseMethodSpec()
			.returns(AndroidClassNames.COLOR_STATE_LIST)
			.addCode(body)
			.build();
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:17,代码来源:GetDefaultMethodGenerator.java

示例8: OneToOneImpl

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
public OneToOneImpl(final AnnotationModelHelper helper, final Element element, AnnotationMirror oneToOneAnnotation, String name, Map<String, ? extends AnnotationMirror> annByType) {
    this.name = name;
    AnnotationParser parser = AnnotationParser.create(helper);
    parser.expectClass("targetEntity", new DefaultProvider() { // NOI18N
        public Object getDefaultValue() {
            return EntityMappingsUtilities.getElementTypeName(element);
        }
    });
    parser.expectEnumConstantArray("cascade", helper.resolveType("javax.persistence.CascadeType"), new ArrayValueHandler() { // NOI18N
        public Object handleArray(List<AnnotationValue> arrayMembers) {
            return new CascadeTypeImpl(arrayMembers);
        }
    }, parser.defaultValue(new CascadeTypeImpl()));
    parser.expectEnumConstant("fetch", helper.resolveType("javax.persistence.FetchType"), parser.defaultValue("EAGER")); // NOI18N
    parser.expectPrimitive("optional", Boolean.class, parser.defaultValue(true)); // NOI18N
    parser.expectString("mappedBy", parser.defaultValue("")); // NOI18N
    parseResult = parser.parse(oneToOneAnnotation);

    joinTable = new JoinTableImpl(helper, annByType.get("javax.persistence.JoinTable")); // NOI18N
    joinColumnList = EntityMappingsUtilities.getJoinColumns(helper, annByType);
    pkJoinColumnList = EntityMappingsUtilities.getPrimaryKeyJoinColumns(helper, annByType);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:OneToOneImpl.java

示例9: findAnnotationValueAsBoolean

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
private static Boolean findAnnotationValueAsBoolean(Element fieldElement, String[] fieldAnnotationFqns, String annotationKey) {
    Boolean isFieldXable = null;
    for (int i = 0; i < fieldAnnotationFqns.length; i++) {
        String fieldAnnotationFqn = fieldAnnotationFqns[i];
        AnnotationMirror fieldAnnotation = JpaControllerUtil.findAnnotation(fieldElement, fieldAnnotationFqn); //NOI18N
        if (fieldAnnotation != null) {  
            String annotationValueString = JpaControllerUtil.findAnnotationValueAsString(fieldAnnotation, annotationKey); //NOI18N
            if (annotationValueString != null) {
                isFieldXable = Boolean.valueOf(annotationValueString);
            }
            else {
                isFieldXable = Boolean.TRUE;
            }
            break;
        }
    }
    return isFieldXable;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:JpaControllerUtil.java

示例10: testGenerateFor_defaultToBooleanAnnotationSupplied

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
@Test
public void testGenerateFor_defaultToBooleanAnnotationSupplied() {
	final Element element = avatarRule.getElementWithUniqueId("boolean");
	final AnnotationMirror mirror = AnnotationMirrorHelper.getAnnotationMirror(element, DefaultToBoolean.class);

	final MethodSpec generatedMethod = generator.generateFor(mirror);

	assertThat(generatedMethod, is(notNullValue()));
	checkMethodSignature(generatedMethod, ClassName.BOOLEAN.box());
	checkCompiles(generatedMethod);
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:12,代码来源:TestGetDefaultMethodGenerator.java

示例11: supplyFor

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
@Override
public MethodSpec supplyFor(final AnnotationMirror useAnno, final int position) {
	return getBaseMethodSpec(position)
			.returns(Object.class)
			.addCode(CodeBlock
					.builder()
					.addStatement("return null")
					.build())
			.build();
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:11,代码来源:GetPlaceholderMethodGenerator.java

示例12: addOnStale

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
private void addOnStale( @Nonnull final AnnotationMirror annotation, @Nonnull final ExecutableElement method )
  throws ArezProcessorException
{
  final String name =
    deriveHookName( method,
                    ComputedDescriptor.ON_STALE_PATTERN,
                    "Stale",
                    getAnnotationParameter( annotation, "name" ) );
  findOrCreateComputed( name ).setOnStale( method );
}
 
开发者ID:arez,项目名称:arez,代码行数:11,代码来源:ComponentDescriptor.java

示例13: buildAnnotations

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
private ImmutableSet<String> buildAnnotations(ExecutableElement element) {
  ImmutableSet.Builder<String> builder = ImmutableSet.builder();

  List<? extends AnnotationMirror> annotations = element.getAnnotationMirrors();
  for (AnnotationMirror annotation : annotations) {
    builder.add(annotation.getAnnotationType()
        .asElement()
        .getSimpleName()
        .toString());
  }

  return builder.build();
}
 
开发者ID:hzsweers,项目名称:inspector,代码行数:14,代码来源:Property.java

示例14: checkElement

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
@Override
public Result checkElement(final ExecutableElement element) {
	if (!ValueHandlerAnnoRetriever.hasAnnotation(element)) {
		return Result.createSuccessful();
	}

	final AnnotationMirror anno = ValueHandlerAnnoRetriever.getAnnotation(element);

	final MethodSpec supplier = getValueMethodGenerator.generateFor(anno);
	final TypeMirror suppliedType = returnTypeToTypeMirror(supplier);
	final TypeMirror recipientType = getParameterWithoutUseAnnotation(element).asType();

	if (!isAssignableOrConvertible(suppliedType, recipientType)) {
		return Result.createFailure(
				"Misused handler annotation found. \'%1$s\' cannot be cast to \'%2$s\'.",
				suppliedType,
				recipientType);
	}

	return Result.createSuccessful();
}
 
开发者ID:MatthewTamlin,项目名称:Spyglass,代码行数:22,代码来源:TypeValidator.java

示例15: copyDocumentedAnnotations

import javax.lang.model.element.AnnotationMirror; //导入依赖的package包/类
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
                                       @Nonnull final MethodSpec.Builder builder )
{
  for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
  {
    final DeclaredType annotationType = annotation.getAnnotationType();
    if ( !annotationType.toString().startsWith( "react4j.annotations." ) &&
         null != annotationType.asElement().getAnnotation( Documented.class ) )
    {
      builder.addAnnotation( AnnotationSpec.get( annotation ) );
    }
  }
}
 
开发者ID:react4j,项目名称:react4j,代码行数:14,代码来源:ProcessorUtil.java


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