Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Trac #190: Generalize "Hide Unused Types" to "Hide Unused Elements"
Browse files Browse the repository at this point in the history
  • Loading branch information
marchof committed Feb 17, 2012
1 parent bc9321c commit 2c80957
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 32 deletions.
2 changes: 2 additions & 0 deletions com.mountainminds.eclemma.doc/pages/changes.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ <h2>Trunk</h2>
<li>For long-running processes intermediate coverage data dumps can now be
collected without terminating the application under test.</li>
<li>Trac #168: New editor for JaCoCo execution data files.</li>
<li>Trac #190: The <i>Coverage</i> view option <i>Hide Unused Types</i> has
been generalized to <i>Hide Unused Elements</i>.</li>
<li>SF #3487904: Avoid NPE in case of new and empty launch configurations.</li>
<li>SF #3477725: Java agent must not be added multiple times to plug-in
launch configurations.</li>
Expand Down
4 changes: 2 additions & 2 deletions com.mountainminds.eclemma.doc/pages/coverageview.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ <h3>Toolbar and Drop-Down Menu</h3>
types and cyclomatic complexity. Please see
<a class="extern" href="https://www.eclemma.org/jacoco/trunk/doc/counters.html">JaCoCo documentation</a>
for detailed counter definitions.</li>
<li><b>Hide Unused Types</b>: Filter all Java types from the coverage view
that has not been loaded during the coverage session.</li>
<li><b>Hide Unused Elements</b>: Filter all elements from the coverage view
that have not been executed at all during the coverage session.</li>
</ul>

<h3>Filtering</h3>
Expand Down
Binary file modified com.mountainminds.eclemma.doc/pages/images/coverageviewmenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion com.mountainminds.eclemma.ui/plugin.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CoverageSWTBotJUnitCommand.name = Coverage SWTBot Test
CoverageSWTBotJUnitCommand.description = Coverage SWTBot Test
SelectRootElementsCommand.name = Select Root Elements
SelectCountersCommand.name = Select Counters
HideUnusedTypesCommand.name = Hide Unused Types
HideUnusedElementsCommand.name = Hide Unused Elements
ImportSessionCommand.name = Import Session...
ExportSessionCommand.name = Export Session...
RelaunchSessionCommand.name = Relaunch Coverage Session
Expand Down
6 changes: 3 additions & 3 deletions com.mountainminds.eclemma.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@
</command>
<command
categoryId="com.mountainminds.eclemma.ui"
id="com.mountainminds.eclemma.ui.hideUnusedTypes"
name="%HideUnusedTypesCommand.name">
id="com.mountainminds.eclemma.ui.hideUnusedElements"
name="%HideUnusedElementsCommand.name">
</command>
<command
categoryId="com.mountainminds.eclemma.ui"
Expand Down Expand Up @@ -780,7 +780,7 @@
visible="true">
</separator>
<command
commandId="com.mountainminds.eclemma.ui.hideUnusedTypes"
commandId="com.mountainminds.eclemma.ui.hideUnusedElements"
style="toggle">
</command>
<separator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,17 @@ public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element == LOADING_ELEMENT) {
return true;
} else {
ICoverageNode c = CoverageTools.getCoverageInfo(element);
if (c == null || c.getInstructionCounter().getTotalCount() == 0) {
final ICoverageNode c = CoverageTools.getCoverageInfo(element);
if (c == null) {
return false;
}
if (settings.getHideUnusedTypes()) {
ICounter cnt = c.getClassCounter();
return cnt.getTotalCount() == 0 || cnt.getCoveredCount() != 0;
final ICounter instructions = c.getInstructionCounter();
if (instructions.getTotalCount() == 0) {
return false;
}
if (settings.getHideUnusedElements()
&& instructions.getCoveredCount() == 0) {
return false;
}
return true;
}
Expand Down Expand Up @@ -340,8 +344,8 @@ private void createHandlers() {
new SelectRootElementsHandler(settings, this));
activateHandler(SelectCountersHandler.ID, new SelectCountersHandler(
settings, this));
activateHandler(HideUnusedTypesHandler.ID, new HideUnusedTypesHandler(
settings, this));
activateHandler(HideUnusedElementsHandler.ID,
new HideUnusedElementsHandler(settings, this));
activateHandler(IWorkbenchCommandConstants.EDIT_COPY,
new CopyHandler(tree.getDisplay(), settings, labelprovider, viewer));
activateHandler(IWorkbenchCommandConstants.FILE_REFRESH,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@
/**
* Handler to toggle hide unused types in the coverage tree.
*/
class HideUnusedTypesHandler extends AbstractHandler implements IElementUpdater {
class HideUnusedElementsHandler extends AbstractHandler implements
IElementUpdater {

public static final String ID = "com.mountainminds.eclemma.ui.hideUnusedTypes"; //$NON-NLS-1$
public static final String ID = "com.mountainminds.eclemma.ui.hideUnusedElements"; //$NON-NLS-1$

private final ViewSettings settings;
private final CoverageView view;

public HideUnusedTypesHandler(ViewSettings settings, CoverageView view) {
public HideUnusedElementsHandler(ViewSettings settings, CoverageView view) {
this.settings = settings;
this.view = view;
}

public Object execute(ExecutionEvent event) throws ExecutionException {
settings.setHideUnusedTypes(!settings.getHideUnusedTypes());
settings.setHideUnusedElements(!settings.getHideUnusedElements());
view.refreshViewer();
return null;
}

public void updateElement(UIElement element,
@SuppressWarnings("rawtypes") Map parameters) {
element.setChecked(settings.getHideUnusedTypes());
element.setChecked(settings.getHideUnusedElements());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class ViewSettings {
private static final String KEY_SORTCOLUMN = "sortcolumn"; //$NON-NLS-1$
private static final String KEY_REVERSESORT = "reversesort"; //$NON-NLS-1$
private static final String KEY_COUNTERS = "counters"; //$NON-NLS-1$
private static final String KEY_HIDEUNUSEDTYPES = "hideunusedtypes"; //$NON-NLS-1$
private static final String KEY_HIDEUNUSEDELEMENTS = "hideunusedelements"; //$NON-NLS-1$
private static final String KEY_ROOTTYPE = "roottype"; //$NON-NLS-1$
private static final String KEY_COLUMN0 = "column0"; //$NON-NLS-1$
private static final String KEY_COLUMN1 = "column1"; //$NON-NLS-1$
Expand Down Expand Up @@ -88,7 +88,7 @@ public class ViewSettings {
private boolean reversesort;
private CounterEntity counters;
private ElementType roottype;
private boolean hideunusedtypes;
private boolean hideunusedelements;
private int[] columnwidths = new int[5];
private boolean linked;

Expand Down Expand Up @@ -129,12 +129,12 @@ public void setRootType(ElementType roottype) {
this.roottype = roottype;
}

public boolean getHideUnusedTypes() {
return hideunusedtypes;
public boolean getHideUnusedElements() {
return hideunusedelements;
}

public void setHideUnusedTypes(boolean flag) {
hideunusedtypes = flag;
public void setHideUnusedElements(boolean flag) {
hideunusedelements = flag;
}

public int[] getColumnWidths() {
Expand All @@ -156,7 +156,7 @@ public void init(IMemento memento) {
CounterEntity.INSTRUCTION);
roottype = getEnum(memento, KEY_ROOTTYPE, ElementType.class,
ElementType.GROUP);
hideunusedtypes = getBoolean(memento, KEY_HIDEUNUSEDTYPES, false);
hideunusedelements = getBoolean(memento, KEY_HIDEUNUSEDELEMENTS, false);
columnwidths[0] = getInt(memento, KEY_COLUMN0, DEFAULT_COLUMNWIDTH[0]);
columnwidths[1] = getInt(memento, KEY_COLUMN1, DEFAULT_COLUMNWIDTH[1]);
columnwidths[2] = getInt(memento, KEY_COLUMN2, DEFAULT_COLUMNWIDTH[2]);
Expand All @@ -167,16 +167,16 @@ public void init(IMemento memento) {

public void save(IMemento memento) {
memento.putInteger(KEY_SORTCOLUMN, sortcolumn);
memento.putInteger(KEY_REVERSESORT, reversesort ? 1 : 0);
memento.putBoolean(KEY_REVERSESORT, reversesort);
memento.putString(KEY_COUNTERS, counters.name());
memento.putString(KEY_ROOTTYPE, roottype.name());
memento.putInteger(KEY_HIDEUNUSEDTYPES, hideunusedtypes ? 1 : 0);
memento.putBoolean(KEY_HIDEUNUSEDELEMENTS, hideunusedelements);
memento.putInteger(KEY_COLUMN0, columnwidths[0]);
memento.putInteger(KEY_COLUMN1, columnwidths[1]);
memento.putInteger(KEY_COLUMN2, columnwidths[2]);
memento.putInteger(KEY_COLUMN3, columnwidths[3]);
memento.putInteger(KEY_COLUMN4, columnwidths[4]);
memento.putInteger(KEY_LINKED, linked ? 1 : 0);
memento.putBoolean(KEY_LINKED, linked);
}

private int getInt(IMemento memento, String key, int preset) {
Expand All @@ -188,6 +188,15 @@ private int getInt(IMemento memento, String key, int preset) {
}
}

private boolean getBoolean(IMemento memento, String key, boolean preset) {
if (memento == null) {
return preset;
} else {
Boolean b = memento.getBoolean(key);
return b == null ? preset : b.booleanValue();
}
}

private <T extends Enum<T>> T getEnum(IMemento memento, String key,
Class<T> type, T preset) {
if (memento == null) {
Expand All @@ -204,8 +213,4 @@ private <T extends Enum<T>> T getEnum(IMemento memento, String key,
}
}

private boolean getBoolean(IMemento memento, String key, boolean preset) {
return getInt(memento, key, preset ? 1 : 0) == 1;
}

}

0 comments on commit 2c80957

Please sign in to comment.