diff --git a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java index ff40debe8..b43189529 100644 --- a/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java +++ b/com.avaloq.tools.ddk.check.core.test/src/com/avaloq/tools/ddk/check/core/test/AbstractCheckTestCase.java @@ -394,6 +394,7 @@ private String getNormalizedContents(final Class * the type of the result value */ @@ -22,7 +22,7 @@ public final class StepResult implements IStepData { /** * Creates and returns a {@link StepResult}. - * + * * @param * the type of the step result value * @return the newly created {@link StepResult} @@ -39,17 +39,18 @@ private StepResult() { } /** {@inheritDoc} */ + @Override public T getValue() { return value; } /** * Sets the value of this {@link StepResult}. This can only be done by the test framework. - * + * * @param value * the new value for this {@link StepResult} */ - protected void setValue(final T value) { + void setValue(final T value) { // currently we set the result multiple time until the postconditions succeed. Hence we cannot enforce this anymore. // XXX : think about refactoring so that we can check the following assertion again, or decide to remove it for good. // Assert.assertFalse("Step result value must not have been set yet.", valueSet); @@ -58,6 +59,7 @@ protected void setValue(final T value) { } /** {@inheritDoc} */ + @Override public boolean isValueSet() { return valueSet; } @@ -72,4 +74,3 @@ public String toString() { } } } - diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/ClassRunner.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/ClassRunner.java index eb7971048..9e550cf10 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/ClassRunner.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/ClassRunner.java @@ -207,7 +207,6 @@ private void runRepeatedly(final FrameworkMethod method, final EachTestNotifier final MultipleTestProblems problems = new MultipleTestProblems(); final Collection failures = Lists.newArrayList(); final Collection errors = Lists.newArrayList(); - final String testCase = getTestClass().getJavaClass().getSimpleName() + "." + method.getName(); int run = 0; int succeeded = 0; while (run < testRuns || (testRuns == 1 && succeeded == 0 && run < testRetries + 1)) { @@ -227,6 +226,7 @@ private void runRepeatedly(final FrameworkMethod method, final EachTestNotifier problems.addProblem(throwable); } } + final String testCase = getTestClass().getJavaClass().getSimpleName() + '.' + method.getName(); if (run > 1) { logRepeatedTestResult(testCase, run, succeeded, failures.size(), errors.size()); } @@ -283,7 +283,7 @@ public void logRepeatedTestResult(final String testCase, final int runs, final i if (errors > 0) { testResult.append(", ").append(errors).append(" errored"); } - testResult.append(")"); + testResult.append(')'); LOGGER.info(testResult.toString()); } diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DiscerningSuite.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DiscerningSuite.java index a4dd879ab..7aae1f3db 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DiscerningSuite.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DiscerningSuite.java @@ -33,7 +33,7 @@ public class DiscerningSuite extends Suite { /** * Creates a new instance of {@link DiscerningSuite}. - * + * * @param klass * root of the suite * @param runners @@ -48,7 +48,7 @@ public DiscerningSuite(final Class klass, final List runners) throws /** * Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}. - * + * * @param klass * the root of the suite * @param suiteClasses @@ -56,14 +56,14 @@ public DiscerningSuite(final Class klass, final List runners) throws * @throws InitializationError * if an error occurred during the initialization */ - public DiscerningSuite(final Class klass, final Class[] suiteClasses) throws InitializationError { + public DiscerningSuite(final Class klass, final Class... suiteClasses) throws InitializationError { super(klass, suiteClasses); initialize(); } /** * Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}. - * + * * @param klass * the root class * @param builder @@ -78,7 +78,7 @@ public DiscerningSuite(final Class klass, final RunnerBuilder builder) throws /** * Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}. - * + * * @param builder * builds runners for classes in the suite * @param klass @@ -88,14 +88,14 @@ public DiscerningSuite(final Class klass, final RunnerBuilder builder) throws * @throws InitializationError * if an error occurred during the initialization */ - public DiscerningSuite(final RunnerBuilder builder, final Class klass, final Class[] suiteClasses) throws InitializationError { + public DiscerningSuite(final RunnerBuilder builder, final Class klass, final Class... suiteClasses) throws InitializationError { super(builder, klass, suiteClasses); initialize(); } /** * Creates a new instance of {@link DiscerningSwtBotNonSwtBotSuite}. - * + * * @param builder * builds runners for classes in the suite * @param classes @@ -103,7 +103,7 @@ public DiscerningSuite(final RunnerBuilder builder, final Class klass, final * @throws InitializationError * if an error occurred during the initialization */ - public DiscerningSuite(final RunnerBuilder builder, final Class[] classes) throws InitializationError { + public DiscerningSuite(final RunnerBuilder builder, final Class... classes) throws InitializationError { super(builder, classes); initialize(); } @@ -141,4 +141,3 @@ public void filter(final Filter filter) throws NoTestsRemainException { } } } - diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DynamicSuite.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DynamicSuite.java index c9aa3ca37..bb365c92c 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DynamicSuite.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/DynamicSuite.java @@ -44,11 +44,11 @@ public DynamicSuite(final Class clazz, final RunnerBuilder builder) throws In this(clazz, builder.runners(clazz, getSuiteClasses(clazz))); } - public DynamicSuite(final RunnerBuilder builder, final Class[] classes) throws InitializationError { + public DynamicSuite(final RunnerBuilder builder, final Class... classes) throws InitializationError { super(builder, classes); } - public DynamicSuite(final Class clazz, final Class[] suiteClasses) throws InitializationError { + public DynamicSuite(final Class clazz, final Class... suiteClasses) throws InitializationError { super(clazz, suiteClasses); } @@ -56,13 +56,13 @@ public DynamicSuite(final Class clazz, final List runners) throws Ini super(clazz, runners); } - public DynamicSuite(final RunnerBuilder builder, final Class clazz, final Class[] suiteClasses) throws InitializationError { + public DynamicSuite(final RunnerBuilder builder, final Class clazz, final Class... suiteClasses) throws InitializationError { super(builder, clazz, suiteClasses); } /** * Collect suite classes from annotation. - * + * * @param clazz * main suite to get suite classes annotation from * @return list of suite classes @@ -90,4 +90,3 @@ private static Class[] getSuiteClasses(final Class clazz) throws Initializ return suiteClasses.toArray(new Class[suiteClasses.size()]); } } - diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/FilterRegistry.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/FilterRegistry.java index f399160aa..ee0a1e8fa 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/FilterRegistry.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/junit/runners/FilterRegistry.java @@ -255,11 +255,10 @@ private String describeFilters(final List filters, final String title) { if (!filters.isEmpty()) { description.append(" (").append(title).append(" filters:"); for (final Filter filter : filters) { - description.append(" ").append(filter.describe()); + description.append(' ').append(filter.describe()); } - description.append(")"); + description.append(')'); } return description.toString(); } } - diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java index 344ce61c4..9445821b3 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/mock/ExtensionRegistryMock.java @@ -50,7 +50,7 @@ private ExtensionRegistryMock() {} * @throws CoreException */ @SuppressWarnings("restriction") // for accessing RegistryProviderFactory - public static void mockRegistry() { + public static synchronized void mockRegistry() { if (registrySpy == null) { registry = RegistryFactory.getRegistry(); registrySpy = spy(registry); diff --git a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/CoreUtilTools.java b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/CoreUtilTools.java index e01c1e8a9..8d24d79a3 100644 --- a/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/CoreUtilTools.java +++ b/com.avaloq.tools.ddk.test.core/src/com/avaloq/tools/ddk/test/core/util/CoreUtilTools.java @@ -71,11 +71,12 @@ public static String generateUniqueName(final String namePrefix) { * @return the random string */ public static String randomAlphanumericString(final int count) { - String string = RandomStringUtils.randomAlphabetic(1); + StringBuilder stringBuilder = new StringBuilder(RandomStringUtils.randomAlphabetic(1)); if (count > 1) { - string = string + RandomStringUtils.randomAlphanumeric(count - 1); + stringBuilder.append(RandomStringUtils.randomAlphanumeric(count - 1)); } + String string = stringBuilder.toString(); Assert.isNotNull(string, "string"); //$NON-NLS-1$ return string.toUpperCase(Locale.ENGLISH); } diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java index 4725d521a..44367aebe 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/junit/runners/TestRunRecording.java @@ -341,6 +341,7 @@ private BufferedImage capture() { * * @return the call stack with test status information, never {@code null} */ + @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") private String captureCallStack() { StringBuilder trace = new StringBuilder(); // Same info as on the screenshot @@ -398,8 +399,7 @@ private static Set getDeadlockThreadIds() { * @return the owned lock information */ private static String getOwnedLockInfo(final ThreadInfo info) { - StringBuilder trace = new StringBuilder(); - trace.append(" Holding locks for:\r\n"); + StringBuilder trace = new StringBuilder(" Holding locks for:\r\n"); for (LockInfo lock : info.getLockedSynchronizers()) { trace.append(" " + lock.toString() + "\r\n"); } @@ -416,9 +416,9 @@ private static String getOwnedLockInfo(final ThreadInfo info) { * the {@code:ThreadInfo} for the thread in question, must not be {@code:null} * @return the thread stack trace */ + @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") private static String getCallStackTrace(final ThreadInfo info) { - StringBuilder trace = new StringBuilder(); - trace.append(" Stack:\r\n"); + StringBuilder trace = new StringBuilder(" Stack:\r\n"); int frameCount = 0; for (StackTraceElement frame : info.getStackTrace()) { trace.append(" " + frame.toString() + "\r\n"); @@ -437,18 +437,17 @@ private static String getCallStackTrace(final ThreadInfo info) { * @return the thread info */ private static String getThreadInfo() { - StringBuilder trace = new StringBuilder(); boolean contention = THREAD_BEAN.isThreadContentionMonitoringEnabled(); Set deadlockedThreads = getDeadlockThreadIds(); ThreadInfo[] threadInfos = THREAD_BEAN.dumpAllThreads(true, true); - trace.append(threadInfos.length + " active threads\r\n"); + StringBuilder trace = new StringBuilder(threadInfos.length).append(" active threads\r\n"); for (ThreadInfo info : threadInfos) { if (info == null) { trace.append(" Inactive\r\n"); continue; } boolean isDeadlocked = deadlockedThreads.contains(Long.valueOf(info.getThreadId())); - trace.append("Thread " + getTaskName(info.getThreadId(), info.getThreadName())); + trace.append("Thread ").append(getTaskName(info.getThreadId(), info.getThreadName())); if (isDeadlocked) { trace.append(" <>"); } diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java index 37d035ce0..9be4d0570 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/CoreSwtbotTools.java @@ -321,7 +321,7 @@ public static void waitForTableItem(final SWTWorkbenchBot bot, final SWTBotTable * to look for items in, must not be {@code null} * @return list of tree items, never {@code null} */ - public static java.util.List treeItems(final SWTWorkbenchBot bot, final SWTBotTree tree) { + public static List treeItems(final SWTWorkbenchBot bot, final SWTBotTree tree) { Assert.isNotNull(bot, ARGUMENT_BOT); Assert.isNotNull(tree, ARGUMENT_TREE); waitForTreeItem(bot, tree); diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/SwtWorkbenchBot.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/SwtWorkbenchBot.java index 067324ae0..27e02f130 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/SwtWorkbenchBot.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/SwtWorkbenchBot.java @@ -59,7 +59,7 @@ public class SwtWorkbenchBot extends SWTWorkbenchBot { private static final int DELAY_WIZARD_PAGE = 1000; private static final String TIMEOUT_MSG = "Timeout of {0} ms reached while waiting for Button {1} to become active"; - private ImpatientSwtWorkbenchBot fastBot; + private ImpatientSwtWorkbenchBot impatientBot; @Override public void closeAllShells() { @@ -593,10 +593,10 @@ public void closePreferencePage() { * @return the fast bot, never {@code null} */ public SWTWorkbenchBot fastBot() { - if (fastBot == null) { - fastBot = new ImpatientSwtWorkbenchBot(); + if (impatientBot == null) { + impatientBot = new ImpatientSwtWorkbenchBot(); } - return fastBot; + return impatientBot; } /** diff --git a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/matcher/AnyWidgetMatcher.java b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/matcher/AnyWidgetMatcher.java index cdf8c18ca..d349ae3c0 100644 --- a/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/matcher/AnyWidgetMatcher.java +++ b/com.avaloq.tools.ddk.test.ui/src/com/avaloq/tools/ddk/test/ui/swtbot/matcher/AnyWidgetMatcher.java @@ -21,21 +21,20 @@ public class AnyWidgetMatcher extends BaseMatcher { /** {@inheritDoc} */ + @Override public boolean matches(final Object item) { - if (item instanceof Widget) { - return true; - } - return false; + return item instanceof Widget; } /** {@inheritDoc} */ + @Override public void describeTo(final Description description) { description.appendText("any widget not null"); } /** * Convenience method to obtain a matcher of this type. - * + * * @return the base matcher */ public static BaseMatcher anyWidget() { diff --git a/com.avaloq.tools.ddk.xtext.format.test/src/com/avaloq/tools/ddk/xtext/format/validation/FormatValidationTest.java b/com.avaloq.tools.ddk.xtext.format.test/src/com/avaloq/tools/ddk/xtext/format/validation/FormatValidationTest.java index e15ddbc4b..6ee62ca58 100644 --- a/com.avaloq.tools.ddk.xtext.format.test/src/com/avaloq/tools/ddk/xtext/format/validation/FormatValidationTest.java +++ b/com.avaloq.tools.ddk.xtext.format.test/src/com/avaloq/tools/ddk/xtext/format/validation/FormatValidationTest.java @@ -17,9 +17,9 @@ import org.junit.Test; -import com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest; import com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration; import com.avaloq.tools.ddk.xtext.test.format.util.FormatTestUtil; +import com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest; import com.google.common.collect.Lists; @@ -68,7 +68,7 @@ protected void beforeEachTest() { * @param baseRules * the base rules */ - private void setFormattingRules(final String[] extendRules, final String[] baseRules) { + private void setFormattingRules(final String[] extendRules, final String... baseRules) { parentFormat = createModel(PARENT_MODEL_NAME, null, baseRules); extendingFormat = createModel(EXTENDING_MODEL_NAME, PARENT_MODEL_NAME, extendRules); } @@ -84,7 +84,8 @@ private void setFormattingRules(final String[] extendRules, final String[] baseR * the rules * @return the FormatConfiguration */ - private FormatConfiguration createModel(final String formatName, final String extendedFormatName, final String[] rules) { + @SuppressWarnings("PMD.InsufficientStringBufferDeclaration") + private FormatConfiguration createModel(final String formatName, final String extendedFormatName, final String... rules) { StringBuilder modelContent = new StringBuilder("formatter for "); modelContent.append("com.avaloq.tools.ddk.xtext.format.validation."); modelContent.append(formatName); @@ -207,4 +208,3 @@ public void requiredRulesImplemented() { assertDiagnostic(extendingFormat, FormatJavaValidator.GRAMMAR_RULE_MISSING_CODE); } } - diff --git a/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/EClassComparatorTest.java b/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/EClassComparatorTest.java index 6179329b1..a71d53ae3 100644 --- a/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/EClassComparatorTest.java +++ b/com.avaloq.tools.ddk.xtext.generator.test/src/com/avaloq/tools/ddk/xtext/generator/test/util/EClassComparatorTest.java @@ -68,10 +68,10 @@ public void testSortingByEPackage() { assertEquals(1, sorted.keySet().size()); assertEquals(Lists.newArrayList(ECLASS, EOBJECT), sorted.get(EcorePackage.eINSTANCE)); - sorted = EClassComparator.sortedEPackageGroups(Lists.newArrayList(XtextPackage.Literals.ABSTRACT_ELEMENT, XtextPackage.Literals.ACTION, EcorePackage.Literals.ECLASS), mapping); + sorted = EClassComparator.sortedEPackageGroups(Lists.newArrayList(XtextPackage.Literals.ABSTRACT_ELEMENT, XtextPackage.Literals.ACTION, ECLASS), mapping); assertEquals(3, sorted.size()); assertEquals(2, sorted.keySet().size()); - assertEquals(Lists.newArrayList(EcorePackage.Literals.ECLASS), sorted.get(EcorePackage.eINSTANCE)); + assertEquals(Lists.newArrayList(ECLASS), sorted.get(EcorePackage.eINSTANCE)); assertEquals(Lists.newArrayList(XtextPackage.Literals.ACTION, XtextPackage.Literals.ABSTRACT_ELEMENT), sorted.get(XtextPackage.eINSTANCE)); } diff --git a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/ecore/CustomClassEcoreGeneratorFragment.java b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/ecore/CustomClassEcoreGeneratorFragment.java index fb3306e7c..8856e0da0 100644 --- a/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/ecore/CustomClassEcoreGeneratorFragment.java +++ b/com.avaloq.tools.ddk.xtext.generator/src/com/avaloq/tools/ddk/xtext/generator/ecore/CustomClassEcoreGeneratorFragment.java @@ -324,7 +324,7 @@ protected Function getTypeMapper() { * @param path * URI for resource to generate into */ - @SuppressWarnings("nls") + @SuppressWarnings({"nls", "PMD.InsufficientStringBufferDeclaration"}) protected void generateCustomClassStub(final String from, final String customClassName, final URI path) { StringBuilder sb = new StringBuilder(); // sb.append(copyright()).append("\n"); diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextMarkerBasedTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextMarkerBasedTest.java index e99f2bf97..bf503e9fb 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextMarkerBasedTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextMarkerBasedTest.java @@ -196,7 +196,7 @@ protected EObject getModel(final String sourceFileName, final CharSequence sourc getMarkerTagsInfo().registerLocalTag(tag.getKey(), context, crossReference); } } catch (IOException e) { - Assert.fail("Exception while creating model from input string: " + e.getMessage()); //$NON-NLS-1$ + fail("Exception while creating model from input string: " + e.getMessage()); //$NON-NLS-1$ } return root; } diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTestUtil.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTestUtil.java index 12d5cc853..2c9e8e4bc 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTestUtil.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/AbstractXtextTestUtil.java @@ -297,7 +297,6 @@ public T getFirstInstanceOf(final EObject context, final Cla */ public void validateSource(final String sourceFileName, final CharSequence sourceContent) { String sourceContentAsString = sourceContent.toString(); - StringBuilder sourceContentWithErrors = new StringBuilder(sourceContent); EObject root = null; try { root = getModel(sourceFileName, sourceContentAsString); @@ -306,6 +305,7 @@ public void validateSource(final String sourceFileName, final CharSequence sourc return; } + StringBuilder sourceContentWithErrors = new StringBuilder(sourceContent); // Store all the validation errors Set errors = Sets.newHashSet(); errors.addAll(Collections2.filter(getDiagnostician().validate(root).getChildren(), new Predicate() { @@ -338,7 +338,7 @@ public boolean apply(final Diagnostic input) { while (offsetIterator.hasNext()) { sourceContentWithErrors.append(SPLITTER); sourceContentWithErrors.append(String.format(ERROR, errorNumber++)); - sourceContentWithErrors.append(errorMessages.get(offsetIterator.next()) + "\n"); + sourceContentWithErrors.append(errorMessages.get(offsetIterator.next())).append('\n'); } if (errorNumber > 1) { sourceContentWithErrors.append(SPLITTER); @@ -366,7 +366,7 @@ private Pair processDiagnostic(final Diagnostic diagnostic) { if (diagnostic instanceof AbstractValidationDiagnostic) { AbstractValidationDiagnostic avd = (AbstractValidationDiagnostic) diagnostic; errorMessage.append("Unexpected issue found. Code '"); - errorMessage.append(avd.getIssueCode() + "'\n"); + errorMessage.append(avd.getIssueCode()).append("'\n"); errorMessage.append(avd.getMessage()); if (avd instanceof FeatureBasedDiagnostic && ((FeatureBasedDiagnostic) avd).getFeature() != null) { List nodes = NodeModelUtils.findNodesForFeature(avd.getSourceEObject(), ((FeatureBasedDiagnostic) avd).getFeature()); @@ -403,4 +403,3 @@ public INode findFirstNonHiddenLeafNode(final INode node) { return node; } } - diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/PluginTestProjectManager.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/PluginTestProjectManager.java index 96f59ec50..781f36182 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/PluginTestProjectManager.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/PluginTestProjectManager.java @@ -33,7 +33,6 @@ import org.eclipse.xtext.ui.util.PluginProjectFactory; import org.junit.Assert; -import com.google.common.collect.Lists; import com.google.inject.Injector; @@ -62,7 +61,7 @@ public PluginTestProjectManager(final Injector injector) { /** * Creates a plugin Project. - * + * * @param injector * the injector * @param name @@ -74,7 +73,7 @@ public PluginTestProjectManager(final Injector injector) { public static IProject createPluginProject(final Injector injector, final String name) throws CoreException { final PluginProjectFactory projectFactory = injector.getInstance(PluginProjectFactory.class); projectFactory.setProjectName(name); - projectFactory.addFolders(Lists.newArrayList(DEFAULT_SOURCE_FOLDER, DEFAULT_SOURCE_GEN_FOLDER)); + projectFactory.addFolders(newArrayList(DEFAULT_SOURCE_FOLDER, DEFAULT_SOURCE_GEN_FOLDER)); projectFactory.addBuilderIds(JavaCore.BUILDER_ID, "org.eclipse.pde.ManifestBuilder", "org.eclipse.pde.SchemaBuilder", XtextProjectHelper.BUILDER_ID); projectFactory.addProjectNatures(JavaCore.NATURE_ID, "org.eclipse.pde.PluginNature", XtextProjectHelper.NATURE_ID); projectFactory.addRequiredBundles(REQUIRED_BUNDLES); @@ -160,4 +159,3 @@ public URI createPlatformUri(final String encodedFileName) { return URI.createPlatformResourceURI('/' + TEST_PROJECT_NAME + "/" + DEFAULT_SOURCE_FOLDER + "/" + encodedFileName, true); } } - diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/contentassist/AbstractAcfContentAssistTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/contentassist/AbstractAcfContentAssistTest.java index aed987701..72d848765 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/contentassist/AbstractAcfContentAssistTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/contentassist/AbstractAcfContentAssistTest.java @@ -63,7 +63,7 @@ protected AcfContentAssistProcessorTestBuilder newBuilder() { * the computed proposals * @return the completion proposal display strings */ - private String getCompletionProposalDisplayStrings(final ICompletionProposal[] computedProposals) { + private String getCompletionProposalDisplayStrings(final ICompletionProposal... computedProposals) { String result = ""; for (ICompletionProposal p : computedProposals) { result += p.getDisplayString() + SEPARATOR; // NOPMD diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/scoping/AbstractScopingTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/scoping/AbstractScopingTest.java index 65e9bbe9f..11a4fdbdb 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/scoping/AbstractScopingTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/scoping/AbstractScopingTest.java @@ -52,12 +52,12 @@ import org.eclipse.xtext.scoping.IScopeProvider; import org.eclipse.xtext.util.Triple; -import com.avaloq.tools.ddk.xtext.test.AbstractXtextMarkerBasedTest; import com.avaloq.tools.ddk.xtext.linking.AbstractFragmentProvider; import com.avaloq.tools.ddk.xtext.naming.QualifiedNames; import com.avaloq.tools.ddk.xtext.resource.IFingerprintComputer; import com.avaloq.tools.ddk.xtext.scoping.ContainerQuery; import com.avaloq.tools.ddk.xtext.scoping.IDomain; +import com.avaloq.tools.ddk.xtext.test.AbstractXtextMarkerBasedTest; import com.avaloq.tools.ddk.xtext.util.EObjectUtil; import com.avaloq.tools.ddk.xtext.util.Regexps; import com.google.common.base.Function; @@ -79,7 +79,7 @@ public abstract class AbstractScopingTest extends AbstractXtextMarkerBasedTest { public static final String INFERRED_DATA_DICTIONARY_FRAGMENT = SEGMENT_SEPARATOR + "1"; private static final String NUMBER_OF_ELEMENTS_MESSAGE = "Incorrect number of elements in scope."; - private static final Splitter FRAGMENT_SEGMENT_SPLITTER = Splitter.onPattern("(? getExpectedURIs(final EObject context, final EClass modelElementClass, final String[] sources) { + private Set getExpectedURIs(final EObject context, final EClass modelElementClass, final String... sources) { HashSet expectedURIs = new HashSet(); for (String source : sources) { expectedURIs.add(Iterables.get(getExportedObjects(context, modelElementClass, source), 0).getEObjectURI()); @@ -554,6 +555,7 @@ public static String createURIFragment(final Object... segments) { * list of feature IDs, indexes (for multi valued features), and other fragment segments * @return URI fragment */ + @SuppressWarnings("PMD.UnusedPrivateMethod") private static String createURIFragment(final boolean topLevel, final Object... segments) { StringBuilder b = new StringBuilder(); if (segments.length == 0) { @@ -576,15 +578,15 @@ private static String createURIFragment(final boolean topLevel, final Object... } b.append(lastSegment); if (reps > 1) { - b.append(AbstractFragmentProvider.REP_SEPARATOR).append(reps); + b.append(REP_SEPARATOR).append(reps); reps = 1; } - b.append(AbstractFragmentProvider.SEGMENT_SEPARATOR); + b.append(SEGMENT_SEPARATOR); lastSegment = parsedSegments.get(i); } b.append(lastSegment); if (reps > 1) { - b.append(AbstractFragmentProvider.REP_SEPARATOR).append(reps); + b.append(REP_SEPARATOR).append(reps); } return b.toString(); } @@ -774,12 +776,12 @@ protected void assertEObjectsAreEqual(final EObject sourceObject, final EObject */ protected EObject getCrossReferencedObject(final int sourceTag, final boolean traverseImplicitItems, final CrossReference crossReference) { EObject context = getObjectForTag(sourceTag); - EObject sourceObject = null; if (crossReference == null) { throw new IllegalArgumentException(NLS.bind("Cross reference on object ''{0}'' could not be resolved.", context.toString())); //$NON-NLS-1$ } // We only handle references in assignments Assignment assignment = EObjectUtil.eContainer(crossReference, Assignment.class); + EObject sourceObject = null; String featureName = assignment.getFeature(); EReference reference = (EReference) context.eClass().getEStructuralFeature(featureName); if (reference.isMany()) { @@ -800,4 +802,3 @@ protected EObject getCrossReferencedObject(final int sourceTag, final boolean tr return sourceObject; } } - diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/contentassist/AbstractContentAssistUiTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/contentassist/AbstractContentAssistUiTest.java index e9c29463c..c3648b371 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/contentassist/AbstractContentAssistUiTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/contentassist/AbstractContentAssistUiTest.java @@ -28,8 +28,8 @@ import org.junit.Assert; import com.avaloq.tools.ddk.xtext.common.ui.contentassist.TemplatesFirstCompletionProposalComparator; -import com.avaloq.tools.ddk.xtext.test.ui.AbstractXtextEditorTest; import com.avaloq.tools.ddk.xtext.resource.Messages; +import com.avaloq.tools.ddk.xtext.test.ui.AbstractXtextEditorTest; import com.avaloq.tools.ddk.xtext.ui.util.UiThreadDispatcher; import com.google.common.base.Function; import com.google.common.collect.Iterables; @@ -92,7 +92,7 @@ public void run() { * the proposals * @return the completion proposal display strings */ - private List getCompletionProposalDisplayStrings(final ICompletionProposal[] proposals) { + private List getCompletionProposalDisplayStrings(final ICompletionProposal... proposals) { return Lists.newArrayList(Iterables.transform(Arrays.asList(proposals), new Function() { @Override public String apply(final ICompletionProposal from) { @@ -149,6 +149,7 @@ protected void assertTemplateProposalExistsAndSuccessful(final String sourceFile * @param offset * offset in test file */ + @SuppressWarnings("PMD.UseObjectForClearerAPI") protected void assertTemplateProposalExistsAndSuccessful(final String sourceFileName, final String sourceContent, final String contentassistProposal, final String expectedContent, final int offset) { if (sourceContent == null) { Assert.assertNotNull(String.format("There must be an existing test source with the file name '%s'.", sourceFileName), getTestSource(sourceFileName)); @@ -258,4 +259,3 @@ protected int getTotalOffsetForToken(final ICompositeNode parserNode, final Stri } } - diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/quickfix/AbstractQuickFixTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/quickfix/AbstractQuickFixTest.java index 509a416c8..fbbffd2ee 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/quickfix/AbstractQuickFixTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/ui/quickfix/AbstractQuickFixTest.java @@ -25,11 +25,11 @@ import org.eclipse.xtext.validation.Issue; import org.junit.Assert; -import com.avaloq.tools.ddk.xtext.test.ui.AbstractXtextEditorTest; -import com.avaloq.tools.ddk.xtext.ui.util.UiThreadDispatcher; import com.avaloq.tools.ddk.check.runtime.quickfix.ICoreModificationContext; import com.avaloq.tools.ddk.check.runtime.ui.quickfix.CoreIssueModificationContext; import com.avaloq.tools.ddk.check.runtime.ui.quickfix.IssueResolutionWrapper; +import com.avaloq.tools.ddk.xtext.test.ui.AbstractXtextEditorTest; +import com.avaloq.tools.ddk.xtext.ui.util.UiThreadDispatcher; import com.google.common.base.Function; import com.google.common.base.Predicates; import com.google.common.collect.Iterables; @@ -43,6 +43,7 @@ * Besides overriding the abstract method getQuickFixFileName(), subclasses have to implement * the test method itself which tests for existence and resolutions of the diagnostic issues. */ +@SuppressWarnings("PMD.UseObjectForClearerAPI") public abstract class AbstractQuickFixTest extends AbstractXtextEditorTest { private IssueResolutionProvider getIssueResolutionProvider() { @@ -455,4 +456,3 @@ public void run() { return resolutions; } } - diff --git a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/validation/AbstractValidationTest.java b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/validation/AbstractValidationTest.java index 548aa9167..cdf82358c 100644 --- a/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/validation/AbstractValidationTest.java +++ b/com.avaloq.tools.ddk.xtext.test.core/src/com/avaloq/tools/ddk/xtext/test/validation/AbstractValidationTest.java @@ -685,8 +685,8 @@ protected void assertNoDiagnosticOnObject(final Diagnostic diagnostics, final EO * the diagnostic to check for issues */ private void assertNoDiagnostics(final Diagnostic diagnostics) { - Assert.assertTrue(diagnostics.getCode() == Diagnostic.OK); - Assert.assertTrue(diagnostics.getChildren().isEmpty()); + assertTrue(diagnostics.getCode() == Diagnostic.OK); + assertTrue(diagnostics.getChildren().isEmpty()); } /** @@ -699,13 +699,12 @@ private void assertNoDiagnostics(final Diagnostic diagnostics) { * @return true, if given list of errors contains an error with given message */ public static boolean containsError(final EList errors, final String message) { - return !Iterables.isEmpty(errors) - && Iterables.contains(Iterables.transform(errors, new Function() { - @Override - public String apply(final org.eclipse.emf.ecore.resource.Resource.Diagnostic d) { - return d.getMessage(); - } - }), message); + return !Iterables.isEmpty(errors) && Iterables.contains(Iterables.transform(errors, new Function() { + @Override + public String apply(final Resource.Diagnostic d) { + return d.getMessage(); + } + }), message); } /** @@ -798,9 +797,7 @@ protected void assertNoSyntaxErrorsOnResource(final String sourceFileName, final final XtextTestSource testSource = createTestSource(sourceFileName, sourceContent.toString()); final List errors = testSource.getModel().eResource().getErrors().stream().filter(error -> error instanceof XtextSyntaxDiagnostic).collect(Collectors.toList()); if (!errors.isEmpty()) { - StringBuilder sb = new StringBuilder(); - sb.append("Syntax error is present in the test source.\n"); - sb.append("List of all found syntax errors:"); + StringBuilder sb = new StringBuilder("Syntax error is present in the test source.\nList of all found syntax errors:"); errors.forEach(err -> sb.append("\n\t " + err.getMessage())); Assert.fail(sb.toString()); } @@ -814,8 +811,7 @@ protected void assertNoSyntaxErrorsOnResource(final String sourceFileName, final */ private void memorizeResourceErrors(final EObject root) { for (AbstractDiagnostic ad : Iterables.filter(root.eResource().getErrors(), AbstractDiagnostic.class)) { - StringBuilder sb = new StringBuilder(); - sb.append("Unexpected error: '"); + StringBuilder sb = new StringBuilder("Unexpected error: '"); sb.append(ad.getMessage()); sb.append(DOT_AND_LINEBREAK); memorizeErrorOnPosition(ad.getOffset(), sb.toString());