From 6ef945642682643784cb4bbe6a35351d8d4b7f75 Mon Sep 17 00:00:00 2001 From: alexkravin Date: Sat, 30 Aug 2014 17:50:12 +0400 Subject: [PATCH 1/2] Pom --- sevntu-checks/pom.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/sevntu-checks/pom.xml b/sevntu-checks/pom.xml index bacb2cc41c..16c9506ad5 100644 --- a/sevntu-checks/pom.xml +++ b/sevntu-checks/pom.xml @@ -45,6 +45,27 @@ 1.5 + + org.codehaus.mojo + build-helper-maven-plugin + 1.9 + + + add-test-source + generate-test-sources + + add-test-source + + + + sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckCtors.java + sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethods.java + sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethodsInMethods.java + + + + + From 92c99703ef8e556cbb9312848bc4a2a677e35e23 Mon Sep 17 00:00:00 2001 From: alexkravin Date: Sat, 30 Aug 2014 17:50:37 +0400 Subject: [PATCH 2/2] Return Count Extended Check #195 Compilable UT inputs --- .../coding/ReturnCountExtendedCheckTest.java | 60 +++-- .../InputReturnCountExtendedCheckCtors.java | 23 +- .../InputReturnCountExtendedCheckMethods.java | 2 + ...urnCountExtendedCheckMethodsInMethods.java | 225 +++++++++++++++--- 4 files changed, 252 insertions(+), 58 deletions(-) diff --git a/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheckTest.java b/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheckTest.java index cba1afb1c9..e7290922de 100644 --- a/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheckTest.java +++ b/sevntu-checks/src/test/java/com/github/sevntu/checkstyle/checks/coding/ReturnCountExtendedCheckTest.java @@ -41,9 +41,28 @@ public void testMethodsMaxReturnLiteralsIsOne() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "25:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "twoReturnsInMethod", 2, 1), - "37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), - "57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1) + "26:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "twoReturnsInMethod", 2, 1), + "38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), + "58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), + "92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1) + }; + + verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); + } + + @Test + public void testMethodsMaxReturnLiteralsIsTwo() throws Exception + { + + checkConfig.addAttribute("maxReturnCount", "2"); + checkConfig.addAttribute("ignoreMethodLinesCount", "0"); // swithed off + checkConfig.addAttribute("minIgnoreReturnDepth", "5"); + checkConfig.addAttribute("ignoreEmptyReturns", "false"); + checkConfig.addAttribute("topLinesToIgnoreCount", "0"); + + String[] expected = { + "38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 2), + "58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 2), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); @@ -60,9 +79,9 @@ public void testConstructorsMaxReturnLiteralsIsOne() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "28:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1), - "41:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1), - "63:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1), + "29:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1), + "42:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1), + "64:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckCtors.java"), expected); @@ -79,8 +98,8 @@ public void testignoreMethodLinesCount() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), - "57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), + "38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), + "58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); @@ -96,7 +115,7 @@ public void testignoreMethodLinesCount2() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), + "58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); @@ -112,26 +131,27 @@ public void testminIgnoreReturnDepth() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "6:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod", 1, 0), - "10:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod2", 1, 0), + "7:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod", 1, 0), + "11:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "oneReturnInMethod2", 1, 0), + "92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 1, 0) }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); } @Test - public void testIgnoreEmptyReturns() throws Exception + public void testIgnoreNonEmptyReturns() throws Exception { checkConfig.addAttribute("maxReturnCount", "1"); checkConfig.addAttribute("ignoreMethodLinesCount", "0"); checkConfig.addAttribute("minIgnoreReturnDepth", "5"); - checkConfig.addAttribute("ignoreEmptyReturns", "true"); + checkConfig.addAttribute("ignoreEmptyReturns", "false"); checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "28:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1), - "41:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1), - "63:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1), + "29:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 2, 1), + "42:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 3, 1), + "64:12: " + getCheckMessage(WARNING_MSG_KEY_CTOR, "InputReturnCountExtendedCheckCtors", 4, 1), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckCtors.java"), expected); @@ -147,7 +167,7 @@ public void testMethodsInMethods() throws Exception checkConfig.addAttribute("topLinesToIgnoreCount", "0"); String[] expected = { - "100:24: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "handleEvent", 3, 1), + "104:24: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "handleEvent", 3, 1), }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethodsInMethods.java"), @@ -165,7 +185,8 @@ public void testIgnoreMethodsNamesProperty() throws Exception checkConfig.addAttribute("ignoreMethodsNames", "threeReturnsInMethod, twoReturnsInMethod"); String[] expected = { - "57:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), + "58:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "fourReturnsInMethod", 4, 1), + "92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1) }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); @@ -182,7 +203,8 @@ public void testRegexIgnoreMethodsNamesProperty() throws Exception checkConfig.addAttribute("ignoreMethodsNames", "(?iu)(?:TwO|Four)(?-iu)ReturnsInMethod"); String[] expected = { - "37:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), + "38:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "threeReturnsInMethod", 3, 1), + "92:16: " + getCheckMessage(WARNING_MSG_KEY_METHOD, "nm", 2, 1) }; verify(checkConfig, getPath("InputReturnCountExtendedCheckMethods.java"), expected); diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckCtors.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckCtors.java index c0e387a7c3..74ed10f224 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckCtors.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckCtors.java @@ -1,3 +1,4 @@ +package com.github.sevntu.checkstyle.checks.coding; public class InputReturnCountExtendedCheckCtors { @@ -5,7 +6,7 @@ public class InputReturnCountExtendedCheckCtors // one "return" public InputReturnCountExtendedCheckCtors() { - return a; + return; } // one "return" @@ -21,7 +22,7 @@ public InputReturnCountExtendedCheckCtors(int x) { } } } - return a + a * a; + return; } // two "returns" @@ -29,32 +30,32 @@ public InputReturnCountExtendedCheckCtors(int x, String s) { System.out.println(); int a = x + s.length(); if (a != 4) { - return 1; + return; } else { System.out.println(a); - return 2; + return; } } // three "returns" public InputReturnCountExtendedCheckCtors(String z, double y) { System.out.println(); - int a = z; + int a = Integer.parseInt(z); y+=0.6; if (a != 4) { - return 1; + return; } else { if (a - 1 != 2) { this.a = 0; - return 6; + return; } else { System.out.println(); - return 2; + return; } } } @@ -65,7 +66,7 @@ public InputReturnCountExtendedCheckCtors(String z, int x, double y) { int a = x; if (a != 4) { if (a != 6) { - return 1; + return; } else { a++; @@ -75,11 +76,11 @@ public InputReturnCountExtendedCheckCtors(String z, int x, double y) { else { if (a - 1 != 2) { this.a = 0; - return 6; + return; } else { System.out.println(); - return 2; + return; } } } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethods.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethods.java index c7f83a6e1d..9d08f09314 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethods.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethods.java @@ -1,3 +1,4 @@ +package com.github.sevntu.checkstyle.checks.coding; public class InputReturnCountExtendedCheckMethods { @@ -98,6 +99,7 @@ public int nm() return 5; } } + return a; } } diff --git a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethodsInMethods.java b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethodsInMethods.java index d92de19d3b..05386e7ddb 100644 --- a/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethodsInMethods.java +++ b/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/coding/InputReturnCountExtendedCheckMethodsInMethods.java @@ -1,4 +1,4 @@ -package com.log4jviewer.ui.preferences.filters; +package com.github.sevntu.checkstyle.checks.coding; /** * Class represents a part of filters preferences page. It is responsible for building a table, where filters are @@ -7,45 +7,43 @@ * @author Ruslan Diachenko
Daniil Yaroslavtsev */ -public class InputReturnCountExtendedCheckMethodsInMethods extends AbstractFilterSettings { +public class InputReturnCountExtendedCheckMethodsInMethods { public static final int COLUMN_COUNT = 3; public static final int ENABLE_COLUMN_INDEX = 2; - private static final Image CHECKED = Activator.getImageDescriptor( - "icons/radio_checked.gif").createImage(); + private static final Object CHECKED = Activator.getImageDescriptor( + "icons/radio_checked.gif"); - private static final Image UNCHECKED = Activator.getImageDescriptor( - "icons/radio_unchecked.gif").createImage(); + private static final Object UNCHECKED = Activator.getImageDescriptor( + "icons/radio_unchecked.gif"); private final Logger logger = LoggerFactory.getLogger(getClass()); private TableViewer tableViewer; - private FilterController filterController; + private TableViewer filterController; - private FilterContentProvider filterContentProvider; + private TableViewer filterContentProvider; - private Button addNewFilterButton; + private TableViewer addNewFilterButton; - private Button removeFilterButton; + private TableViewer removeFilterButton; - private Table filterTable; + private TableViewer filterTable; - public InputReturnCountExtendedCheckMethodsInMethods(final FilterController filterController, - final FilterContentProvider filterContentProvider) { + public InputReturnCountExtendedCheckMethodsInMethods(final TableViewer filterController, + final TableViewer filterContentProvider) { this.filterController = filterController; this.filterContentProvider = filterContentProvider; } - @Override public TableViewer getTableViewer() { return tableViewer; } - @Override - protected void createTableViewer(final Composite composite) { + protected void createTableViewer(final String composite) { tableViewer = new TableViewer(composite, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL @@ -53,12 +51,12 @@ protected void createTableViewer(final Composite composite) { | SWT.FULL_SELECTION); tableViewer.setUseHashlookup(true); - tableViewer.setContentProvider(new ArrayContentProvider()); + tableViewer.setContentProvider(new Object()); filterTable = tableViewer.getTable(); filterTable.setHeaderVisible(true); filterTable.setLinesVisible(true); - GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false, 1, 17); + String gridData = new String(SWT.FILL.toString() + SWT.FILL.toString()); filterTable.setLayoutData(gridData); createColumns(); @@ -69,8 +67,8 @@ protected void createTableViewer(final Composite composite) { tableViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override - public int selectionChanged(final SelectionChangedEvent evt) { - checkAndSetRemoveBtnState(); + public int selectionChanged(final String evt) { + createColumns(); int activeFilterIndex = filterTable.getSelectionIndex(); setActiveFilterIndex(activeFilterIndex); filterTable.redraw(); @@ -81,36 +79,207 @@ public int selectionChanged(final SelectionChangedEvent evt) { // Selects a full row even when any it`s cell is editing filterTable.addListener(SWT.EraseItem, new Listener() { @Override - public int handleEvent(final Event event) { + public int handleEvent(String event) { if (!tableViewer.getSelection().isEmpty()) { - TableItem eventItem = (TableItem) event.item; + String eventItem = event.trim(); - FilterModel filterModel = (FilterModel) eventItem.getData(); + String filterModel = eventItem.trim(); if (isFilterActive(filterModel)) { - event.detail |= SWT.SELECTED; + event = SWT.SELECTED.toString(); } } return 5; } + + @Override + public int handleEvent(double event) + { + return 0; + } }); // Selects a full row even when any it`s cell is editing filterTable.addListener(SWT.EraseItem, new Listener() { @Override - public int handleEvent(final Event event) { + public int handleEvent(double event) { if (!tableViewer.getSelection().isEmpty()) { - TableItem eventItem = (TableItem) event.item; + double eventItem = event; - FilterModel filterModel = (FilterModel) eventItem.getData(); + double filterModel = eventItem; if (isFilterActive(filterModel)) { - event.detail |= SWT.SELECTED; + event = Double.parseDouble(SWT.SELECTED); return 1; } return 2; } return 3; } + + @Override + public int handleEvent(String event) + { + return 0; + } }); } + + private class Image { + + } + + private static class Activator { + + public static Object getImageDescriptor(String string) + { + return null; + } + + } + + private class Logger { + + } + + private static class LoggerFactory { + + public static + Logger + getLogger(Class class1) + { + return null; + } + + } + + private class TableViewer { + + public TableViewer(String composite, int i) + { + } + + public String getSelection() + { + return null; + } + + public void addListener(String eraseitem, Listener listener) + { + + } + + public void redraw() + { + + } + + public int getSelectionIndex() + { + return 0; + } + + public + void + addSelectionChangedListener(ISelectionChangedListener iSelectionChangedListener) + { + + } + + public void setCellEditingStrategy(TableViewer tableViewer) + { + + } + + public + void + addFilterTableListener(TableViewer tableViewer, TableViewer filterContentProvider) + { + + } + + public void setInput(Object filters) + { + + } + + public Object getFilters() + { + return null; + } + + public void setLayoutData(String gridData) + { + + } + + public void setLinesVisible(boolean b) + { + + } + + public void setHeaderVisible(boolean b) + { + + } + + public TableViewer getTable() + { + return null; + } + + public void setContentProvider(Object object) + { + + } + + public void setUseHashlookup(boolean b) + { + + } + + } + + private void createColumns() { + + } + + private void setActiveFilterIndex(int x) { + + } + + private interface SWT { + + String SELECTED = null; + String EraseItem = null; + byte[] FILL = null; + int FULL_SELECTION = 0; + int BORDER = 0; + int V_SCROLL = 0; + int H_SCROLL = 0; + int SINGLE = 0; + + } + + private interface ISelectionChangedListener { + + int selectionChanged(String evt); + + } + + private boolean isFilterActive(String s) { + return false; + } + + private boolean isFilterActive(double s) { + return false; + } + + private interface Listener { + + int handleEvent(String event); + + int handleEvent(double event); + + } + }