Skip to content

Commit

Permalink
Issue #102 - Moved indexingFunctions array to RootNamespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
seidewitz committed Sep 14, 2022
1 parent c3b5d77 commit 6a45ec1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down Expand Up @@ -312,14 +313,38 @@ 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");
}

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");
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6a45ec1

Please sign in to comment.