Skip to content

Commit

Permalink
Merge pull request #883 from hcoles/analysis_warnings
Browse files Browse the repository at this point in the history
assorted code style fixes
  • Loading branch information
hcoles authored Apr 19, 2021
2 parents 19b5029 + 7516947 commit 83d62d6
Show file tree
Hide file tree
Showing 72 changed files with 173 additions and 408 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ static Document readDocument(final InputStream inputStream) throws ReportAggrega
try {
docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
return docBuilder.parse(inputStream);
} catch (final IOException e) {
throw new ReportAggregationException(e.getMessage(), e);
} catch (final SAXException e) {
throw new ReportAggregationException(e.getMessage(), e);
} catch (final ParserConfigurationException e) {
} catch (final IOException | SAXException | ParserConfigurationException e) {
throw new ReportAggregationException(e.getMessage(), e);
} finally {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ 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 MutationIdentifier id = new MutationIdentifier(location, Arrays.asList(Integer.valueOf((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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@

final class MutatorUtil {

private static Map<String, MethodMutatorFactory> factories = new ConcurrentHashMap<>();
private static final Map<String, MethodMutatorFactory> FACTORIES = new ConcurrentHashMap<>();

@SuppressWarnings("unchecked")
static MethodMutatorFactory loadMutator(final String className) {
if (!factories.containsKey(className)) {
if (!FACTORIES.containsKey(className)) {
try {
final Class<MethodMutatorFactory> clazz = (Class<MethodMutatorFactory>) Class.forName(className);
final Method values = clazz.getMethod("values");
final Object valuesArray = values.invoke(null);
final MethodMutatorFactory mutator = (MethodMutatorFactory) Array.get(valuesArray, 0);
factories.put(className, mutator);
FACTORIES.put(className, mutator);
} catch (final Exception e) {
throw new RuntimeException("Unable to load Mutator for class: " + className, e);
}
}
return factories.get(className);
return FACTORIES.get(className);
}
}
2 changes: 1 addition & 1 deletion pitest-ant/src/main/java/org/pitest/ant/PitestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void checkRequiredOptions() {
}

private boolean optionMissing(final String option) {
return !this.options.keySet().contains(option);
return !this.options.containsKey(option);
}

private String generateAnalysisClasspath() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ public String apply(final ClientClasspathPlugin a) {
try {
return new File(a.getClass().getProtectionDomain().getCodeSource()
.getLocation().toURI()).getCanonicalPath();
} catch (final IOException ex) {
throw createPitErrorForExceptionOnClass(ex, a);
} catch (final URISyntaxException ex) {
} catch (final IOException | URISyntaxException ex) {
throw createPitErrorForExceptionOnClass(ex, a);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class AddlerHash implements HashFunction {
@Override
public long hash(final byte[] value) {
final Adler32 adler = new Adler32();
adler.update(value);
adler.update(value, 0, value.length);
return adler.getValue();
}

Expand Down
110 changes: 0 additions & 110 deletions pitest-entry/src/main/java/org/pitest/classinfo/Repository.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.pitest.mutationtest.config.TestPluginArguments;
import org.pitest.process.LaunchOptions;
import org.pitest.process.ProcessArgs;
import org.pitest.testapi.Description;
import org.pitest.util.ExitCode;
import org.pitest.util.Log;
import org.pitest.util.PitError;
Expand Down Expand Up @@ -109,7 +110,7 @@ public CoverageData calculateCoverage() {
private static void verifyBuildSuitableForMutationTesting(final CoverageData coverage) {
if (!coverage.allTestsGreen()) {
LOG.severe("Tests failing without mutation: " + StringUtil.newLine()
+ coverage.getFailingTestDescriptions().stream().map(test -> test.toString())
+ coverage.getFailingTestDescriptions().stream().map(Description::toString)
.collect(Collectors.joining(StringUtil.newLine())));
throw new PitHelpError(Help.FAILING_TESTS, coverage.getCountFailedTests());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private static Function<Entry<MutationDetails, MutationStatusTestPair>, Mutation
}

private static Function<Entry<MutationDetails, MutationStatusTestPair>, MutationDetails> toMutationDetails() {
return a -> a.getKey();
return Entry::getKey;
}

private static Predicate<Entry<MutationDetails, MutationStatusTestPair>> hasStatus(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import org.pitest.classinfo.ClassName;
import org.pitest.functional.FCollection;
Expand All @@ -23,7 +22,7 @@ public List<List<MutationDetails>> groupMutations(
final Collection<ClassName> codeClasses,
final Collection<MutationDetails> mutations) {
final Map<ClassName, Collection<MutationDetails>> bucketed = FCollection
.bucket(mutations, byClass());
.bucket(mutations, MutationDetails::getClassName);
final List<List<MutationDetails>> chunked = new ArrayList<>();
for (final Collection<MutationDetails> each : bucketed.values()) {
shrinkToMaximumUnitSize(chunked, each);
Expand All @@ -45,8 +44,4 @@ private void shrinkToMaximumUnitSize(
}
}

private static Function<MutationDetails, ClassName> byClass() {
return a -> a.getClassName();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,7 @@ public List<String> getList(FeatureParameter key) {

public Optional<Integer> getInteger(FeatureParameter key) {
final Optional<String> val = getString(key);
if (val.isPresent()) {
return Optional.ofNullable(Integer.parseInt(val.get()));
}
return Optional.empty();
return val.map(Integer::parseInt);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Map.Entry;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.logging.Logger;

import org.pitest.bytecode.analysis.ClassTree;
Expand Down Expand Up @@ -83,7 +82,7 @@ private void checkForInlinedCode(final Collection<MutationDetails> combined,
final Entry<LineMutatorPair, Collection<MutationDetails>> each) {

final List<MutationDetails> mutationsInHandlerBlock = FCollection
.filter(each.getValue(), isInFinallyHandler());
.filter(each.getValue(), MutationDetails::isInFinallyBlock);
if (!isPossibleToCorrectInlining(mutationsInHandlerBlock)) {
combined.addAll(each.getValue());
return;
Expand All @@ -95,7 +94,7 @@ private void checkForInlinedCode(final Collection<MutationDetails> combined,
// check that we have at least on mutation in a different block
// to the base one (is this not implied by there being only 1 mutation in
// the handler ????)
final List<Integer> ids = map(each.getValue(), mutationToBlock());
final List<Integer> ids = map(each.getValue(), MutationDetails::getBlock);
if (ids.stream().anyMatch(not(isEqual(firstBlock)))) {
combined.add(makeCombinedMutant(each.getValue()));
} else {
Expand All @@ -113,15 +112,11 @@ private boolean isPossibleToCorrectInlining(
return !mutationsInHandlerBlock.isEmpty();
}

private static Predicate<MutationDetails> isInFinallyHandler() {
return a -> a.isInFinallyBlock();
}

private static MutationDetails makeCombinedMutant(
final Collection<MutationDetails> value) {
final MutationDetails first = value.iterator().next();
final Set<Integer> indexes = new HashSet<>();
mapTo(value, mutationToIndex(), indexes);
mapTo(value, MutationDetails::getFirstIndex, indexes);

final MutationIdentifier id = new MutationIdentifier(first.getId()
.getLocation(), indexes, first.getId().getMutator());
Expand All @@ -130,13 +125,6 @@ private static MutationDetails makeCombinedMutant(
first.getLineNumber(), first.getBlock());
}

private static Function<MutationDetails, Integer> mutationToIndex() {
return a -> a.getFirstIndex();
}

private static Function<MutationDetails, Integer> mutationToBlock() {
return a -> a.getBlock();
}

private static Function<MutationDetails, LineMutatorPair> toLineMutatorPair() {
return a -> new LineMutatorPair(a.getLineNumber(), a.getMutator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,11 @@ class LoggingLineScanner extends MethodVisitor {
@Override
public void visitMethodInsn(final int opcode, final String owner,
final String name, final String desc, boolean itf) {
if (FCollection.contains(this.loggingClasses, matches(owner))) {
if (FCollection.contains(this.loggingClasses, owner::startsWith)) {
this.lines.add(this.currentLineNumber);
}
}

private static Predicate<String> matches(final String owner) {
return a -> owner.startsWith(a);
}

@Override
public void visitLineNumber(final int line, final Label start) {
this.currentLineNumber = line;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.pitest.mutationtest.build.intercept.staticinitializers;

import java.util.Collection;
import java.util.function.Predicate;

import org.pitest.bytecode.analysis.ClassTree;
import org.pitest.functional.FCollection;
Expand All @@ -21,11 +20,7 @@ public void begin(ClassTree clazz) {
@Override
public Collection<MutationDetails> intercept(
Collection<MutationDetails> mutations, Mutater m) {
return FCollection.filter(mutations, Prelude.not(isInStaticInitCode()));
}

private Predicate<MutationDetails> isInStaticInitCode() {
return a -> a.isInStaticInitializer();
return FCollection.filter(mutations, Prelude.not(MutationDetails::isInStaticInitializer));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private void analyseClass(ClassTree tree) {
clinit.get().instructions().stream()
.flatMap(is(MethodInsnNode.class))
.filter(calls(tree.name()))
.map(toPredicate())
.map(StaticInitializerInterceptor::matchesCall)
.collect(Collectors.toList());

final Predicate<MethodTree> matchingCalls = Prelude.or(selfCalls);
Expand All @@ -107,13 +107,6 @@ private static Predicate<MethodTree> isPrivateStatic() {
&& ((a.rawNode().access & Opcodes.ACC_PRIVATE) != 0);
}



private static Function<MethodInsnNode, Predicate<MethodTree>> toPredicate() {
return a -> matchesCall(a);
}


private static Predicate<MethodTree> matchesCall(final MethodInsnNode call) {
return a -> a.rawNode().name.equals(call.name)
&& a.rawNode().desc.equals(call.desc);
Expand All @@ -124,15 +117,11 @@ private Predicate<MethodInsnNode> calls(final ClassName self) {
}

private <T extends AbstractInsnNode> Function<AbstractInsnNode,Stream<T>> is(final Class<T> clazz) {
return new Function<AbstractInsnNode,Stream<T>>() {
@SuppressWarnings("unchecked")
@Override
public Stream<T> apply(AbstractInsnNode a) {
if (a.getClass().isAssignableFrom(clazz)) {
return Stream.of((T)a);
}
return Stream.empty();
return a -> {
if (a.getClass().isAssignableFrom(clazz)) {
return Stream.of((T)a);
}
return Stream.empty();
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Collection<? extends MutationInterceptorFactory> findInterceptors() {
public Collection<? extends ProvidesFeature> findFeatures() {
return findToolClasspathPlugins().stream()
.filter(p -> p instanceof ProvidesFeature)
.map(p -> ProvidesFeature.class.cast(p))
.map(ProvidesFeature.class::cast)
.collect(Collectors.toList());
}

Expand Down
Loading

0 comments on commit 83d62d6

Please sign in to comment.