Skip to content

Commit

Permalink
Improve JavaDoc & code style
Browse files Browse the repository at this point in the history
Update code according to Checkstyle's rules.
  • Loading branch information
echebbi committed Aug 15, 2019
1 parent 6de2b49 commit a31654d
Show file tree
Hide file tree
Showing 85 changed files with 736 additions and 352 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ public void start(BundleContext context) throws Exception { // NOPMD - Base
// signature
super.start(context);
plugin = this;
// this.context = context;
setActivator(this);
setupStateDirectories();

Expand Down Expand Up @@ -130,10 +129,6 @@ private void setupStateDirectories() {
setupHistoryFile();
}

// private static IPath getStateLocation() {
// return Platform.getStateLocation(context.getBundle());
// }

private void setupHistoryFile() {
IPath pluginLocation = getStateLocation();
File stateFile = pluginLocation.append(HISTORY_DIR).append(STATE_FILE).toFile();
Expand Down Expand Up @@ -191,18 +186,6 @@ public static PitCoreActivator getDefault() {
return plugin;
}

// /**
// * Returns an image descriptor for the image file at the given plug-in
// * relative path
// *
// * @param path
// * the path
// * @return the image descriptor
// */
// public static ImageDescriptor getImageDescriptor(String path) {
// return imageDescriptorFromPlugin(PLUGIN_ID, path);
// }

public static void log(String msg) {
log(Status.INFO, msg, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package org.pitest.pitclipse.core;

public enum PitMutators {
DEFAULTS("defaultMutators", "&Default Mutators"), STRONGER("strongerMutators", "&Stronger Mutators"), ALL(
"allMutators", "&All Mutators");

DEFAULTS("defaultMutators", "&Default Mutators"),
STRONGER("strongerMutators", "&Stronger Mutators"),
ALL("allMutators", "&All Mutators");

private final String label;
private final String id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,65 @@
import static org.pitest.pitclipse.core.PitCoreActivator.warn;

/**
* <p>Manages contributions to a given extension point.</p>
*
* @param <T>
* <p>This extension point must provide a "class" attribute
* that correspond to a fully qualified name of a Java class
* implementing the {@link ResultNotifier} interface.</p>
*
* @param <U>
* The type of results expected by the extensions
*/
public class ExtensionPointHandler<T> {
public class ExtensionPointHandler<U> {
private final String extensionPointId;

/**
* Creates a new handler to manage contributions to the given extension point.
*
* @param extensionPointId
* The id of the extension points which contributions must be handled.
*/
public ExtensionPointHandler(String extensionPointId) {
this.extensionPointId = extensionPointId;
}

public <U> void execute(IExtensionRegistry registry, U results) {
/**
* <p>Makes contributions to the extension points handling given results.</p>
*
* <p>More specifically, this method:
* <ol>
* <li>Browse all contributions to the extension point
* <li>Create a new instance corresponding the "class" attribute of each of these contributions
* <li>Cast these instances as {@link ResultNotifier ResultNotifier&lt;U&gt;}
* <li>Call {@link ResultNotifier#handleResults(Object) notifier.handleResults} with given results as parameter
* </ol>
*
* @param registry
* The registry providing available extensions.
* @param results
* The results to be handled by the extensions.
*/
public void execute(IExtensionRegistry registry, U results) {
evaluate(registry, results);
}

private <U> void evaluate(IExtensionRegistry registry, final U results) {
private void evaluate(IExtensionRegistry registry, final U results) {
IConfigurationElement[] config = registry.getConfigurationElementsFor(extensionPointId);
try {
for (IConfigurationElement e : config) {
Object obj = e.createExecutableExtension("class");
if (obj instanceof ResultNotifier) {
@SuppressWarnings("unchecked")
final ResultNotifier<U> notifier = (ResultNotifier<U>) obj;
executeExtension(new NotifierRunnable<U>(notifier, results));
executeExtension(() -> notifier.handleResults(results));
}
}
} catch (CoreException ex) {
warn("Error thrown notifying results", ex);
}
}

private <U> void executeExtension(final Runnable extension) {
private void executeExtension(final Runnable extension) {
ISafeRunnable runnable = new ISafeRunnable() {
@Override
public void handleException(Throwable e) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,56 @@

import java.util.List;

/**
* <p>Options used by a running PIT application.</p>
*
* <p>An instance of this class is <strong>immutable</strong> and, once built,
* is inherently <strong>thread-safe</strong>.</p>
*/
public class PitRuntimeOptions {

private final int portNumber;
private final PitOptions options;
private final ImmutableList<String> projects;

/**
* Creates a new object representing the options used by a running PIT application.
*
* @param portNumber
* The port used by PIT to send its results.
* @param options
* The options given to PIT to parameterize its analyze.
* @param projects
* The projects analyzed by PIT.
*/
public PitRuntimeOptions(int portNumber, PitOptions options, List<String> projects) {
this.portNumber = portNumber;
this.options = options;
this.projects = ImmutableList.copyOf(projects);
}

/**
* Returns the port used by PIT to send its results.
* @return the port used by PIT to send its results
*/
public int getPortNumber() {
return portNumber;
}

/**
* <p>Returns the options that have been given to PIT.</p>
* <p>These options parameterize PIT analyze.</p>
*
* @return the options that have been given to PIT
*/
public PitOptions getOptions() {
return options;
}

/**
* Returns the name of the projects analyzed by PIT.
* @return the name of the projects analyzed by PIT
*/
public List<String> getMutatedProjects() {
return projects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.pitest.pitclipse.core.extension.point;

/**
* An object able to process some results.
* An object able to process Pitest's results.
*
* @param <T> the type of expected results
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
import org.pitest.pitclipse.runner.PitResults;
import org.pitest.pitclipse.runner.client.PitResultHandler;

/**
* <p>Notifies all contributions to the {@code results} extension point
* that new results have been produced by PIT.</p>
*
* <p>Contributions are notified in a background job.</p>
*/
public class ExtensionPointResultHandler implements PitResultHandler {

public void handle(PitResults results) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* <p>Launches a server that will update all contributions to the {@code results}
* extension point with the results produced by the currently running PIT application.</p>
*
* <p>This class is registered through the {@code executePit} extension point
* and is hence called each time a new PIT application is launched.</p>
*/
public class PitExecutionNotifier implements ResultNotifier<PitRuntimeOptions> {
private static final ExecutorService executorService = Executors.newCachedThreadPool();

Expand All @@ -35,6 +42,7 @@ public void handleResults(PitRuntimeOptions runtimeOptions) {
PitServer server = new PitServer(runtimeOptions.getPortNumber());
PitRequest request = PitRequest.builder().withPitOptions(runtimeOptions.getOptions())
.withProjects(runtimeOptions.getMutatedProjects()).build();
// TODO Check whether it can be replaced by Jobs API
executorService.execute(new PitCommunicator(server, request, resultHandler));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.pitest.pitclipse.core.extension.handler.ExtensionPointHandler;
import org.pitest.pitclipse.core.extension.point.ResultNotifier;
import org.pitest.pitclipse.runner.PitResults;

/**
* <p>Notifies all contributions to the {@code results} extension point that new PIT results are available.</p>
*
* <p>
* More specifically, an instance of this class:
* <ol>
* <li>Browse the extension registry to find contributions to the {@code results} extension point
* <li>[for each contribution] Instantiate a new class from the "class" attribute
* <li>Cast the new class to {@link ResultNotifier}
* <li>Call {@link ResultNotifier#handleResults(Object)}, passing giving results as parameter
* </ol>
* </p>
*/
public class UpdateExtensions implements Runnable {
private static final String EXTENSION_POINT_ID = "org.pitest.pitclipse.core.results";

private final PitResults results;

/**
* Creates a new runnable to update contributions to the {@code results} extension point.
*
* @param results
* The results to be handled by the contributions.
*/
public UpdateExtensions(PitResults results) {
this.results = results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@
import org.eclipse.core.runtime.IExtensionRegistry;
import org.eclipse.core.runtime.Platform;
import org.pitest.pitclipse.core.extension.handler.ExtensionPointHandler;
import org.pitest.pitclipse.core.extension.point.ResultNotifier;
import org.pitest.pitclipse.runner.model.MutationsModel;

/**
* <p>Updates all contributions to the {@code mutations.results} extension point.</p>
*
* <p>
* More specifically, an instance of this class:
* <ol>
* <li>Browse the extension registry to find contributions to the {@code mutations.results} extension point
* <li>[for each contribution] Instantiate a new class from the "class" attribute
* <li>Cast the new class to {@link ResultNotifier}
* <li>Call {@link ResultNotifier#handleResults(Object)}, passing giving results as parameter
* </ol>
* </p>
*/
public class UpdateMutations implements Runnable {
private static final String EXTENSION_POINT_ID = "org.pitest.pitclipse.core.mutations.results";

private final MutationsModel model;

/**
* Creates a new runnable to update contributions to the {@code mutation.results} extension point.
*
* @param results
* The results to be handled by the contributions.
*/
public UpdateMutations(MutationsModel model) {
this.model = model;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

package org.pitest.pitclipse.core.preferences;

public class PitPreferences {
/**
* Constants used to deal with Pitclipse's preferences.
*/
public final class PitPreferences {

public static final String PIT_MUTATORS = "pitMutators";

Expand All @@ -35,5 +38,9 @@ public class PitPreferences {
public static final String RUN_IN_PARALLEL = "runInParallel";
public static final String TIMEOUT = "pitTimeout";
public static final String TIMEOUT_FACTOR = "pitTimeoutFactor";

private PitPreferences() {
// utility class should not be instantiated
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
import org.pitest.pitclipse.runner.model.ModelBuilder;
import org.pitest.pitclipse.runner.model.MutationsModel;

/**
* <p>Launches a background job that updates all contributions to the {@code mutation.results}
* extension point.</p>
*
* <p>Those contributions are updated with a {@link MutationsModel} build by a {@link ModelBuilder}
* from the given PIT results.</p>
*
* <p>This class is registered through the {@code results} extension point
* and is hence called each time new results are produced by PIT.</p>
*/
public class MutationsModelNotifier implements ResultNotifier<PitResults> {

private static final ModelBuilder MODEL_BUILDER = new ModelBuilder(JdtStructureService.INSTANCE);
Expand Down
Loading

0 comments on commit a31654d

Please sign in to comment.