@Override public int compareTo(final Location o) { int comp = this.clazz.compareTo(o.getClassName()); if (comp != 0) { return comp; } comp = this.method.name().compareTo(o.getMethodName().name()); if (comp != 0) { return comp; } return this.methodDesc.compareTo(o.getMethodDesc()); }
public Location asLocation() { return Location.location(this.owner,MethodName.fromString(this.rawNode.name), this.rawNode.desc); }
public static Location location(final ClassName clazz, final MethodName method, final String methodDesc) { return new Location(clazz, method, methodDesc); }
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")); }; }
/** * Returns the class in which this mutation is located * * @return class in which mutation is located */ public ClassName getClassName() { return this.location.getClassName(); }
/** * Returns the class in which this mutation is located * * @return class in which mutation is located */ public MethodName getMethod() { return this.id.getLocation().getMethodName(); }
/** * Returns true if this mutation has a matching identifier * * @param id * the MutationIdentifier to match * @return true if the MutationIdentifier matches otherwise false */ public boolean matches(final MutationIdentifier id) { return this.location.equals(id.location) && this.mutator.equals(id.mutator) && this.indexes.contains(id.getFirstIndex()); }
public String desc() { return location.getMethodDesc(); }
public boolean isFor(final ClassName clazz) { return this.location.getClassName().equals(clazz); }
private static Predicate<MutationDetails> isInStaticInitializer() { return a -> a.getId().getLocation().getMethodName().equals(CLINIT); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions); Location location = mID.getLocation(); if(location.getMethodDesc().equals(desc) && location.getMethodName().name().equals(name)) { return new MutationMethodAdapter( MutationOperator.fromID(mID.getMutator()), new Method(location.getMethodName().name(), location.getMethodDesc()), methodVisitor); } return methodVisitor; } }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final BlockLocation other = (BlockLocation) obj; if (this.block != other.block) { return false; } if (this.location == null) { if (other.location != null) { return false; } } else if (!this.location.equals(other.location)) { return false; } return true; }
private String makeMutationNode(final MutationResult mutation) { final MutationDetails details = mutation.getDetails(); return makeNode(clean(details.getFilename()), sourceFile) + makeNode(clean(details.getClassName().asJavaName()), mutatedClass) + makeNode(clean(details.getMethod().name()), mutatedMethod) + makeNode(clean(details.getId().getLocation().getMethodDesc()), methodDescription) + makeNode("" + details.getLineNumber(), lineNumber) + makeNode(clean(details.getMutator()), mutator) + makeNode("" + details.getFirstIndex(), index) + makeNode("" + details.getBlock(), block) + makeNodeWhenConditionSatisfied(!fullMutationMatrix, createKillingTestDesc(mutation.getKillingTest()), killingTest) + makeNodeWhenConditionSatisfied(fullMutationMatrix, createTestDesc(mutation.getKillingTests()), killingTests) + makeNodeWhenConditionSatisfied(fullMutationMatrix, createTestDesc(mutation.getSucceedingTests()), succeedingTests) + makeNode(clean(details.getDescription()), description); }
private void writeLineCoverage(final BlockCoverage each, final Writer out) { final Location l = each.getBlock().getLocation(); write( out, "<block classname='" + l.getClassName().asJavaName() + "'" + " method='" + StringUtil.escapeBasicHtmlChars(l.getMethodName().name()) + StringUtil.escapeBasicHtmlChars(l.getMethodDesc()) + "' number='" + each.getBlock().getBlock() + "'>"); write(out, "<tests>\n"); final List<String> ts = new ArrayList<>(each.getTests()); Collections.sort(ts); for (final String test : ts) { write(out, "<test name='" + StringUtil.escapeBasicHtmlChars(test) + "'/>\n"); } write(out, "</tests>\n"); write(out, "</block>\n"); }
@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; }
private Set<Integer> getLinesForBlock(BlockLocation bl) { Set<Integer> lines = this.blocksToLines.get(bl); if (lines == null) { calculateLinesForBlocks(bl.getLocation().getClassName()); lines = this.blocksToLines.get(bl); if (lines == null) { lines = Collections.emptySet(); } } return lines; }
@Override public boolean matches(MutationDetails value) { return value.getId().getLocation().getMethodName().name().equals(name); } };
public static Predicate<MethodTree> forLocation(final Location location) { return a -> a.asLocation().equals(location); } }
public static String methodKey(MutationResult mutation) { String className = mutation.getDetails().getClassName().asJavaName(); String methodName = mutation.getDetails().getMethod().name(); String methodDescription = mutation.getDetails().getId().getLocation().getMethodDesc(); return className + "." + methodName + methodDescription; }
@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); }