org.objectweb.asm.TypePath Java Examples

The following examples show how to use org.objectweb.asm.TypePath. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@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));
}
 
Example #2
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Prints a disassembled view of the given type annotation.
 *
 * @param typeRef
 *          a reference to the annotated type. See {@link TypeReference}.
 * @param typePath
 *          the path to the annotated type argument, wildcard bound, array
 *          element type, or static inner type within 'typeRef'. May be
 *          <tt>null</tt> if the annotation targets 'typeRef' as a whole.
 * @param desc
 *          the class descriptor of the annotation class.
 * @param visible
 *          <tt>true</tt> if the annotation is visible at runtime.
 * @return a visitor to visit the annotation values.
 */
public Textifier visitTypeAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
  buf.setLength(0);
  buf.append(tab).append('@');
  appendDescriptor(FIELD_DESCRIPTOR, desc);
  buf.append('(');
  text.add(buf.toString());
  Textifier t = createTextifier();
  text.add(t.getText());
  buf.setLength(0);
  buf.append(") : ");
  appendTypeReference(typeRef);
  buf.append(", ").append(typePath);
  buf.append(visible ? "\n" : " // invisible\n");
  text.add(buf.toString());
  return t;
}
 
Example #3
Source File: LocalVariablesSorter.java    From Concurnas with MIT License 6 votes vote down vote up
@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) {
  Type type = Type.getType(descriptor);
  int[] remappedIndex = new int[index.length];
  for (int i = 0; i < remappedIndex.length; ++i) {
    remappedIndex[i] = remap(index[i], type);
  }
  return super.visitLocalVariableAnnotation(
      typeRef, typePath, start, end, remappedIndex, descriptor, visible);
}
 
Example #4
Source File: MethodRemapper.java    From JReFrameworker with MIT License 6 votes vote down vote up
@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) {
  AnnotationVisitor annotationVisitor =
      super.visitLocalVariableAnnotation(
          typeRef, typePath, start, end, index, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? annotationVisitor
      : new AnnotationRemapper(api, annotationVisitor, remapper);
}
 
Example #5
Source File: MethodRemapper.java    From Concurnas with MIT License 6 votes vote down vote up
@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) {
  AnnotationVisitor annotationVisitor =
      super.visitLocalVariableAnnotation(
          typeRef, typePath, start, end, index, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? annotationVisitor
      : new AnnotationRemapper(api, annotationVisitor, remapper);
}
 
Example #6
Source File: MethodNode.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public AnnotationVisitor visitTryCatchAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  TryCatchBlockNode tryCatchBlock = tryCatchBlocks.get((typeRef & 0x00FFFF00) >> 8);
  TypeAnnotationNode typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor);
  if (visible) {
    if (tryCatchBlock.visibleTypeAnnotations == null) {
      tryCatchBlock.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    tryCatchBlock.visibleTypeAnnotations.add(typeAnnotation);
  } else {
    if (tryCatchBlock.invisibleTypeAnnotations == null) {
      tryCatchBlock.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    tryCatchBlock.invisibleTypeAnnotations.add(typeAnnotation);
  }
  return typeAnnotation;
}
 
Example #7
Source File: Textifier.java    From Concurnas with MIT License 6 votes vote down vote up
/**
 * Prints a disassembled view of the given type annotation.
 *
 * @param typeRef a reference to the annotated type. See {@link TypeReference}.
 * @param typePath the path to the annotated type argument, wildcard bound, array element type, or
 *     static inner type within 'typeRef'. May be {@literal null} if the annotation targets
 *     'typeRef' as a whole.
 * @param descriptor the class descriptor of the annotation class.
 * @param visible {@literal true} if the annotation is visible at runtime.
 * @return a visitor to visit the annotation values.
 */
public Textifier visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  stringBuilder.setLength(0);
  stringBuilder.append(tab).append('@');
  appendDescriptor(FIELD_DESCRIPTOR, descriptor);
  stringBuilder.append('(');
  text.add(stringBuilder.toString());

  stringBuilder.setLength(0);
  stringBuilder.append(") : ");
  appendTypeReference(typeRef);
  stringBuilder.append(", ").append(typePath);
  stringBuilder.append(visible ? "\n" : INVISIBLE);
  return addNewTextifier(stringBuilder.toString());
}
 
Example #8
Source File: RemappingMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@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) {
  AnnotationVisitor annotationVisitor =
      super.visitLocalVariableAnnotation(
          typeRef, typePath, start, end, index, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? annotationVisitor
      : new RemappingAnnotationAdapter(annotationVisitor, remapper);
}
 
Example #9
Source File: MethodNode.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@Override
public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc,
    boolean visible) {
  LocalVariableAnnotationNode an = new LocalVariableAnnotationNode(typeRef, typePath, getLabelNodes(start), getLabelNodes(end), index, desc);
  if (visible) {
    if (visibleLocalVariableAnnotations == null) {
      visibleLocalVariableAnnotations = new ArrayList<LocalVariableAnnotationNode>(1);
    }
    visibleLocalVariableAnnotations.add(an);
  } else {
    if (invisibleLocalVariableAnnotations == null) {
      invisibleLocalVariableAnnotations = new ArrayList<LocalVariableAnnotationNode>(1);
    }
    invisibleLocalVariableAnnotations.add(an);
  }
  return an;
}
 
Example #10
Source File: Textifier.java    From JByteMod-Beta with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Printer visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
  buf.setLength(0);
  buf.append(tab2).append("TRYCATCHBLOCK @");
  appendDescriptor(FIELD_DESCRIPTOR, desc);
  buf.append('(');
  text.add(buf.toString());
  Textifier t = createTextifier();
  text.add(t.getText());
  buf.setLength(0);
  buf.append(") : ");
  appendTypeReference(typeRef);
  buf.append(", ").append(typePath);
  buf.append(visible ? "\n" : " // invisible\n");
  text.add(buf.toString());
  return t;
}
 
Example #11
Source File: CheckMethodAdapter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@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));
}
 
Example #12
Source File: LocalVariablesSorter.java    From JReFrameworker with MIT License 6 votes vote down vote up
@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) {
  Type type = Type.getType(descriptor);
  int[] remappedIndex = new int[index.length];
  for (int i = 0; i < remappedIndex.length; ++i) {
    remappedIndex[i] = remap(index[i], type);
  }
  return super.visitLocalVariableAnnotation(
      typeRef, typePath, start, end, remappedIndex, descriptor, visible);
}
 
Example #13
Source File: ClassNode.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  TypeAnnotationNode typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor);
  if (visible) {
    if (visibleTypeAnnotations == null) {
      visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    visibleTypeAnnotations.add(typeAnnotation);
  } else {
    if (invisibleTypeAnnotations == null) {
      invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    invisibleTypeAnnotations.add(typeAnnotation);
  }
  return typeAnnotation;
}
 
Example #14
Source File: MethodNode.java    From JReFrameworker with MIT License 6 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  // Find the last real instruction, i.e. the instruction targeted by this annotation.
  AbstractInsnNode currentInsn = instructions.getLast();
  while (currentInsn.getOpcode() == -1) {
    currentInsn = currentInsn.getPrevious();
  }
  // Add the annotation to this instruction.
  TypeAnnotationNode typeAnnotation = new TypeAnnotationNode(typeRef, typePath, descriptor);
  if (visible) {
    if (currentInsn.visibleTypeAnnotations == null) {
      currentInsn.visibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    currentInsn.visibleTypeAnnotations.add(typeAnnotation);
  } else {
    if (currentInsn.invisibleTypeAnnotations == null) {
      currentInsn.invisibleTypeAnnotations = new ArrayList<TypeAnnotationNode>(1);
    }
    currentInsn.invisibleTypeAnnotations.add(typeAnnotation);
  }
  return typeAnnotation;
}
 
Example #15
Source File: MethodConstantsCollector.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
  cp.newUTF8(desc);
  if (visible) {
    cp.newUTF8("RuntimeVisibleTypeAnnotations");
  } else {
    cp.newUTF8("RuntimeInvisibleTypeAnnotations");
  }
  return new AnnotationConstantsCollector(mv.visitAnnotation(desc, visible), cp);
}
 
Example #16
Source File: DalvikStatsTool.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitLocalVariableAnnotation(
    int typeRef,
    TypePath typePath,
    Label[] start,
    Label[] end,
    int[] index,
    String desc,
    boolean visible) {
  return annotationVisitor;
}
 
Example #17
Source File: Textifier.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public Printer visitLocalVariableAnnotation(
    final int typeRef,
    final TypePath typePath,
    final Label[] start,
    final Label[] end,
    final int[] index,
    final String descriptor,
    final boolean visible) {
  stringBuilder.setLength(0);
  stringBuilder.append(tab2).append("LOCALVARIABLE @");
  appendDescriptor(FIELD_DESCRIPTOR, descriptor);
  stringBuilder.append('(');
  text.add(stringBuilder.toString());

  stringBuilder.setLength(0);
  stringBuilder.append(") : ");
  appendTypeReference(typeRef);
  stringBuilder.append(", ").append(typePath);
  for (int i = 0; i < start.length; ++i) {
    stringBuilder.append(" [ ");
    appendLabel(start[i]);
    stringBuilder.append(" - ");
    appendLabel(end[i]);
    stringBuilder.append(" - ").append(index[i]).append(" ]");
  }
  stringBuilder.append(visible ? "\n" : INVISIBLE);
  return addNewTextifier(stringBuilder.toString());
}
 
Example #18
Source File: RemappingFieldAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  AnnotationVisitor annotationVisitor =
      super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? null
      : new RemappingAnnotationAdapter(annotationVisitor, remapper);
}
 
Example #19
Source File: MethodRemapper.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  AnnotationVisitor annotationVisitor =
      super.visitInsnAnnotation(typeRef, typePath, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? annotationVisitor
      : new AnnotationRemapper(api, annotationVisitor, remapper);
}
 
Example #20
Source File: TraceMethodVisitor.java    From Concurnas with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  Printer annotationPrinter = p.visitInsnAnnotation(typeRef, typePath, descriptor, visible);
  return new TraceAnnotationVisitor(
      super.visitInsnAnnotation(typeRef, typePath, descriptor, visible), annotationPrinter);
}
 
Example #21
Source File: TraceClassVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  Printer annotationPrinter = p.visitClassTypeAnnotation(typeRef, typePath, descriptor, visible);
  return new TraceAnnotationVisitor(
      super.visitTypeAnnotation(typeRef, typePath, descriptor, visible), annotationPrinter);
}
 
Example #22
Source File: CheckFieldAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@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));
}
 
Example #23
Source File: RemappingMethodAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  AnnotationVisitor annotationVisitor =
      super.visitInsnAnnotation(typeRef, typePath, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? annotationVisitor
      : new RemappingAnnotationAdapter(annotationVisitor, remapper);
}
 
Example #24
Source File: RemappingMethodAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(
    int typeRef, TypePath typePath, String desc, boolean visible) {
  AnnotationVisitor av =
      super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible);
  return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
}
 
Example #25
Source File: RemappingFieldAdapter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitTypeAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  AnnotationVisitor annotationVisitor =
      super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(descriptor), visible);
  return annotationVisitor == null
      ? null
      : new RemappingAnnotationAdapter(annotationVisitor, remapper);
}
 
Example #26
Source File: RemappingMethodAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    int typeRef, TypePath typePath, String desc, boolean visible) {
  AnnotationVisitor av =
      super.visitInsnAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible);
  return av == null ? av : new RemappingAnnotationAdapter(av, remapper);
}
 
Example #27
Source File: CheckClassAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@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));
}
 
Example #28
Source File: TraceMethodVisitor.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(
    final int typeRef, final TypePath typePath, final String descriptor, final boolean visible) {
  Printer annotationPrinter = p.visitInsnAnnotation(typeRef, typePath, descriptor, visible);
  return new TraceAnnotationVisitor(
      super.visitInsnAnnotation(typeRef, typePath, descriptor, visible), annotationPrinter);
}
 
Example #29
Source File: CheckMethodVisitorFsm.java    From Bats with Apache License 2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitInsnAnnotation(final int typeRef,
    final TypePath typePath, final String desc, final boolean visible) {
  fsmCursor.transition("visitInsnAnnotation");
  final AnnotationVisitor annotationVisitor = super.visitInsnAnnotation(
      typeRef, typePath, desc, visible);
  return annotationVisitor; // TODO: add CheckAnnotationVisitorFsm
}
 
Example #30
Source File: CheckMethodAdapter.java    From JByteMod-Beta with GNU General Public License v2.0 5 votes vote down vote up
@Override
public AnnotationVisitor visitTryCatchAnnotation(final int typeRef, final TypePath typePath, final String desc, final boolean visible) {
  checkStartCode();
  checkEndCode();
  int sort = typeRef >>> 24;
  if (sort != TypeReference.EXCEPTION_PARAMETER) {
    throw new IllegalArgumentException("Invalid type reference sort 0x" + Integer.toHexString(sort));
  }
  CheckClassAdapter.checkTypeRefAndPath(typeRef, typePath);
  CheckMethodAdapter.checkDesc(desc, false);
  return new CheckAnnotationAdapter(super.visitTryCatchAnnotation(typeRef, typePath, desc, visible));
}