Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #2087 #2147

Merged
merged 2 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.lflang.validation;

import java.util.Map;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.xtext.naming.QualifiedName;
import org.eclipse.xtext.resource.IEObjectDescription;
import org.eclipse.xtext.validation.NamesAreUniqueValidationHelper;
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
import org.lflang.lf.AttrParm;
import org.lflang.lf.Attribute;
import org.lflang.lf.LfPackage;

public class LFNamesAreUniqueValidationHelper extends NamesAreUniqueValidationHelper {
Expand All @@ -22,4 +28,32 @@ public EClass getAssociatedClusterType(EClass eClass) {
}
return super.getAssociatedClusterType(eClass);
}

/** {@inheritDoc} */
@Override
@SuppressWarnings("deprecation")
protected void checkDescriptionForDuplicatedName(
IEObjectDescription description,
Map<EClass, Map<QualifiedName, IEObjectDescription>> clusterTypeToName,
ValidationMessageAcceptor acceptor) {
// Special handling for value id in AttrParm
if (description.getEClass() == LfPackage.eINSTANCE.getAttrParm()) {
var param = (AttrParm) description.getEObjectOrProxy();
var clusterType = getAssociatedClusterType(param.eClass());
if (param.eContainer() instanceof Attribute attribute) {
// Only check for duplicates in the same attribute
for (int i = 0; i < attribute.getAttrParms().indexOf(param); i++) {
var prev = attribute.getAttrParms().get(i);
if (param.getName() == null
? param.getName() == prev.getName()
: param.getName().equals(prev.getName())) {
createDuplicateNameError(description, clusterType, acceptor);
return;
}
}
}
} else {
super.checkDescriptionForDuplicatedName(description, clusterTypeToName, acceptor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,29 @@ private Model parseWithError(String s) throws Exception {
return model;
}

/** Assert no issues when multiple labels are used. */
@Test
public void multipleLabels() throws Exception {
String testCase =
"""
target C
reactor Source {
output out: int
timer t(1 nsec, 10 msec)
state s: int = 0
@label(value="Foo")
reaction(startup) {= lf_print("Starting Source"); =}
@label(value="Bar")
reaction(t) -> out {=
lf_set(out, self->s++);
lf_print("Inside source reaction_0");
=}
}""";
validator.assertNoIssues(parseWithoutError(testCase));
}

/** Ensure that duplicate identifiers for actions reported. */
@Test
public void tracingOptionsCpp() throws Exception {
Expand Down
Loading