public Location asLocation() { return Location.location(this.owner,MethodName.fromString(this.rawNode.name), this.rawNode.desc); }
public String describe() { return this.method.name(); }
public static MethodName fromString(final String name) { return new MethodName(name); }
private Predicate<MutationDetails> inEqualsMethod() { return a -> { final Location loc = a.getId().getLocation(); return loc.getMethodDesc().equals("(Ljava/lang/Object;)Z") && loc.getMethodName().equals(MethodName.fromString("equals")); }; }
return false; } else if (!this.method.equals(other.method)) { return false;
@Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.clazz == null) ? 0 : this.clazz.hashCode()); result = (prime * result) + ((this.method == null) ? 0 : this.method.hashCode()); result = (prime * result) + ((this.methodDesc == null) ? 0 : this.methodDesc.hashCode()); return result; }
private static Predicate<MutationDetails> isInStaticInitializer() { return a -> a.getId().getLocation().getMethodName().equals(CLINIT); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.clazz == null) ? 0 : this.clazz.hashCode()); result = (prime * result) + ((this.method == null) ? 0 : this.method.hashCode()); result = (prime * result) + ((this.methodDesc == null) ? 0 : this.methodDesc.hashCode()); return result; }
@Override protected BlockCoverage mapToData(final Map<String, Object> map) { final String method = (String) map.get(METHOD); final Location location = new Location(ClassName.fromString((String) map.get(CLASSNAME)), MethodName.fromString(method.substring(0, method.indexOf(OPEN_PAREN))), method.substring(method.indexOf(OPEN_PAREN))); final BlockLocation blockLocation = new BlockLocation(location, Integer.parseInt((String) map.get(NUMBER))); @SuppressWarnings("unchecked") final Collection<String> tests = (Collection<String>) map.get(TESTS); return new BlockCoverage(blockLocation, tests); }
public static MutationDetails makeMutation(final ClassName clazz) { return new MutationDetails(new MutationIdentifier(Location.location(clazz, new MethodName("aMethod"), "()V"), 1, "mutatorId"), "foo.java", "A mutation", 0, 0); }
return false; } else if (!this.method.equals(other.method)) { return false;
@Override protected MutationResult mapToData(final Map<String, Object> map) { final Location location = new Location(ClassName.fromString((String) map.get(MUTATED_CLASS)), MethodName.fromString((String) map.get(MUTATED_METHOD)), (String) map.get(METHOD_DESCRIPTION)); final MutationIdentifier id = new MutationIdentifier(location, Arrays.asList(new Integer((String) map.get(INDEX))), (String) map.get(MUTATOR)); final MutationDetails md = new MutationDetails(id, (String) map.get(SOURCE_FILE), (String) map.get(DESCRIPTION), Integer.parseInt((String) map.get(LINE_NUMBER)), Integer.parseInt((String) map.get(BLOCK))); final MutationStatusTestPair status = new MutationStatusTestPair(Integer.parseInt((String) map.get(NUMBER_OF_TESTS_RUN)), DetectionStatus.valueOf((String) map.get(STATUS)), (String) map.get(KILLING_TEST)); return new MutationResult(md, status); }
private void analyseClass(ClassTree tree) { final Optional<MethodTree> clinit = tree.methods().stream().filter(nameEquals(CLINIT.name())).findFirst(); if (clinit.isPresent()) { final List<Predicate<MethodTree>> selfCalls = clinit.get().instructions().stream() .flatMap(is(MethodInsnNode.class)) .filter(calls(tree.name())) .map(toPredicate()) .collect(Collectors.toList()); final Predicate<MethodTree> matchingCalls = Prelude.or(selfCalls); final Predicate<MutationDetails> initOnlyMethods = Prelude.or(tree.methods().stream() .filter(isPrivateStatic()) .filter(matchingCalls) .map(AnalysisFunctions.matchMutationsInMethod()) .collect(Collectors.toList()) ); this.isStaticInitCode = Prelude.or(isInStaticInitializer(), initOnlyMethods); } }
public static MethodName fromString(final String name) { return new MethodName(name); }
@Override public Map<BlockLocation, Set<Integer>> mapLines(final ClassName clazz) { final Map<BlockLocation, Set<Integer>> map = new HashMap<>(); final Optional<byte[]> maybeBytes = this.source.fetchClassBytes(clazz); // classes generated at runtime eg by mocking frameworks // will be instrumented but not available on the classpath if (maybeBytes.isPresent()) { final ClassReader cr = new ClassReader(maybeBytes.get()); final ClassNode classNode = new ClassNode(); cr.accept(classNode, ClassReader.EXPAND_FRAMES); for (final Object m : classNode.methods) { final MethodNode mn = (MethodNode) m; final Location l = Location.location(clazz, MethodName.fromString(mn.name), mn.desc); final List<Block> blocks = ControlFlowAnalyser.analyze(mn); for (int i = 0; i != blocks.size(); i++) { final BlockLocation bl = new BlockLocation(l, i); map.put(bl, blocks.get(i).getLines()); } } } return map; }
@Override public boolean matches(MutationDetails value) { return value.getId().getLocation().getMethodName().name().equals(name); } };
private void handleProbes(final SafeDataInputStream is) { final int classId = is.readInt(); final String methodName = is.readString(); final String methodSig = is.readString(); final int first = is.readInt(); final int last = is.readInt(); final Location loc = Location.location(this.classIdToName.get(classId), MethodName.fromString(methodName), methodSig); for (int i = first; i != (last + 1); i++) { // nb, convert from classwide id to method scoped index within // BlockLocation this.probeToBlock.put(CodeCoverageStore.encode(classId, i), new BlockLocation(loc, i - first)); } }
@Test public void shouldFilterMethodsWithGeneratedAnnotation() { final List<MutationDetails> mutations = this.mutator.findMutations(ClassName.fromClass(MethodAnnotatedWithGenerated.class)); final Collection<MutationDetails> actual = runWithTestee(mutations, MethodAnnotatedWithGenerated.class); assertThat(actual).hasSize(1); assertThat(actual.iterator().next().getId().getLocation().getMethodName().name()).isEqualTo("bar"); }
@Test public void shouldSortInConsistantOrder() { final Location a = location(ClassName.fromString("A"), MethodName.fromString("A"), "A"); final Location b = location(ClassName.fromString("AA"), MethodName.fromString("A"), "A"); final Location c = location(ClassName.fromString("A"), MethodName.fromString("AA"), "A"); final Location d = location(ClassName.fromString("A"), MethodName.fromString("AA"), "AA"); final List<Location> ls = Arrays.asList(a, b, c, d); Collections.sort(ls); assertEquals(Arrays.asList(a, c, d, b), ls); }