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

Emits a warning when a parameter refers to an experiment variable in … #304

Merged
merged 1 commit into from
Sep 5, 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,6 @@
/*******************************************************************************************************
*
* ExperimentDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* ExperimentDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand Down Expand Up @@ -65,8 +64,8 @@ public class ExperimentDescription extends SpeciesDescription {
public ExperimentDescription(final String keyword, final SpeciesDescription enclosing,
final Iterable<IDescription> cp, final EObject source, final Facets facets) {
super(keyword, null, enclosing, null, cp, source, facets);
// String type = getLitteral(IKeyword.TYPE);
// setIf(Flag.isBatch, IKeyword.BATCH.equals(type));
String type = getLitteral(IKeyword.TYPE);
setIf(Flag.isBatch, IKeyword.BATCH.equals(type));
setIf(Flag.isMemorize, facets.containsKey(RECORD));
}

Expand Down Expand Up @@ -280,6 +279,8 @@ public boolean visitChildren(final DescriptionVisitor<IDescription> visitor) {
*/
public Boolean isMemorize() { return isSet(Flag.isMemorize); }

public Boolean isBatch() { return isSet(Flag.isBatch); }

@Override
public Class<? extends IExperimentAgent> getJavaBase() {
String type = getLitteral(IKeyword.TYPE);
Expand Down
4 changes: 2 additions & 2 deletions gama.core/src/gama/gaml/descriptions/IDescription.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*******************************************************************************************************
*
* IDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform
* .
* IDescription.java, in gama.core, is part of the source code of the GAMA modeling and simulation platform .
*
* (c) 2007-2024 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
Expand Down Expand Up @@ -110,6 +109,7 @@ enum Flag {

/** The is memorize. */
isMemorize,
isBatch,

}

Expand Down
20 changes: 13 additions & 7 deletions gama.core/src/gama/gaml/variables/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
import com.google.common.base.Objects;
import com.google.common.collect.Iterables;

import gama.annotations.precompiler.IConcept;
import gama.annotations.precompiler.ISymbolKind;
import gama.annotations.precompiler.GamlAnnotations.doc;
import gama.annotations.precompiler.GamlAnnotations.facet;
import gama.annotations.precompiler.GamlAnnotations.facets;
import gama.annotations.precompiler.GamlAnnotations.inside;
import gama.annotations.precompiler.GamlAnnotations.symbol;
import gama.annotations.precompiler.IConcept;
import gama.annotations.precompiler.ISymbolKind;
import gama.core.common.interfaces.IKeyword;
import gama.core.common.interfaces.ISkill;
import gama.core.common.interfaces.IVarAndActionSupport;
Expand Down Expand Up @@ -221,8 +221,7 @@ public void validate(final IDescription vd) {
// The name is ok. Now verifying the logic of facets
// Verifying that 'function' is not used in conjunction with other
// "value" facets
if (cd.hasFacet(FUNCTION)
&& (cd.hasFacet(INIT) || cd.hasFacet(UPDATE) || cd.hasFacet(ON_CHANGE))) {
if (cd.hasFacet(FUNCTION) && (cd.hasFacet(INIT) || cd.hasFacet(UPDATE) || cd.hasFacet(ON_CHANGE))) {
cd.error("A function cannot have an 'init', 'on_change' or 'update' facet", IGamlIssue.REMOVE_VALUE,
FUNCTION);
return;
Expand Down Expand Up @@ -340,13 +339,21 @@ public void assertCanBeParameter(final VariableDescription cd) {
// AD 07/21 : Adds the possibility for experiment variables to become parameters
// We keep on looking after looking in the model so as to make sure that built-in parameters (like
// seed, for instance) can be correctly retrieved
targetedVar = ((ExperimentDescription) cd.getEnclosingDescription()).getAttribute(varName);
ExperimentDescription ed = (ExperimentDescription) cd.getEnclosingDescription();
targetedVar = ed.getAttribute(varName);
Comment on lines +342 to +343

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Getting worse: Complex Method
Variable.VarValidator.assertCanBeParameter increases in cyclomatic complexity from 18 to 19, threshold = 9

Suppress

if (targetedVar == null) {
final String p = "Parameter '" + cd.getParameterName() + "' ";
cd.error(p + "cannot refer to the non-global variable " + varName, IGamlIssue.UNKNOWN_VAR,
IKeyword.VAR);
return;
}
if (ed.isBatch()) {
final String p = "Parameter '" + cd.getParameterName() + "' ";
cd.warning(p
+ "refers to an experiment variable, which cannot be explored during batch experiments. Move "
+ varName + " to the global section if it makes sense.", IGamlIssue.WRONG_CONTEXT,
IKeyword.VAR);
}
}
if (cd.getGamlType().equals(Types.NO_TYPE)) {
cd.error("Impossible to determine the type of the parameter " + varName, IGamlIssue.UNMATCHED_TYPES,
Expand Down Expand Up @@ -512,7 +519,7 @@ public void assertCanBeParameter(final VariableDescription cd) {
public Variable(final IDescription sd) {
super(sd);
final VariableDescription desc = (VariableDescription) sd;
setName(sd.getName());
setName(sd.getName());
parameter = desc.getParameterName();
category = getLiteral(IKeyword.CATEGORY, null);
updateExpression = getFacet(IKeyword.UPDATE);
Expand All @@ -524,7 +531,6 @@ public Variable(final IDescription sd) {
type = desc.getGamlType();
}


/**
* Builds the helpers.
*
Expand Down