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


Java Inherited类代码示例

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


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

示例1: getAnnotation

import java.lang.annotation.Inherited; //导入依赖的package包/类
private static <A extends Annotation> A getAnnotation(Class<?> type, Class<A> annotationType, boolean checkType) {
    A annotation;
    if (checkType) {
        annotation = type.getAnnotation(annotationType);
        if (annotation != null) {
            return annotation;
        }
    }

    if (annotationType.getAnnotation(Inherited.class) != null) {
        for (Class<?> anInterface : type.getInterfaces()) {
            annotation = getAnnotation(anInterface, annotationType, true);
            if (annotation != null) {
                return annotation;
            }
        }
    }

    if (type.isInterface() || type.equals(Object.class)) {
        return null;
    } else {
        return getAnnotation(type.getSuperclass(), annotationType, false);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:25,代码来源:JavaReflectionUtil.java

示例2: predicateClassAnnotatedWith

import java.lang.annotation.Inherited; //导入依赖的package包/类
public static Predicate<Class<?>> predicateClassAnnotatedWith(
    final Class<? extends Annotation> annotation) {
  if (!annotation.isAnnotationPresent(Inherited.class)) {
    return predicateAnnotatedWith(annotation);
  }

  return new Predicate<Class<?>>() {
    @Override
    public boolean apply(Class<?> c) {
      while (c != null) {
        if (c.isAnnotationPresent(annotation)) {
          return true;
        }
        c = c.getSuperclass();
      }
      return false;
    }
  };
}
 
开发者ID:wangyuntao,项目名称:reflect,代码行数:20,代码来源:Utils.java

示例3: getAnnotation

import java.lang.annotation.Inherited; //导入依赖的package包/类
/**
 * An internal-use utility that creates a reified annotation.
 * This overloaded version take annotation inheritance into account.
 */
public static <A extends Annotation> A getAnnotation(ClassSymbol annotated,
                                                     Class<A> annoType) {
    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    A result = null;
    while (annotated.name != annotated.name.table.names.java_lang_Object) {
        result = getAnnotation((Symbol)annotated, annoType);
        if (result != null || !inherited)
            break;
        Type sup = annotated.getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous())
            break;
        annotated = (ClassSymbol) sup.tsym;
    }
    return result;
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:20,代码来源:JavacElements.java

示例4: getAllReflectionClasses

import java.lang.annotation.Inherited; //导入依赖的package包/类
private void getAllReflectionClasses() throws NotFoundException{

		//System annotations
		addClassIfNotExists(typeOracle.getType(Retention.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
		addClassIfNotExists(typeOracle.getType(Documented.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
		addClassIfNotExists(typeOracle.getType(Inherited.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
		addClassIfNotExists(typeOracle.getType(Target.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
		addClassIfNotExists(typeOracle.getType(Deprecated.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
		//typeOracle.getType("org.lirazs.gbackbone.client.test.reflection.TestReflectionGenerics.TestReflection1");
		
		//=====GWT0.7
		for (JClassType classType : typeOracle.getTypes()) {
			Reflectable reflectable = GenUtils.getClassTypeAnnotationWithMataAnnotation(classType, Reflectable.class);
			if (reflectable != null){
				processClass(classType, reflectable);
				
				if (reflectable.assignableClasses()){
					for (JClassType type : classType.getSubtypes()){
						processClass(type, reflectable);
					}
				}
			}
		}
		//======end of gwt0.7
	}
 
开发者ID:liraz,项目名称:gwt-backbone,代码行数:26,代码来源:ReflectAllInOneCreator.java

示例5: getAnnotation

import java.lang.annotation.Inherited; //导入依赖的package包/类
/**
 * An internal-use utility that creates a reified annotation.
 * This overloaded version take annotation inheritance into account.
 */
public static <A extends Annotation> A getAnnotation(ClassSymbol annotated,
                                                     Class<A> annoType) {
    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    A result = null;
    while (annotated.name != annotated.name.table.java_lang_Object) {
        result = getAnnotation((Symbol)annotated, annoType);
        if (result != null || !inherited)
            break;
        Type sup = annotated.getSuperclass();
        if (sup.tag != TypeTags.CLASS || sup.isErroneous())
            break;
        annotated = (ClassSymbol) sup.tsym;
    }
    return result;
}
 
开发者ID:unktomi,项目名称:form-follows-function,代码行数:20,代码来源:JavacElements.java

示例6: indexSupertypes

import java.lang.annotation.Inherited; //导入依赖的package包/类
/**
 * Index super types for {@link IndexSubclasses} and any {@link IndexAnnotated}
 * additionally accompanied by {@link Inherited}.
 */
private void indexSupertypes(TypeElement rootElement, TypeElement element) throws IOException {

	for (TypeMirror mirror : types.directSupertypes(element.asType())) {
		if (mirror.getKind() != TypeKind.DECLARED) {
			continue;
		}

		DeclaredType superType = (DeclaredType) mirror;
		TypeElement superTypeElement = (TypeElement) superType.asElement();
		storeSubclass(superTypeElement, rootElement);

		for (AnnotationMirror annotationMirror : superTypeElement.getAnnotationMirrors()) {
			TypeElement annotationElement = (TypeElement) annotationMirror.getAnnotationType()
					.asElement();

			if (hasAnnotation(annotationElement, Inherited.class)) {
				storeAnnotation(annotationElement, rootElement);
			}
		}

		indexSupertypes(rootElement, superTypeElement);
	}
}
 
开发者ID:soklet,项目名称:soklet,代码行数:28,代码来源:ClassIndexProcessor.java

示例7: apply

import java.lang.annotation.Inherited; //导入依赖的package包/类
@Nonnull
@Override
public List<String> apply(@Nonnull AnalysisContext analysisContext) {
    List<String> inheritedAnnotations = newArrayList();
    ClassPool classPool = classPoolAccessorFor(analysisContext).getClassPool();
    for (String annotation : getAnnotationsFoundInClassPath(analysisContext)) {
        CtClass annotationClazz = classPool.getOrNull(annotation);
        if (annotationClazz == null) {
            logger.debug("Annotation [{}] cannot be found on the class path; skipping detection", annotation);
            continue;
        }
        try {
            if (annotationClazz.getAnnotation(Inherited.class) != null) {
                inheritedAnnotations.add(annotation);
            }
        } catch (ClassNotFoundException e) {
            logger.debug("@Inherited is not available; this is quite disturbing.");
        }
    }
    logger.debug("Found those inheritable annotations: {}", inheritedAnnotations);
    return inheritedAnnotations;
}
 
开发者ID:ImmobilienScout24,项目名称:deadcode4j,代码行数:23,代码来源:AnnotationsAnalyzer.java

示例8: getAnnotations

import java.lang.annotation.Inherited; //导入依赖的package包/类
private static Set<org.kie.soup.project.datamodel.oracle.Annotation> getAnnotations( final java.lang.annotation.Annotation[] annotations,
                                                                                            boolean checkInheritance ) {
    final Set<org.kie.soup.project.datamodel.oracle.Annotation> fieldAnnotations = new LinkedHashSet<>();
    for ( java.lang.annotation.Annotation a : annotations ) {

        if ( checkInheritance ) {
            if ( !a.annotationType().isAnnotationPresent( Inherited.class ) ) {
                continue;
            }
        }

        final org.kie.soup.project.datamodel.oracle.Annotation fieldAnnotation = new org.kie.soup.project.datamodel.oracle.Annotation( a.annotationType().getName() );
        for ( Method m : a.annotationType().getDeclaredMethods() ) {
            final String methodName = m.getName();
            fieldAnnotation.addParameter( methodName, getAnnotationAttributeValue( a, methodName ) );
        }
        fieldAnnotations.add( fieldAnnotation );
    }
    return fieldAnnotations;
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:21,代码来源:AnnotationUtils.java

示例9: addConstructor

import java.lang.annotation.Inherited; //导入依赖的package包/类
public void addConstructor(Constructor<?> constructor) throws Exception {
    List<Type> paramTypes = new ArrayList<Type>();
    for (Class<?> paramType : constructor.getParameterTypes()) {
        paramTypes.add(Type.getType(paramType));
    }
    String methodDescriptor = Type.getMethodDescriptor(VOID_TYPE, paramTypes.toArray(EMPTY_TYPES));

    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, signature(constructor), EMPTY_STRINGS);

    for (Annotation annotation : constructor.getDeclaredAnnotations()) {
        if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
            continue;
        }
        Retention retention = annotation.annotationType().getAnnotation(Retention.class);
        AnnotationVisitor annotationVisitor = methodVisitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), retention != null && retention.value() == RetentionPolicy.RUNTIME);
        annotationVisitor.visitEnd();
    }

    methodVisitor.visitCode();

    // this.super(p0 .. pn)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    for (int i = 0; i < constructor.getParameterTypes().length; i++) {
        methodVisitor.visitVarInsn(Type.getType(constructor.getParameterTypes()[i]).getOpcode(Opcodes.ILOAD), i + 1);
    }
    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>", methodDescriptor, false);

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:32,代码来源:AsmBackedClassGenerator.java

示例10: includeNotInheritedAnnotations

import java.lang.annotation.Inherited; //导入依赖的package包/类
private void includeNotInheritedAnnotations() {
    for (Annotation annotation : type.getDeclaredAnnotations()) {
        if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
            continue;
        }
        Retention retention = annotation.annotationType().getAnnotation(Retention.class);
        boolean visible = retention != null && retention.value() == RetentionPolicy.RUNTIME;
        AnnotationVisitor annotationVisitor = visitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), visible);
        visitAnnotationValues(annotation, annotationVisitor);
        annotationVisitor.visitEnd();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:AsmBackedClassGenerator.java

示例11: assertGoodTesterAnnotation

import java.lang.annotation.Inherited; //导入依赖的package包/类
private static void assertGoodTesterAnnotation(
    Class<? extends Annotation> annotationClass) {
  assertNotNull(
      rootLocaleFormat("%s must be annotated with @TesterAnnotation.",
          annotationClass),
      annotationClass.getAnnotation(TesterAnnotation.class));
  final Retention retentionPolicy =
      annotationClass.getAnnotation(Retention.class);
  assertNotNull(
      rootLocaleFormat("%s must have a @Retention annotation.", annotationClass),
      retentionPolicy);
  assertEquals(
      rootLocaleFormat("%s must have RUNTIME RetentionPolicy.", annotationClass),
      RetentionPolicy.RUNTIME, retentionPolicy.value());
  assertNotNull(
      rootLocaleFormat("%s must be inherited.", annotationClass),
      annotationClass.getAnnotation(Inherited.class));

  for (String propertyName : new String[]{"value", "absent"}) {
    Method method = null;
    try {
      method = annotationClass.getMethod(propertyName);
    } catch (NoSuchMethodException e) {
      fail(rootLocaleFormat("%s must have a property named '%s'.",
          annotationClass, propertyName));
    }
    final Class<?> returnType = method.getReturnType();
    assertTrue(rootLocaleFormat("%s.%s() must return an array.",
        annotationClass, propertyName),
        returnType.isArray());
    assertSame(rootLocaleFormat("%s.%s() must return an array of %s.",
        annotationClass, propertyName, annotationClass.getDeclaringClass()),
        annotationClass.getDeclaringClass(), returnType.getComponentType());
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:36,代码来源:FeatureEnumTest.java

示例12: getAttribute

import java.lang.annotation.Inherited; //导入依赖的package包/类
@Override
protected <A extends Annotation> Attribute.Compound getAttribute(final Class<A> annoType) {

    Attribute.Compound attrib = super.getAttribute(annoType);

    boolean inherited = annoType.isAnnotationPresent(Inherited.class);
    if (attrib != null || !inherited)
        return attrib;

    // Search supertypes
    ClassSymbol superType = getSuperClassToSearchForAnnotations();
    return superType == null ? null
                             : superType.getAttribute(annoType);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:15,代码来源:Symbol.java

示例13: initializeAnnotations

import java.lang.annotation.Inherited; //导入依赖的package包/类
private void initializeAnnotations() {
	if (lazyAnnotations != null) {
		return;
	}

	if (parent != null) {
		lazyAnnotations = new HashMap<Class<?>, Annotation>();
		// ((Annotations)parent).initializeAnnotations();
		// for (Entry<Class<?>, Annotation> entry :
		// ((Annotations)parent).lazyAnnotations.entrySet()) {
		// if
		// (entry.getValue().annotationType().isAnnotationPresent(Inherited.class))
		// {
		// lazyAnnotations.put(entry.getKey(), entry.getValue());
		// }
		// }

		for (Annotation a : parent.getAnnotations()) {
			if (ClassHelper.AsClass(a.annotationType())
					.isAnnotationPresent(Inherited.class)) {
				lazyAnnotations.put(a.annotationType(), a);
			}
		}

		lazyAnnotations.putAll(declaredAnnotations);
	} else {
		lazyAnnotations = declaredAnnotations;
	}
}
 
开发者ID:liraz,项目名称:gwt-backbone,代码行数:30,代码来源:Annotations.java

示例14: assertGoodTesterAnnotation

import java.lang.annotation.Inherited; //导入依赖的package包/类
private static void assertGoodTesterAnnotation(
    Class<? extends Annotation> annotationClass) {
  assertNotNull(
      String.format("%s must be annotated with @TesterAnnotation.",
          annotationClass),
      annotationClass.getAnnotation(TesterAnnotation.class));
  final Retention retentionPolicy =
      annotationClass.getAnnotation(Retention.class);
  assertNotNull(
      String.format("%s must have a @Retention annotation.", annotationClass),
      retentionPolicy);
  assertEquals(
      String.format("%s must have RUNTIME RetentionPolicy.", annotationClass),
      RetentionPolicy.RUNTIME, retentionPolicy.value());
  assertNotNull(
      String.format("%s must be inherited.", annotationClass),
      annotationClass.getAnnotation(Inherited.class));

  for (String propertyName : new String[]{"value", "absent"}) {
    Method method = null;
    try {
      method = annotationClass.getMethod(propertyName);
    } catch (NoSuchMethodException e) {
      fail(String.format("%s must have a property named '%s'.",
          annotationClass, propertyName));
    }
    final Class<?> returnType = method.getReturnType();
    assertTrue(String.format("%s.%s() must return an array.",
        annotationClass, propertyName),
        returnType.isArray());
    assertSame(String.format("%s.%s() must return an array of %s.",
        annotationClass, propertyName, annotationClass.getDeclaringClass()),
        annotationClass.getDeclaringClass(), returnType.getComponentType());
  }
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:36,代码来源:FeatureEnumTest.java

示例15: addConstructor

import java.lang.annotation.Inherited; //导入依赖的package包/类
public void addConstructor(Constructor<?> constructor) throws Exception {
    List<Type> paramTypes = new ArrayList<Type>();
    for (Class<?> paramType : constructor.getParameterTypes()) {
        paramTypes.add(Type.getType(paramType));
    }
    String methodDescriptor = Type.getMethodDescriptor(Type.VOID_TYPE, paramTypes.toArray(
            new Type[paramTypes.size()]));

    MethodVisitor methodVisitor = visitor.visitMethod(Opcodes.ACC_PUBLIC, "<init>", methodDescriptor, signature(constructor), new String[0]);

    for (Annotation annotation : constructor.getDeclaredAnnotations()) {
        if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
            continue;
        }
        Retention retention = annotation.annotationType().getAnnotation(Retention.class);
        AnnotationVisitor annotationVisitor = methodVisitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), retention != null && retention.value() == RetentionPolicy.RUNTIME);
        annotationVisitor.visitEnd();
    }

    methodVisitor.visitCode();

    // this.super(p0 .. pn)
    methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
    for (int i = 0; i < constructor.getParameterTypes().length; i++) {
        methodVisitor.visitVarInsn(Type.getType(constructor.getParameterTypes()[i]).getOpcode(Opcodes.ILOAD), i + 1);
    }
    methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, superclassType.getInternalName(), "<init>",
            methodDescriptor);

    methodVisitor.visitInsn(Opcodes.RETURN);
    methodVisitor.visitMaxs(0, 0);
    methodVisitor.visitEnd();
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:34,代码来源:AsmBackedClassGenerator.java


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