From 6a45ec18ea1e2e880889846d52b584384190de8e Mon Sep 17 00:00:00 2001 From: Ed Seidewitz Date: Wed, 14 Sep 2022 14:26:37 -0400 Subject: [PATCH] Issue #102 - Moved indexingFunctions array to RootNamespace. --- .../impl/InvocationExpressionImpl.java | 21 +-------- .../alf/syntax/units/RootNamespace.java | 47 ++++++++++++++----- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/org.modeldriven.alf/src/org/modeldriven/alf/syntax/expressions/impl/InvocationExpressionImpl.java b/org.modeldriven.alf/src/org/modeldriven/alf/syntax/expressions/impl/InvocationExpressionImpl.java index 9d42ebd3f..cdea7d596 100644 --- a/org.modeldriven.alf/src/org/modeldriven/alf/syntax/expressions/impl/InvocationExpressionImpl.java +++ b/org.modeldriven.alf/src/org/modeldriven/alf/syntax/expressions/impl/InvocationExpressionImpl.java @@ -810,25 +810,6 @@ public boolean isAddInvocation() { return false; } - private static final ElementReference[] indexingFunctions = { - RootNamespace.getRootScope().getSequenceFunction("At"), - RootNamespace.getRootScope().getSequenceFunction("IncludeAt"), - RootNamespace.getRootScope().getSequenceFunction("InsertAt"), - RootNamespace.getRootScope().getSequenceFunction("IncludeAllAt"), - RootNamespace.getRootScope().getSequenceFunction("ExcludeAt"), - RootNamespace.getRootScope().getSequenceFunction("ReplacingAt"), - RootNamespace.getRootScope().getCollectionFunction("at"), - RootNamespace.getRootScope().getCollectionFunction("includeAt"), - RootNamespace.getRootScope().getCollectionFunction("insertAt"), - RootNamespace.getRootScope().getCollectionFunction("includeAllAt"), - RootNamespace.getRootScope().getCollectionFunction("excludeAt"), - RootNamespace.getRootScope().getCollectionFunction("replacingAt"), - RootNamespace.getRootScope().getCollectionFunction("addAt"), - RootNamespace.getRootScope().getCollectionFunction("addAllAt"), - RootNamespace.getRootScope().getCollectionFunction("removeAt"), - RootNamespace.getRootScope().getCollectionFunction("replaceAt"), - }; - /** * Determine whether this is an invocation of a library function the * needs adjustment if indexing is from 0. @@ -837,7 +818,7 @@ public boolean isIndexingInvocation() { InvocationExpression self = this.getSelf(); if (self.getIsBehavior()) { ElementReference referent = self.getReferent(); - for (ElementReference function: indexingFunctions) { + for (ElementReference function: RootNamespace.getRootScope().getIndexingFunctions()) { if (referent.getImpl().equals(function)) { return true; } diff --git a/org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/RootNamespace.java b/org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/RootNamespace.java index c6b8ee3a4..03057d9f3 100644 --- a/org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/RootNamespace.java +++ b/org.modeldriven.alf/src/org/modeldriven/alf/syntax/units/RootNamespace.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright 2011-2017 Model Driven Solutions, Inc. + * Copyright 2011-2022 Model Driven Solutions, Inc. * All rights reserved worldwide. This program and the accompanying materials * are made available for use under the terms of the GNU General Public License * (GPL) version 3 that accompanies this distribution and is available at @@ -13,7 +13,6 @@ import org.modeldriven.alf.syntax.common.ElementReference; import org.modeldriven.alf.syntax.expressions.QualifiedName; -import org.modeldriven.alf.syntax.units.NamespaceDefinition; import org.modeldriven.alf.syntax.units.impl.ModelNamespaceImpl; public class RootNamespace extends ModelNamespace { @@ -117,6 +116,8 @@ public static NamespaceDefinition getModelScope(UnitDefinition unit) { private ElementReference collectionFunctionsPackage = null; private ElementReference collectionClassesPackage = null; + private ElementReference[] indexingFunctions = null; + private QualifiedName listFunctions = null; private ElementReference listFunctionGet = null; @@ -137,7 +138,7 @@ protected QualifiedName getAlfStandardLibraryName() { public QualifiedName getAlfStandardLibrary() { if (alfStandardLibrary == null) { alfStandardLibrary = getAlfStandardLibraryName(); - alfStandardLibrary.getImpl().setCurrentScope(getRootScope()); + alfStandardLibrary.getImpl().setCurrentScope(this); } return alfStandardLibrary; } @@ -312,6 +313,30 @@ public ElementReference getCollectionClassesPackage() { return collectionClassesPackage; } + public ElementReference[] getIndexingFunctions() { + if (indexingFunctions == null) { + indexingFunctions = new ElementReference[] { + getSequenceFunction("At"), + getSequenceFunction("IncludeAt"), + getSequenceFunction("InsertAt"), + getSequenceFunction("IncludeAllAt"), + getSequenceFunction("ExcludeAt"), + getSequenceFunction("ReplacingAt"), + getCollectionFunction("at"), + getCollectionFunction("includeAt"), + getCollectionFunction("insertAt"), + getCollectionFunction("includeAllAt"), + getCollectionFunction("excludeAt"), + getCollectionFunction("replacingAt"), + getCollectionFunction("addAt"), + getCollectionFunction("addAllAt"), + getCollectionFunction("removeAt"), + getCollectionFunction("replaceAt") + }; + } + return indexingFunctions; + } + protected QualifiedName getFoundationalModelLibraryName() { return new QualifiedName().getImpl().addName("FoundationalModelLibrary"); } @@ -319,7 +344,7 @@ protected QualifiedName getFoundationalModelLibraryName() { public QualifiedName getListFunctions() { if (listFunctions == null) { QualifiedName foundationalModelLibraryName = getFoundationalModelLibraryName(); - foundationalModelLibraryName.getImpl().setCurrentScope(getRootScope()); + foundationalModelLibraryName.getImpl().setCurrentScope(this); listFunctions = foundationalModelLibraryName.getImpl(). addName("PrimitiveBehaviors").getImpl().addName("ListFunctions"); } @@ -346,7 +371,7 @@ public QualifiedName getBooleanFunctions() { if (booleanFunctions == null) { booleanFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("BooleanFunctions"); - booleanFunctions.getImpl().setCurrentScope(getRootScope()); + booleanFunctions.getImpl().setCurrentScope(this); } return booleanFunctions; } @@ -373,7 +398,7 @@ public QualifiedName getIntegerFunctions() { if (integerFunctions == null) { integerFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("IntegerFunctions"); - integerFunctions.getImpl().setCurrentScope(getRootScope()); + integerFunctions.getImpl().setCurrentScope(this); } return integerFunctions; } @@ -416,7 +441,7 @@ public QualifiedName getStringFunctions() { if (stringFunctions == null) { stringFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("StringFunctions"); - stringFunctions.getImpl().setCurrentScope(getRootScope()); + stringFunctions.getImpl().setCurrentScope(this); } return stringFunctions; } @@ -435,7 +460,7 @@ public QualifiedName getUnlimitedNaturalFunctions() { if (unlimitedNaturalFunctions == null) { unlimitedNaturalFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("UnlimitedNaturalFunctions"); - unlimitedNaturalFunctions.getImpl().setCurrentScope(getRootScope()); + unlimitedNaturalFunctions.getImpl().setCurrentScope(this); } return unlimitedNaturalFunctions; } @@ -444,7 +469,7 @@ public QualifiedName getRealFunctions() { if (realFunctions == null) { realFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("RealFunctions"); - realFunctions.getImpl().setCurrentScope(getRootScope()); + realFunctions.getImpl().setCurrentScope(this); } return realFunctions; } @@ -494,7 +519,7 @@ public QualifiedName getBitStringFunctions() { if (bitStringFunctions == null) { bitStringFunctions = getPrimitiveBehaviors().getImpl().copy(). addName("BitStringFunctions"); - bitStringFunctions.getImpl().setCurrentScope(getRootScope()); + bitStringFunctions.getImpl().setCurrentScope(this); } return bitStringFunctions; } @@ -528,7 +553,7 @@ protected QualifiedName getStandardProfileName() { public ElementReference getStandardProfile() { if (standardProfile == null) { QualifiedName standardProfileName = getStandardProfileName(); - standardProfileName.getImpl().setCurrentScope(getRootScope()); + standardProfileName.getImpl().setCurrentScope(this); ElementReference namespace = standardProfileName.getImpl().getNamespaceReferent(); if (namespace != null && namespace.getImpl().isProfile()) { standardProfile = namespace;