From 715569f7a60726037e7d03cff9e860bec69276a4 Mon Sep 17 00:00:00 2001 From: AlexisDrogoul Date: Sat, 7 May 2022 19:51:20 +0700 Subject: [PATCH] Fixes #3385 (keeping a cache of the built-in doc) --- .../gaml/descriptions/SpeciesDescription.java | 5 +- .../descriptions/VariableDescription.java | 84 ++++++++++++------- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/msi.gama.core/src/msi/gaml/descriptions/SpeciesDescription.java b/msi.gama.core/src/msi/gaml/descriptions/SpeciesDescription.java index ae1d66a0ba..1d5bc09302 100644 --- a/msi.gama.core/src/msi/gaml/descriptions/SpeciesDescription.java +++ b/msi.gama.core/src/msi/gaml/descriptions/SpeciesDescription.java @@ -321,10 +321,11 @@ public void copyJavaAdditions() { } if (toAdd) { // Fixes a problem where built-in attributes were not linked with their declaring class - Class c = VariableDescription.CLASS_DEFINITIONS.remove(v); + // Class c = VariableDescription.CLASS_DEFINITIONS.remove(v); final VariableDescription var = (VariableDescription) v.copy(this); addOwnAttribute(var); - VariableDescription.CLASS_DEFINITIONS.put(var, c); + var.builtInDoc = ((VariableDescription) v).getBuiltInDoc(); + // VariableDescription.CLASS_DEFINITIONS.put(var, c); } } else { diff --git a/msi.gama.core/src/msi/gaml/descriptions/VariableDescription.java b/msi.gama.core/src/msi/gaml/descriptions/VariableDescription.java index 3bd8827663..c1a058baa2 100644 --- a/msi.gama.core/src/msi/gaml/descriptions/VariableDescription.java +++ b/msi.gama.core/src/msi/gaml/descriptions/VariableDescription.java @@ -1,12 +1,12 @@ /******************************************************************************************************* * - * VariableDescription.java, in msi.gama.core, is part of the source code of the - * GAMA modeling and simulation platform (v.1.8.2). + * VariableDescription.java, in msi.gama.core, is part of the source code of the GAMA modeling and simulation platform + * (v.1.8.2). * * (c) 2007-2022 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU) * * Visit https://github.com/gama-platform/gama for license information and contacts. - * + * ********************************************************************************************************/ package msi.gaml.descriptions; @@ -47,35 +47,37 @@ public class VariableDescription extends SymbolDescription { /** The dependencies. */ private static Map> dependencies = GamaMapFactory.createUnordered(); - + /** The Constant INIT_DEPENDENCIES_FACETS. */ public final static Set INIT_DEPENDENCIES_FACETS = ImmutableSet. builder().add(INIT, MIN, MAX, STEP, SIZE, AMONG).build(); - + /** The Constant UPDATE_DEPENDENCIES_FACETS. */ public final static Set UPDATE_DEPENDENCIES_FACETS = ImmutableSet. builder().add(UPDATE, VALUE, MIN, MAX).build(); - + /** The Constant FUNCTION_DEPENDENCIES_FACETS. */ public final static Set FUNCTION_DEPENDENCIES_FACETS = ImmutableSet. builder().add(FUNCTION).build(); - + /** The Constant CLASS_DEFINITIONS. */ public static final Map> CLASS_DEFINITIONS = new HashMap<>(); - + /** The Constant PREF_DEFINITIONS. */ public static final Map PREF_DEFINITIONS = new HashMap<>(); - + /** The plugin. */ private String plugin; + String builtInDoc; + /** The is not modifiable. */ private final boolean _isGlobal, _isNotModifiable; - + /** The is synthetic species container. */ // for variables automatically added to species for containing micro-agents private boolean _isSyntheticSpeciesContainer; - + /** The set. */ private IGamaHelper get, init, set; // private GamaHelper[] listeners; @@ -83,10 +85,14 @@ public class VariableDescription extends SymbolDescription { /** * Instantiates a new variable description. * - * @param keyword the keyword - * @param superDesc the super desc - * @param source the source - * @param facets the facets + * @param keyword + * the keyword + * @param superDesc + * the super desc + * @param source + * the source + * @param facets + * the facets */ public VariableDescription(final String keyword, final IDescription superDesc, final EObject source, final Facets facets) { @@ -150,7 +156,8 @@ public void dispose() { /** * Copy from. * - * @param v2 the v 2 + * @param v2 + * the v 2 */ public void copyFrom(final VariableDescription v2) { // Special cases for functions @@ -253,9 +260,12 @@ public IType getTypeNamed(final String s) { /** * Gets the dependencies. * - * @param facetsToVisit the facets to visit - * @param includingThis the including this - * @param includingSpecies the including species + * @param facetsToVisit + * the facets to visit + * @param includingThis + * the including this + * @param includingSpecies + * the including species * @return the dependencies */ public Collection getDependencies(final Set facetsToVisit, final boolean includingThis, @@ -312,7 +322,8 @@ public Collection getDependencies(final Set facetsT /** * Gets the var expr. * - * @param asField the as field + * @param asField + * the as field * @return the var expr */ // If asField is true, should not try to build a GlobalVarExpr @@ -374,19 +385,23 @@ public String getShortDescription() { * @return the built in doc */ public String getBuiltInDoc() { + if (builtInDoc != null) return builtInDoc; + builtInDoc = ""; final VariableDescription builtIn = getBuiltInAncestor(); - if (builtIn == null) return null; + if (builtIn == null) { builtInDoc = null; } Class clazz = CLASS_DEFINITIONS.get(builtIn); if (clazz == null) return PREF_DEFINITIONS.get(getName()); final vars vars = clazz.getAnnotationsByType(vars.class)[0]; for (final msi.gama.precompiler.GamlAnnotations.variable v : vars.value()) { if (v.name().equals(name)) { final doc[] docs = v.doc(); - if (docs.length > 0) // documentation of fields is not used - return docs[0].value(); + if (docs.length > 0) { // documentation of fields is not used + builtInDoc = docs[0].value(); + } + break; } } - return ""; + return builtInDoc; } @@ -408,9 +423,12 @@ private VariableDescription getBuiltInAncestor() { /** * Adds the helpers. * - * @param get the get - * @param init the init - * @param set the set + * @param get + * the get + * @param init + * the init + * @param set + * the set */ public void addHelpers(final IGamaHelper get, final IGamaHelper init, final IGamaHelper set) { this.get = get; @@ -421,10 +439,14 @@ public void addHelpers(final IGamaHelper get, final IGamaHelper init, fina /** * Adds the helpers. * - * @param skill the skill - * @param get the get - * @param init the init - * @param set the set + * @param skill + * the skill + * @param get + * the get + * @param init + * the init + * @param set + * the set */ public void addHelpers(final Class skill, final IGamaHelper get, final IGamaHelper init, final IGamaHelper set) {