Skip to content

Commit

Permalink
feat: modify Check generator to not reference event Collector
Browse files Browse the repository at this point in the history
Have it leave out ResourceValidationRuleSummaryEvent.Collector from the
generated 'validate' method signature so that the checkedTypeRef call to
create a JvmTypeReference to the particular inner class cannot fail.

That is something that apparently could in some situations happen.
  • Loading branch information
hasu authored and rubenporras committed Aug 26, 2024
1 parent 84b0674 commit 887710f
Show file tree
Hide file tree
Showing 62 changed files with 35 additions and 2,680 deletions.
2 changes: 0 additions & 2 deletions com.avaloq.tools.ddk.check.core.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ Require-Bundle: com.avaloq.tools.ddk.check.core,
org.eclipse.ui.ide,
org.eclipse.core.runtime,
org.eclipse.xtend.lib,
org.eclipse.xtext.junit4,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.testing,
org.junit,
org.mockito,
com.avaloq.tools.ddk.check.runtime.core,
org.eclipse.ui.workbench;resolution:=optional,
org.eclipse.xtext.xbase,
org.eclipse.xtext.xbase.junit,
org.eclipse.xtext.xbase.lib,
org.apache.logging.log4j,
org.apache.commons.lang,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ Require-Bundle: org.eclipse.ui,
com.avaloq.tools.ddk.test.ui,
com.avaloq.tools.ddk.check.runtime.core,
org.junit,
com.google.guava,
org.eclipse.xtext.junit4
com.google.guava
Export-Package: com.avaloq.tools.ddk.check.runtime.test.core
Import-Package: org.mockito,
org.mockito.stubbing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Require-Bundle: com.avaloq.tools.ddk.check.runtime.core,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.xtext,
org.eclipse.xtext.junit4,
org.eclipse.xtext.testing,
org.eclipse.xtext.ui.testing,
org.junit,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.avaloq.tools.ddk.check.validation;

import com.avaloq.tools.ddk.check.runtime.issue.AbstractDispatchingCheckImpl;
import com.avaloq.tools.ddk.check.runtime.issue.DispatchingCheckImpl;
import com.avaloq.tools.ddk.check.testLanguage.Greeting;
import com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import org.eclipse.emf.ecore.EObject;
Expand All @@ -15,7 +14,7 @@
* Validator for ExecutionEnvironment.
*/
@SuppressWarnings("all")
public class ExecutionEnvironmentCheckImpl extends AbstractDispatchingCheckImpl {
public class ExecutionEnvironmentCheckImpl extends DispatchingCheckImpl {
@Inject
private ExecutionEnvironmentCheckCatalog executionEnvironmentCatalog;

Expand All @@ -28,19 +27,19 @@ public final ImmutableMap<String, String> getIssueCodeToLabelMap() {
}

@Override
public void validate(final CheckMode checkMode, final EObject object, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector, final ResourceValidationRuleSummaryEvent.Collector eventCollector) {
public void validate(final CheckMode checkMode, final EObject object, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
if (checkMode.shouldCheck(CheckType.NORMAL)) {
diagnosticCollector.setCurrentCheckType(CheckType.NORMAL);
if (object instanceof final com.avaloq.tools.ddk.check.testLanguage.Greeting castObject) {
validate("greetingNameLengthGreeting", "ExecutionEnvironment.greetingNameLengthGreeting", object,
() -> greetingNameLengthGreeting(castObject, diagnosticCollector), diagnosticCollector, eventCollector);
() -> greetingNameLengthGreeting(castObject, diagnosticCollector), diagnosticCollector);
}
}
}

private class GreetingNameLengthClass {

public void runGreeting(final Greeting g, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void runGreeting(final Greeting g, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
int _length = g.getName().length();
boolean _greaterThan = (_length > 5);
if (_greaterThan) {
Expand Down Expand Up @@ -78,7 +77,7 @@ public void runGreeting(final Greeting g, final AbstractDispatchingCheckImpl.Dia
* greetingNameLengthGreeting.
*/
@Check(CheckType.NORMAL)
public void greetingNameLengthGreeting(final Greeting context, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void greetingNameLengthGreeting(final Greeting context, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
greetingNameLengthImpl.runGreeting(context, diagnosticCollector);
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.avaloq.tools.ddk.check.validation;

import com.avaloq.tools.ddk.check.lib.IResourceCache;
import com.avaloq.tools.ddk.check.runtime.issue.AbstractDispatchingCheckImpl;
import com.avaloq.tools.ddk.check.runtime.issue.DispatchingCheckImpl;
import com.avaloq.tools.ddk.check.testLanguage.Greeting;
import com.avaloq.tools.ddk.xtext.tracing.ResourceValidationRuleSummaryEvent;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
Expand All @@ -21,7 +20,7 @@
* Validator for LibraryChecks.
*/
@SuppressWarnings("all")
public class LibraryChecksCheckImpl extends AbstractDispatchingCheckImpl {
public class LibraryChecksCheckImpl extends DispatchingCheckImpl {
@Inject
private LibraryChecksCheckCatalog libraryChecksCatalog;

Expand All @@ -37,18 +36,18 @@ public final ImmutableMap<String, String> getIssueCodeToLabelMap() {
}

@Override
public void validate(final CheckMode checkMode, final EObject object, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector, final ResourceValidationRuleSummaryEvent.Collector eventCollector) {
public void validate(final CheckMode checkMode, final EObject object, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
if (checkMode.shouldCheck(CheckType.FAST)) {
diagnosticCollector.setCurrentCheckType(CheckType.FAST);
if (object instanceof final com.avaloq.tools.ddk.check.testLanguage.Greeting castObject) {
validate("checkCatalogIsActiveGreeting", "LibraryChecks.checkCatalogIsActiveGreeting", object,
() -> checkCatalogIsActiveGreeting(castObject, diagnosticCollector), diagnosticCollector, eventCollector);
() -> checkCatalogIsActiveGreeting(castObject, diagnosticCollector), diagnosticCollector);
validate("cacheInjectionFailedGreeting", "LibraryChecks.cacheInjectionFailedGreeting", object,
() -> cacheInjectionFailedGreeting(castObject, diagnosticCollector), diagnosticCollector, eventCollector);
() -> cacheInjectionFailedGreeting(castObject, diagnosticCollector), diagnosticCollector);
validate("cacheDoesntWorkGreeting", "LibraryChecks.cacheDoesntWorkGreeting", object,
() -> cacheDoesntWorkGreeting(castObject, diagnosticCollector), diagnosticCollector, eventCollector);
() -> cacheDoesntWorkGreeting(castObject, diagnosticCollector), diagnosticCollector);
validate("formalParametersGreeting", "LibraryChecks.formalParametersGreeting", object,
() -> formalParametersGreeting(castObject, diagnosticCollector), diagnosticCollector, eventCollector);
() -> formalParametersGreeting(castObject, diagnosticCollector), diagnosticCollector);
}
}
}
Expand All @@ -57,7 +56,7 @@ public void validate(final CheckMode checkMode, final EObject object, final Abst
* checkCatalogIsActiveGreeting.
*/
@Check(CheckType.FAST)
public void checkCatalogIsActiveGreeting(final Greeting it, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {// Issue diagnostic
public void checkCatalogIsActiveGreeting(final Greeting it, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {// Issue diagnostic
libraryChecksCatalog.accept(diagnosticCollector, //
it, // context EObject
null, // EStructuralFeature
Expand All @@ -72,7 +71,7 @@ public void checkCatalogIsActiveGreeting(final Greeting it, final AbstractDispat
* cacheInjectionFailedGreeting.
*/
@Check(CheckType.FAST)
public void cacheInjectionFailedGreeting(final Greeting g, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void cacheInjectionFailedGreeting(final Greeting g, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
if ((LibraryChecksCheckImpl.this.cache == null)) {// Issue diagnostic
libraryChecksCatalog.accept(diagnosticCollector, //
g, // context EObject
Expand All @@ -89,7 +88,7 @@ public void cacheInjectionFailedGreeting(final Greeting g, final AbstractDispatc
* cacheDoesntWorkGreeting.
*/
@Check(CheckType.FAST)
public void cacheDoesntWorkGreeting(final Greeting it, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void cacheDoesntWorkGreeting(final Greeting it, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
String _qualifiedCatalogName = this.getQualifiedCatalogName();
final String key = (_qualifiedCatalogName + ".testValue");
try {
Expand Down Expand Up @@ -132,7 +131,7 @@ private class FormalParametersClass {



public void runGreeting(final Greeting it, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void runGreeting(final Greeting it, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
final String p1 = libraryChecksCatalog.getFormalParameters_Param1(it);
final boolean p2 = false;
final List<String> expectedNames = ImmutableList.<String>of("foo", "bar", "ba\u0001\nz");
Expand Down Expand Up @@ -255,7 +254,7 @@ public void runGreeting(final Greeting it, final AbstractDispatchingCheckImpl.Di
* formalParametersGreeting.
*/
@Check(CheckType.FAST)
public void formalParametersGreeting(final Greeting context, final AbstractDispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
public void formalParametersGreeting(final Greeting context, final DispatchingCheckImpl.DiagnosticCollector diagnosticCollector) {
formalParametersImpl.runGreeting(context, diagnosticCollector);
}
}
1 change: 0 additions & 1 deletion com.avaloq.tools.ddk.check.ui.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Require-Bundle: org.junit,
org.eclipse.xtext.common.types.ui,
org.eclipse.jdt.core,
org.eclipse.ui.ide,
org.eclipse.xtext.junit4,
org.eclipse.xtext.xbase.lib,
org.eclipse.core.runtime,
org.slf4j.ext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Require-Bundle: com.avaloq.tools.ddk.test.core,
org.eclipse.ui.ide,
org.eclipse.core.runtime,
org.eclipse.xtend.lib,
org.eclipse.xtext.junit4,
org.eclipse.xtext.ui.testing,
org.junit,
org.eclipse.xtext.xbase.lib,
Expand Down
7 changes: 0 additions & 7 deletions com.avaloq.tools.ddk.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,4 @@
version="0.0.0"
unpack="false"/>

<plugin
id="com.avaloq.tools.ddk.xtextspy"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,12 @@ Bundle-ActivationPolicy: lazy
Require-Bundle: com.avaloq.tools.ddk.sample.helloworld,
com.avaloq.tools.ddk.sample.helloworld.ui,
org.junit,
org.eclipse.xtext.junit4,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.xbase.lib,
org.eclipse.core.runtime,
org.eclipse.ui.workbench;resolution:=optional,
org.eclipse.xtext.xbase.junit,
com.avaloq.tools.ddk.check.runtime.core,
com.avaloq.tools.ddk.check.runtime.ui,
com.avaloq.tools.ddk.check.core.test,
Expand Down
7 changes: 0 additions & 7 deletions com.avaloq.tools.ddk.source.feature/feature.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,4 @@
version="0.0.0"
unpack="false"/>

<plugin
id="com.avaloq.tools.ddk.xtextspy.source"
download-size="0"
install-size="0"
version="0.0.0"
unpack="false"/>

</feature>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Bundle-ActivationPolicy: lazy
Export-Package: com.avaloq.tools.ddk.xtext.format.ui;x-internal=true
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui.workbench;resolution:=optional,
org.eclipse.xtext.junit4,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.junit,
org.eclipse.xtext.xbase.testing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Require-Bundle: com.avaloq.tools.ddk.test.core,
org.eclipse.xtend,
org.eclipse.xtend.typesystem.emf,
org.eclipse.xtext,
org.eclipse.xtext.junit4,
org.junit,
org.mockito,
com.avaloq.tools.ddk.xtext.ui,
Expand Down
1 change: 0 additions & 1 deletion com.avaloq.tools.ddk.xtext.test.core/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ Require-Bundle: com.avaloq.tools.ddk.xtext,
org.eclipse.pde.core,
org.eclipse.ui.ide,
org.eclipse.xtend.lib,
org.eclipse.xtext.junit4;visibility:=reexport,
org.eclipse.xtext.testing;visibility:=reexport,
org.eclipse.xtext.ui.testing;visibility:=reexport,
org.eclipse.xtext.ui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;

import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.xtext.junit4.validation.AssertableDiagnostics;
import org.eclipse.xtext.junit4.validation.AssertableDiagnostics.DiagnosticPredicate;
import org.eclipse.xtext.junit4.validation.ValidatorTester;
import org.eclipse.xtext.validation.AbstractValidationDiagnostic;
import org.eclipse.xtext.testing.validation.AssertableDiagnostics.Pred;
import org.eclipse.xtext.testing.validation.ValidatorTester;

import com.avaloq.tools.ddk.xtext.test.AbstractXtextTestUtil;
import com.avaloq.tools.ddk.xtext.validation.AbstractDeclarativeValidValidator;
Expand All @@ -29,48 +26,13 @@
/**
* Base class for valid validation tests.
*/
@SuppressWarnings({"deprecation", "removal"})
@SuppressWarnings("nls")
public abstract class AbstractValidValidationTest extends AbstractValidationTest {

// --------------------------------------------------------------------------
// ValidAssertableDiagnostics
// --------------------------------------------------------------------------

/**
* This class can be removed once https://bugs.eclipse.org/bugs/show_bug.cgi?id=374743 is solved.
*/
protected static class ValidAssertableDiagnostics extends AssertableDiagnostics {

public ValidAssertableDiagnostics(final Diagnostic diag) {
super(diag);
throw new UnsupportedOperationException();
}

/**
* Returns predicate matching any diagnostic with given issue code and message fragment.
*
* @param issueCode
* issue code to match
* @param messageFragment
* message fragment (substring) to match
* @return predicate
*/
public static Pred diagnostic(final String issueCode, final String messageFragment) {
return new Pred(null, null, issueCode, messageFragment);
}

/**
* Returns predicate matching any diagnostic with given issue code.
*
* @param issueCode
* issue code to match
* @return predicate
*/
public static Pred diagnostic(final String issueCode) {
return new Pred(null, null, issueCode, null);
}
}

/** The tester. */
private ValidatorTester<?> tester;

Expand Down Expand Up @@ -106,7 +68,7 @@ protected ValidatorTester<?> getTester() {
*/
protected void validate(final EObject element, final String... issueCodes) {
for (String issueCode : issueCodes) {
getTester().validate(element).assertAny(ValidAssertableDiagnostics.diagnostic(issueCode));
getTester().validate(element).assertAny(d -> new Pred(null, null, issueCode, null).apply(d));
}
}

Expand All @@ -122,21 +84,9 @@ protected void validate(final EObject element, final String... issueCodes) {
*/
protected void validateNot(final EObject element, final String... issueCodes) {
for (String issueCode : issueCodes) {
assertNot(getTester().validate(element), ValidAssertableDiagnostics.diagnostic(issueCode));
}
}

/**
* Checks that there is no occurrence of a diagnostic predicate in a diagnostic list.
*
* @param validate
* the diagnostic list in which to look for a diagnostic predicate
* @param predicate
* the predicate diagnostic to look for
*/
private void assertNot(final AssertableDiagnostics validate, final DiagnosticPredicate predicate) {
if (Iterables.any(Iterables.filter(validate.getAllDiagnostics(), AbstractValidationDiagnostic.class), predicate)) {
fail("Predicate " + predicate.toString() + " found.");
if (!Iterables.isEmpty(Iterables.filter(getTester().validate(element).getAllDiagnostics(), d -> new Pred(null, null, issueCode, null).apply(d)))) {
fail("predicate found");
}
}
}

Expand Down
3 changes: 0 additions & 3 deletions com.avaloq.tools.ddk.xtext.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Require-Bundle: com.avaloq.tools.ddk.xtext,
org.eclipse.emf.mwe2.launch;resolution:=optional,
org.eclipse.xtext,
org.eclipse.xtext.xtext.generator,
org.eclipse.xtext.junit4,
org.eclipse.xtext.util,
org.eclipse.xtext.ui,
com.avaloq.tools.ddk.xtext.ui,
Expand All @@ -27,7 +26,6 @@ Require-Bundle: com.avaloq.tools.ddk.xtext,
com.avaloq.tools.ddk.test.core,
org.eclipse.pde.core,
org.eclipse.xtext.xbase.lib,
org.eclipse.xtext.junit4,
org.eclipse.emf.ecore,
org.slf4j.ext
Import-Package: org.apache.log4j,
Expand All @@ -43,7 +41,6 @@ Import-Package: org.apache.log4j,
com.avaloq.tools.ddk.xtext.test.export,
com.avaloq.tools.ddk.xtext.test.format,
com.avaloq.tools.ddk.xtext.ui.test,
com.avaloq.tools.ddk.xtextspy.test,
com.avaloq.tools.ddk.sample.helloworld.test
Export-Package: com.avaloq.tools.ddk.xtext,
com.avaloq.tools.ddk.xtext.formatter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import com.avaloq.tools.ddk.xtext.test.export.ExportTestSuite;
import com.avaloq.tools.ddk.xtext.test.format.FormatTestSuite;
import com.avaloq.tools.ddk.xtext.ui.test.XtextUiTestSuite;
import com.avaloq.tools.ddk.xtextspy.test.XtextSpyTestSuite;


/**
Expand All @@ -52,7 +51,6 @@
CheckUiTestSuite.class,
CheckCfgUiTestSuite.class,
CheckCfgTestSuite.class,
XtextSpyTestSuite.class,
TypeSystemTestSuite.class
})
// @Format-On
Expand Down
Loading

0 comments on commit 887710f

Please sign in to comment.