Skip to content

Commit 92e68f5

Browse files
committed
chore: enable CPD detection (pmd.cpd.min 100000 -> 100), de-dup and baseline
pmd.cpd.min=100000 effectively disabled PMD's copy/paste detector: cpd-check passed on virtually any duplication. Lower the threshold to 100 (PMD's default) so CPD detects duplication going forward. At 100 the reactor surfaces pre-existing duplications; each was assessed for whether it is genuinely extractable logic or incidental/deliberate similarity: - Refactored: the identical isExtensionUpdateRequired guard chain in the Check validator/quickfix extension helpers lifted to AbstractCheckExtensionHelper (keyed on getExtensionPointId() plus a new protected getTargetClassName() hook); the identical private featureIterable helper in Abstract{,Streaming}FingerprintComputer extracted to a shared package-private FingerprintFeatures utility. - Baselined with per-site CPD-OFF markers and reasons: test scaffolding in AbstractValidationTest, sibling test cases in ParameterListMatcherTest, incidental token overlap in DispatchingCheckImpl, migrated Xtend dispatch/emission code in FormatJvmModelInferrer (file-scoped) and FormatFragment2, and sibling test-class scaffolding in the two CheckCfg test classes. Full-reactor pmd:cpd-check is clean at threshold 100. Closes #1339.
1 parent df46e04 commit 92e68f5

16 files changed

Lines changed: 155 additions & 115 deletions

File tree

com.avaloq.tools.ddk.check.runtime.core/src/com/avaloq/tools/ddk/check/runtime/issue/DispatchingCheckImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
@SuppressWarnings({"checkstyle:AbstractClassName"})
3636
public abstract class DispatchingCheckImpl extends AbstractCheckImpl {
3737

38+
// CPD-OFF — incidental token overlap (DI field + trace/try idiom), not an extractable unit (#1339)
3839
@Inject
3940
private ITraceSet traceSet;
4041

@@ -72,6 +73,7 @@ public boolean validate(final EClass eClass, final EObject object, final Diagnos
7273

7374
State state = new State();
7475
state.chain = diagnostics;
76+
// CPD-ON
7577
state.eventCollector = eventCollector;
7678

7779
validate(checkMode, object, state);
@@ -123,6 +125,7 @@ protected void validate(final String contextName, final String qContextName, fin
123125
if (!disabledMethodTracker.isDisabled(contextName)) {
124126
Collector eventCollector = diagnosticCollector.getEventCollector();
125127
try {
128+
// CPD-OFF — incidental token overlap (DI field + trace/try idiom), not an extractable unit (#1339)
126129
traceStart(qContextName, object, eventCollector);
127130
checkAction.run();
128131
} catch (Exception e) {
@@ -160,6 +163,7 @@ protected static class State implements ValidationMessageAcceptorMixin, Diagnost
160163
// CHECKSTYLE:OFF
161164
public DiagnosticChain chain;
162165
public CheckType currentCheckType;
166+
// CPD-ON
163167
public boolean hasErrors;
164168
public ResourceValidationRuleSummaryEvent.Collector eventCollector;
165169
// CHECKSTYLE:ON

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/AbstractCheckDocumentationExtensionHelper.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ protected boolean isExtensionEnabled(final IPluginModelBase base, final CheckCat
4444
return !config.isGenerateLanguageInternalChecks();
4545
}
4646

47+
/**
48+
* Documentation extensions do not reference a generated target class, so documentation helpers have no target class name and
49+
* provide their own {@link #isExtensionUpdateRequired} logic that never consults it.
50+
*
51+
* @param catalog
52+
* the check catalog
53+
* @return never returns normally
54+
*/
55+
@SuppressWarnings("PMD.UnusedFormalParameter")
56+
@Override
57+
protected String getTargetClassName(final CheckCatalog catalog) {
58+
throw new UnsupportedOperationException("Documentation extension helpers have no target class"); //$NON-NLS-1$
59+
}
60+
4761
}

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/AbstractCheckExtensionHelper.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,41 @@ protected boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IP
147147
return extension.getPoint().equals(getExtensionPointId()); // if points are different, given extension must not be updated
148148
}
149149

150+
/**
151+
* Checks whether a class-referencing extension (validator / quickfix) needs updating: it must point at this helper's
152+
* extension point and reference exactly one element whose target class, language and catalog name still match the
153+
* check catalog. Shared by the validator and quickfix helpers, whose only difference is {@link #getTargetClassName}.
154+
*
155+
* @param catalog
156+
* the catalog
157+
* @param extension
158+
* the extension
159+
* @param elements
160+
* the elements
161+
* @return true, if the extension must be regenerated
162+
*/
163+
protected boolean isTargetClassExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
164+
// CHECKSTYLE:OFF
165+
// @Format-Off
166+
return getExtensionPointId().equals(extension.getPoint())
167+
&& (!extensionNameMatches(extension, catalog)
168+
|| Iterables.size(elements) != 1
169+
|| !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog))
170+
|| catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null
171+
|| catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName()));
172+
// @Format-On
173+
// CHECKSTYLE:ON
174+
}
175+
176+
/**
177+
* Gets the target class name based on the package path of given check catalog.
178+
*
179+
* @param catalog
180+
* the check catalog
181+
* @return the target class FQN
182+
*/
183+
protected abstract String getTargetClassName(CheckCatalog catalog);
184+
150185
/**
151186
* Updates a given extension to values calculated using given check catalog.
152187
*

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckPreferencesExtensionHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ public String getExtensionPointName(final CheckCatalog catalog) {
160160
* the check catalog
161161
* @return the target class FQN
162162
*/
163-
private String getTargetClassName(final CheckCatalog catalog) {
163+
@Override
164+
protected String getTargetClassName(final CheckCatalog catalog) {
164165
return getFromServiceProvider(CheckGeneratorNaming.class, catalog).qualifiedPreferenceInitializerClassName(catalog);
165166
}
166167

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckQuickfixExtensionHelper.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,22 +120,14 @@ protected void doUpdateExtension(final CheckCatalog catalog, final IPluginExtens
120120
* the check catalog
121121
* @return the target class FQN
122122
*/
123-
private String getTargetClassName(final CheckCatalog catalog) {
123+
@Override
124+
protected String getTargetClassName(final CheckCatalog catalog) {
124125
return getFromServiceProvider(CheckGeneratorNaming.class, catalog).qualifiedQuickfixClassName(catalog);
125126
}
126127

127128
@Override
128-
public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
129-
// CHECKSTYLE:OFF
130-
// @Format-Off
131-
return QUICKFIX_EXTENSION_POINT_ID.equals(extension.getPoint())
132-
&& (!extensionNameMatches(extension, catalog)
133-
|| Iterables.size(elements) != 1
134-
|| !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog))
135-
|| catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null
136-
|| catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName()));
137-
// @Format-On
138-
// CHECKSTYLE:ON
129+
protected boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
130+
return isTargetClassExtensionUpdateRequired(catalog, extension, elements);
139131
}
140132

141133
}

com.avaloq.tools.ddk.check.ui/src/com/avaloq/tools/ddk/check/ui/builder/util/CheckValidatorExtensionHelper.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,23 +112,14 @@ private String getCatalogResourceName(final CheckCatalog catalog) {
112112
* the check catalog
113113
* @return the target class FQN
114114
*/
115-
private String getTargetClassName(final CheckCatalog catalog) {
115+
@Override
116+
protected String getTargetClassName(final CheckCatalog catalog) {
116117
return getFromServiceProvider(CheckGeneratorNaming.class, catalog).qualifiedValidatorClassName(catalog);
117118
}
118119

119120
@Override
120-
public boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
121-
// CHECKSTYLE:OFF
122-
// @Format-Off
123-
return CHECK_EXTENSION_POINT_ID.equals(extension.getPoint())
124-
&& (!extensionNameMatches(extension, catalog)
125-
|| Iterables.size(elements) != 1
126-
|| !targetClassMatches(Iterables.get(elements, 0), getTargetClassName(catalog))
127-
|| catalog.getGrammar() == null && Iterables.get(elements, 0).getAttribute(LANGUAGE_ELEMENT_TAG) != null
128-
|| catalog.getGrammar() != null && !languageNameMatches(Iterables.get(elements, 0), catalog.getGrammar().getName())
129-
);
130-
// @Format-On
131-
// CHECKSTYLE:ON
121+
protected boolean isExtensionUpdateRequired(final CheckCatalog catalog, final IPluginExtension extension, final Iterable<IPluginElement> elements) {
122+
return isTargetClassExtensionUpdateRequired(catalog, extension, elements);
132123
}
133124

134125
}

com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/contentassist/CheckCfgContentAssistTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ default Test (
4545
}
4646
""";
4747

48+
// CPD-OFF — sibling test-class scaffolding, kept explicit (#1339)
4849
@Override
4950
protected AbstractXtextTestUtil getXtextTestUtil() {
5051
return CheckCfgTestUtil.getInstance();
@@ -70,6 +71,7 @@ protected void afterAllTests() {
7071

7172
@Test
7273
public void testConfiguredParameterProposals() {
74+
// CPD-ON
7375
final String source = SOURCE_TEMPLATE.formatted(TestPropertySpecificationWithExpectedValues.INSTANCE.getName(), expected(TestPropertySpecificationWithExpectedValues.INSTANCE.getExpectedValues()));
7476
assertKernelSourceProposals("ConfiguredParameterProposals.checkcfg", source);
7577
}

com.avaloq.tools.ddk.checkcfg.core.test/src/com/avaloq/tools/ddk/checkcfg/validation/CheckCfgConfiguredParameterValidationsTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
public class CheckCfgConfiguredParameterValidationsTest extends AbstractValidationTest {
3030

31+
// CPD-OFF — sibling test-class scaffolding, kept explicit (#1339)
3132
@Override
3233
protected AbstractXtextTestUtil getXtextTestUtil() {
3334
return CheckCfgTestUtil.getInstance();
@@ -53,6 +54,7 @@ protected void afterAllTests() {
5354

5455
@Test
5556
public void testConfiguredParameterValues() {
57+
// CPD-ON
5658
final TestPropertySpecificationWithExpectedValues allowedOnly = TestPropertySpecificationWithExpectedValues.INSTANCE;
5759
final TestPropertySpecificationWithOutExpectedValues acceptsAny = TestPropertySpecificationWithOutExpectedValues.INSTANCE;
5860
final String source = """

com.avaloq.tools.ddk.typesystem.test/src/com/avaloq/tools/ddk/typesystem/ParameterListMatcherTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ void testUnnamedFormalAfterNamed4() {
893893
assertSame(unnamedFormal2, matchResult.getUnnamedFormalsAfterNamed().get(1), UNNAMED_FORMAL_AFTER_NAMED_NOT_LOCATED);
894894
}
895895

896+
// CPD-OFF — explicit parameterized test cases, kept readable over shared (#1339)
896897
@Test
897898
void testForceMatchByPosition1() {
898899
List<NamedFormalParameter> formals = new ArrayList<NamedFormalParameter>();
@@ -946,5 +947,6 @@ void testForceMatchByPosition3() {
946947
checkParameterMatch(IParameterMatchChecker.MatchStatus.MATCH, actuals.get(1), formals.get(1), matches.get(1));
947948
checkParameterMatch(IParameterMatchChecker.MatchStatus.MATCH, actuals.get(2), formals.get(2), matches.get(2));
948949
}
950+
// CPD-ON
949951

950952
}

com.avaloq.tools.ddk.xtext.format.generator/src/com/avaloq/tools/ddk/xtext/format/generator/FormatFragment2.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ protected XtendFileAccess doGetXtendStubFile() {
164164
protected void appendTo(final TargetStringConcatenation builder) {
165165
builder.append("import com.avaloq.tools.ddk.xtext.formatting.ExtendedLineEntry");
166166
builder.newLine();
167+
// CPD-OFF — parallel Xtend/Java formatter-stub emission, kept explicit (#1339)
167168
builder.append("import java.util.List");
168169
builder.newLine();
169170
builder.newLine();
@@ -184,6 +185,7 @@ protected void appendTo(final TargetStringConcatenation builder) {
184185
builder.append(" */");
185186
builder.newLine();
186187
builder.append("class ");
188+
// CPD-ON
187189
builder.append(getFormatterStub(getGrammar()).getSimpleName());
188190
builder.append(" extends ");
189191
builder.append(FormatGeneratorUtil.getFormatterName(getGrammar(), "Abstract"));
@@ -251,6 +253,7 @@ protected void appendTo(final TargetStringConcatenation builder) {
251253
builder.append("import java.util.List;");
252254
builder.newLine();
253255
builder.newLine();
256+
// CPD-OFF — parallel Xtend/Java formatter-stub emission, kept explicit (#1339)
254257
builder.append("import org.eclipse.xtext.TerminalRule;");
255258
builder.newLine();
256259
builder.newLine();
@@ -271,6 +274,7 @@ protected void appendTo(final TargetStringConcatenation builder) {
271274
builder.append(" */");
272275
builder.newLine();
273276
builder.append("public class ");
277+
// CPD-ON
274278
builder.append(getFormatterStub(getGrammar()).getSimpleName());
275279
builder.append(" extends ");
276280
builder.append(FormatGeneratorUtil.getFormatterName(getGrammar(), "Abstract"));

0 commit comments

Comments
 (0)