Java Code Examples for org.pitest.bytecode.analysis.MethodTree#instruction()

The following examples show how to use org.pitest.bytecode.analysis.MethodTree#instruction() . 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: KotlinInterceptor.java    From pitest-kotlin with Apache License 2.0 5 votes vote down vote up
private static Predicate<MutationDetails> isKotlinJunkMutation(final ClassTree currentClass) {
  return a -> {
      int instruction = a.getInstructionIndex();
      MethodTree method = currentClass.methods().stream()
          .filter(MethodMatchers.forLocation(a.getId().getLocation()))
          .findFirst()
          .get();
      AbstractInsnNode mutatedInstruction = method.instruction(instruction);
      Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
      context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
      return KOTLIN_JUNK.matches(method.instructions(), context);
  };
}
 
Example 2
Source File: MethodReferenceNullCheckFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Predicate<MutationDetails> isAnImplicitNullCheck() {
  return a -> {
    final int instruction = a.getInstructionIndex();
    final MethodTree method = MethodReferenceNullCheckFilter.this.currentClass.methods().stream()
        .filter(MethodMatchers.forLocation(a.getId().getLocation()))
        .findFirst()
        .get();

    final AbstractInsnNode mutatedInstruction = method.instruction(instruction);

    final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
    context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
    return NULL_CHECK.matches(method.instructions(), context);
  };
}
 
Example 3
Source File: ForEachLoopFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Predicate<MutationDetails> mutatesIteratorLoopPlumbing() {
  return a -> {
    final int instruction = a.getInstructionIndex();
    final MethodTree method = ForEachLoopFilter.this.currentClass.methods().stream()
        .filter(MethodMatchers.forLocation(a.getId().getLocation()))
        .findFirst()
        .get();
    final AbstractInsnNode mutatedInstruction = method.instruction(instruction);

    final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
    context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
    return ITERATOR_LOOP.matches(method.instructions(), context);
  };
}
 
Example 4
Source File: ImplicitNullCheckFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Predicate<MutationDetails> isAnImplicitNullCheck() {
  return a -> {
    final int instruction = a.getInstructionIndex();
    final MethodTree method = ImplicitNullCheckFilter.this.currentClass.methods().stream()
        .filter(MethodMatchers.forLocation(a.getId().getLocation()))
        .findFirst()
        .get();

    final AbstractInsnNode mutatedInstruction = method.instruction(instruction);

    final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
    context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
    return GET_CLASS_NULL_CHECK.matches(method.instructions(), context);
  };
}
 
Example 5
Source File: AvoidForLoopCounterFilter.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Predicate<MutationDetails> mutatesAForLoopCounter() {
  return a -> {
    final int instruction = a.getInstructionIndex();
    final MethodTree method = AvoidForLoopCounterFilter.this.currentClass.methods().stream()
        .filter(MethodMatchers.forLocation(a.getId().getLocation()))
        .findFirst().get();
    final AbstractInsnNode mutatedInstruction = method.instruction(instruction);

    final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG);
    context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction);
    return MUTATED_FOR_COUNTER.matches(method.instructions(), context);
  };
}
 
Example 6
Source File: FilterTester.java    From pitest with Apache License 2.0 5 votes vote down vote up
private Function<MutationDetails, Loc> toLocation(final ClassTree tree) {
  return a -> {
    final MethodTree method = tree.method(a.getId().getLocation()).get();
    final Loc l = new Loc();
    l.index = a.getInstructionIndex();
    l.node = method.instruction(a.getInstructionIndex());
    return l;
  };
}
 
Example 7
Source File: InfiniteForLoopFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
boolean couldCauseInfiniteLoop(MethodTree method, MutationDetails each) {
  final AbstractInsnNode instruction = method.instruction(each.getInstructionIndex());
  return instruction.getOpcode() == Opcodes.IINC;
}
 
Example 8
Source File: InfiniteIteratorLoopFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
@Override
boolean couldCauseInfiniteLoop(MethodTree method, MutationDetails each) {
  final AbstractInsnNode instruction = method.instruction(each.getInstructionIndex());
  return isIteratorNext(instruction);
}
 
Example 9
Source File: EqualsPerformanceShortcutFilter.java    From pitest with Apache License 2.0 4 votes vote down vote up
private boolean mutatesAConditionalJump(MethodTree tree, int index) {
  final AbstractInsnNode mutatedInsns = tree.instruction(index);
  return InstructionMatchers.aConditionalJump().test(null, mutatedInsns);
}