本文整理匯總了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);
}
}
示例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;
}
};
}
示例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;
}
示例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
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
}
示例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());
}
}
示例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);
}
示例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;
}
}
示例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());
}
}
示例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();
}