类org.objectweb.asm.TypeReference源码实例Demo

下面列出了怎么用org.objectweb.asm.TypeReference的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Concurnas   文件: CheckClassAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkState();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.CLASS_TYPE_PARAMETER
      && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND
      && sort != TypeReference.CLASS_EXTENDS) {
    throw new IllegalArgumentException(
        "Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码2 项目: Concurnas   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitEndNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.METHOD_TYPE_PARAMETER
      && sort != TypeReference.METHOD_TYPE_PARAMETER_BOUND
      && sort != TypeReference.METHOD_RETURN
      && sort != TypeReference.METHOD_RECEIVER
      && sort != TypeReference.METHOD_FORMAL_PARAMETER
      && sort != TypeReference.THROWS) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码3 项目: Concurnas   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.INSTANCEOF
      && sort != TypeReference.NEW
      && sort != TypeReference.CONSTRUCTOR_REFERENCE
      && sort != TypeReference.METHOD_REFERENCE
      && sort != TypeReference.CAST
      && sort != TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitInsnAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码4 项目: JByteMod-Beta   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc,
    boolean visible) {
  checkStartCode();
  checkEndCode();
  int sort = typeRef >>> 24;
  if (sort != TypeReference.LOCAL_VARIABLE && sort != TypeReference.RESOURCE_VARIABLE) {
    throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
  checkDesc(desc, false);
  if (start == null || end == null || index == null || end.length != start.length || index.length != start.length) {
    throw new IllegalArgumentException("Invalid start, end and index arrays (must be non null and of identical length");
  }
  for (int i = 0; i < start.length; ++i) {
    checkLabel(start[i], true, "start label");
    checkLabel(end[i], true, "end label");
    checkUnsignedShort(index[i], "Invalid variable index");
    int s = labels.get(start[i]).intValue();
    int e = labels.get(end[i]).intValue();
    if (e < s) {
      throw new IllegalArgumentException("Invalid start and end labels (end must be greater than start)");
    }
  }
  return super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, desc, visible);
}
 
源代码5 项目: JReFrameworker   文件: CheckClassAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkState();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.CLASS_TYPE_PARAMETER
      && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND
      && sort != TypeReference.CLASS_EXTENDS) {
    throw new IllegalArgumentException(
        "Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码6 项目: JReFrameworker   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitEndNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.METHOD_TYPE_PARAMETER
      && sort != TypeReference.METHOD_TYPE_PARAMETER_BOUND
      && sort != TypeReference.METHOD_RETURN
      && sort != TypeReference.METHOD_RECEIVER
      && sort != TypeReference.METHOD_FORMAL_PARAMETER
      && sort != TypeReference.THROWS) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码7 项目: JReFrameworker   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.INSTANCEOF
      && sort != TypeReference.NEW
      && sort != TypeReference.CONSTRUCTOR_REFERENCE
      && sort != TypeReference.METHOD_REFERENCE
      && sort != TypeReference.CAST
      && sort != TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitInsnAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码8 项目: JReFrameworker   文件: CheckClassAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkState();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.CLASS_TYPE_PARAMETER
      && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND
      && sort != TypeReference.CLASS_EXTENDS) {
    throw new IllegalArgumentException(
        "Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码9 项目: JReFrameworker   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitEndNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.METHOD_TYPE_PARAMETER
      && sort != TypeReference.METHOD_TYPE_PARAMETER_BOUND
      && sort != TypeReference.METHOD_RETURN
      && sort != TypeReference.METHOD_RECEIVER
      && sort != TypeReference.METHOD_FORMAL_PARAMETER
      && sort != TypeReference.THROWS) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码10 项目: JReFrameworker   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.INSTANCEOF
      && sort != TypeReference.NEW
      && sort != TypeReference.CONSTRUCTOR_REFERENCE
      && sort != TypeReference.METHOD_REFERENCE
      && sort != TypeReference.CAST
      && sort != TypeReference.CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_INVOCATION_TYPE_ARGUMENT
      && sort != TypeReference.CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
      && sort != TypeReference.METHOD_REFERENCE_TYPE_ARGUMENT) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitInsnAnnotation(typeRef, typePath, descriptor, visible));
}
 
@Test
@SuppressWarnings("unchecked")
public void testReceiverTypeTypeAnnotationsRuntimeRetention() throws Exception {
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getReceiverType()).thenReturn(simpleAnnotatedType);
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeReference(TypeReference.METHOD_RECEIVER).getValue(),
            null,
            Type.getDescriptor(AbstractAttributeAppenderTest.Baz.class),
            true);
    verifyNoMoreInteractions(methodVisitor);
    verify(methodDescription).getDeclaredAnnotations();
    verify(methodDescription).getParameters();
    verify(methodDescription).getReturnType();
    verify(methodDescription).getExceptionTypes();
    verify(methodDescription).getTypeVariables();
    verify(methodDescription).getReceiverType();
    verifyNoMoreInteractions(methodDescription);
}
 
@Test
@SuppressWarnings("unchecked")
public void testReceiverTypeTypeAnnotationsClassFileRetention() throws Exception {
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getReceiverType()).thenReturn(simpleAnnotatedType);
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    MethodAttributeAppender.ForInstrumentedMethod.INCLUDING_RECEIVER.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeReference(TypeReference.METHOD_RECEIVER).getValue(),
            null,
            Type.getDescriptor(AbstractAttributeAppenderTest.QuxBaz.class),
            false);
    verifyNoMoreInteractions(methodVisitor);
    verify(methodDescription).getDeclaredAnnotations();
    verify(methodDescription).getParameters();
    verify(methodDescription).getReturnType();
    verify(methodDescription).getExceptionTypes();
    verify(methodDescription).getTypeVariables();
    verify(methodDescription).getReceiverType();
    verifyNoMoreInteractions(methodDescription);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodReturnTypeTypeAnnotationRuntimeRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(simpleAnnotatedType);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeReference(TypeReference.METHOD_RETURN).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodReturnTypeTypeAnnotationClassFileRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(simpleAnnotatedType);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeReference(TypeReference.METHOD_RETURN).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodExceptionTypeTypeAnnotationRuntimeRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Explicit(simpleAnnotatedType));
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newExceptionReference(0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodExceptionTypeTypeAnnotationClassFileRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Explicit(simpleAnnotatedType));
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newExceptionReference(0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationRuntimeRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    ParameterDescription parameterDescription = mock(ParameterDescription.class);
    when(parameterDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(parameterDescription.getType()).thenReturn(simpleAnnotatedType);
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(parameterDescription));
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newFormalParameterReference(0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testMethodParameterTypeTypeAnnotationClassFileRetention() throws Exception {
    when(annotationValueFilter.isRelevant(any(AnnotationDescription.class), any(MethodDescription.InDefinedShape.class))).thenReturn(true);
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    ParameterDescription parameterDescription = mock(ParameterDescription.class);
    when(parameterDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(parameterDescription.getType()).thenReturn(simpleAnnotatedType);
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Explicit<ParameterDescription>(parameterDescription));
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(simpleAnnotatedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newFormalParameterReference(0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testTypeVariableTypeAnnotationRuntimeRetention() throws Exception {
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable));
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.METHOD_TYPE_PARAMETER, 0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.METHOD_TYPE_PARAMETER_BOUND, 0, 0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyZeroInteractions(methodVisitor);
}
 
@Test
@SuppressWarnings("unchecked")
public void testTypeVariableTypeAnnotations() throws Exception {
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(methodDescription.getParameters()).thenReturn((ParameterList) new ParameterList.Empty<ParameterDescription>());
    when(methodDescription.getReturnType()).thenReturn(TypeDescription.Generic.VOID);
    when(methodDescription.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable));
    when(methodDescription.getExceptionTypes()).thenReturn(new TypeList.Generic.Empty());
    when(methodDescription.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    methodAttributeAppender.apply(methodVisitor, methodDescription, annotationValueFilter);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.METHOD_TYPE_PARAMETER, 0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verify(methodVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.METHOD_TYPE_PARAMETER_BOUND, 0, 0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(methodVisitor);
}
 
@Test
public void testSuperClassTypeAnnotationClassFileRetention() throws Exception {
    when(instrumentedType.getTypeVariables()).thenReturn(new TypeList.Generic.Empty());
    when(instrumentedType.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
    when(simpleAnnotatedType.getDeclaredAnnotations())
            .thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(instrumentedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    when(instrumentedType.getSuperClass()).thenReturn(simpleAnnotatedType);
    TypeAttributeAppender.ForInstrumentedType.INSTANCE.apply(classVisitor, instrumentedType, annotationValueFilter);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newSuperTypeReference(-1).getValue(), null, Type.getDescriptor(QuxBaz.class), false);
    verifyNoMoreInteractions(classVisitor);
    verify(instrumentedType).getDeclaredAnnotations();
    verify(instrumentedType).getSuperClass();
    verify(instrumentedType).getInterfaces();
    verify(instrumentedType).getTypeVariables();
    verifyNoMoreInteractions(instrumentedType);
}
 
@Test
public void testTypeVariableTypeAnnotationRuntimeRetention() throws Exception {
    when(instrumentedType.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable));
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(instrumentedType.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
    when(instrumentedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    TypeAttributeAppender.ForInstrumentedType.INSTANCE.apply(classVisitor, instrumentedType, annotationValueFilter);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.CLASS_TYPE_PARAMETER, 0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.CLASS_TYPE_PARAMETER_BOUND, 0, 0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyNoMoreInteractions(classVisitor);
    verify(instrumentedType).getDeclaredAnnotations();
    verify(instrumentedType).getSuperClass();
    verify(instrumentedType).getInterfaces();
    verify(instrumentedType).getTypeVariables();
    verifyNoMoreInteractions(instrumentedType);
}
 
@Test
public void testTypeVariableTypeAnnotations() throws Exception {
    when(instrumentedType.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(annotatedTypeVariable));
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(instrumentedType.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
    when(instrumentedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    TypeAttributeAppender.ForInstrumentedType.INSTANCE.apply(classVisitor, instrumentedType, annotationValueFilter);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.CLASS_TYPE_PARAMETER, 0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.CLASS_TYPE_PARAMETER_BOUND, 0, 0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(classVisitor);
    verify(instrumentedType).getDeclaredAnnotations();
    verify(instrumentedType).getSuperClass();
    verify(instrumentedType).getInterfaces();
    verify(instrumentedType).getTypeVariables();
    verifyNoMoreInteractions(instrumentedType);
}
 
@Test
public void testTypeVariableTypeAnnotationRuntimeRetention() throws Exception {
    when(instrumentedType.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(pseudoType, annotatedTypeVariable));
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new Baz.Instance()));
    when(instrumentedType.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
    when(instrumentedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    new TypeAttributeAppender.ForInstrumentedType.Differentiating(0, 1, 0).apply(classVisitor, instrumentedType, annotationValueFilter);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.CLASS_TYPE_PARAMETER, 1).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.CLASS_TYPE_PARAMETER_BOUND, 1, 0).getValue(),
            null,
            Type.getDescriptor(Baz.class),
            true);
    verifyNoMoreInteractions(classVisitor);
    verify(instrumentedType).getDeclaredAnnotations();
    verify(instrumentedType).getInterfaces();
    verify(instrumentedType).getTypeVariables();
    verifyNoMoreInteractions(instrumentedType);
}
 
@Test
public void testTypeVariableTypeAnnotations() throws Exception {
    when(instrumentedType.getTypeVariables()).thenReturn(new TypeList.Generic.Explicit(pseudoType, annotatedTypeVariable));
    when(annotatedTypeVariable.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(annotatedTypeVariableBound.getDeclaredAnnotations()).thenReturn(new AnnotationList.ForLoadedAnnotations(new QuxBaz.Instance()));
    when(instrumentedType.getInterfaces()).thenReturn(new TypeList.Generic.Empty());
    when(instrumentedType.getDeclaredAnnotations()).thenReturn(new AnnotationList.Empty());
    new TypeAttributeAppender.ForInstrumentedType.Differentiating(0, 1, 0).apply(classVisitor, instrumentedType, annotationValueFilter);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterReference(TypeReference.CLASS_TYPE_PARAMETER, 1).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verify(classVisitor).visitTypeAnnotation(TypeReference.newTypeParameterBoundReference(TypeReference.CLASS_TYPE_PARAMETER_BOUND, 1, 0).getValue(),
            null,
            Type.getDescriptor(QuxBaz.class),
            false);
    verifyNoMoreInteractions(classVisitor);
    verify(instrumentedType).getDeclaredAnnotations();
    verify(instrumentedType).getInterfaces();
    verify(instrumentedType).getTypeVariables();
    verifyNoMoreInteractions(instrumentedType);
}
 
源代码26 项目: Concurnas   文件: CheckFieldAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitEndNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.FIELD) {
    throw new IllegalArgumentException(
        "Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(Opcodes.V1_5, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码27 项目: Concurnas   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitTryCatchAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.EXCEPTION_PARAMETER) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  CheckMethodAdapter.checkDescriptor(version, descriptor, false);
  return new CheckAnnotationAdapter(
      super.visitTryCatchAnnotation(typeRef, typePath, descriptor, visible));
}
 
源代码28 项目: Concurnas   文件: CheckMethodAdapter.java
@Override
public AnnotationVisitor visitLocalVariableAnnotation(
    final int typeRef,
    final TypePath typePath,
    final Label[] start,
    final Label[] end,
    final int[] index,
    final String descriptor,
    final boolean visible) {
  checkVisitCodeCalled();
  checkVisitMaxsNotCalled();
  int sort = new TypeReference(typeRef).getSort();
  if (sort != TypeReference.LOCAL_VARIABLE && sort != TypeReference.RESOURCE_VARIABLE) {
    throw new IllegalArgumentException(INVALID_TYPE_REFERENCE + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRef(typeRef);
  checkDescriptor(version, descriptor, false);
  if (start == null
      || end == null
      || index == null
      || end.length != start.length
      || index.length != start.length) {
    throw new IllegalArgumentException(
        "Invalid start, end and index arrays (must be non null and of identical length");
  }
  for (int i = 0; i < start.length; ++i) {
    checkLabel(start[i], true, START_LABEL);
    checkLabel(end[i], true, END_LABEL);
    checkUnsignedShort(index[i], INVALID_LOCAL_VARIABLE_INDEX);
    int startInsnIndex = labelInsnIndices.get(start[i]).intValue();
    int endInsnIndex = labelInsnIndices.get(end[i]).intValue();
    if (endInsnIndex < startInsnIndex) {
      throw new IllegalArgumentException(
          "Invalid start and end labels (end must be greater than start)");
    }
  }
  return super.visitLocalVariableAnnotation(
      typeRef, typePath, start, end, index, descriptor, visible);
}
 
源代码29 项目: JByteMod-Beta   文件: CheckFieldAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
  checkEnd();
  int sort = typeRef >>> 24;
  if (sort != TypeReference.FIELD) {
    throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
  CheckMethodAdapter.checkDesc(desc, false);
  return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible));
}
 
源代码30 项目: JByteMod-Beta   文件: CheckClassAdapter.java
@Override
public AnnotationVisitor visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
  checkState();
  int sort = typeRef >>> 24;
  if (sort != TypeReference.CLASS_TYPE_PARAMETER && sort != TypeReference.CLASS_TYPE_PARAMETER_BOUND && sort != TypeReference.CLASS_EXTENDS) {
    throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  checkTypeRefAndPath(typeRef, typePath);
  CheckMethodAdapter.checkDesc(desc, false);
  return new CheckAnnotationAdapter(super.visitTypeAnnotation(typeRef, typePath, desc, visible));
}
 
 类所在包
 同包方法