diff options
author | Ed Willink | 2017-07-14 18:27:29 +0000 |
---|---|---|
committer | Ed Willink | 2017-07-14 18:27:29 +0000 |
commit | 5c2ae968d998a9d6779787e7f04f0033021c6fdb (patch) | |
tree | fddf63ee3072fccc13c4789bd462152f90f0fa3d | |
parent | 9dfad32495a17935f7a0fc685b0cb1bbe852b03f (diff) | |
download | org.eclipse.ocl-ewillink/509670.tar.gz org.eclipse.ocl-ewillink/509670.tar.xz org.eclipse.ocl-ewillink/509670.zip |
Tidy boxingewillink/509670
19 files changed, 248 insertions, 190 deletions
diff --git a/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupFilterGenerator.java b/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupFilterGenerator.java index 2fc572fb4e..0f6db6cbe4 100644 --- a/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupFilterGenerator.java +++ b/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupFilterGenerator.java @@ -48,6 +48,7 @@ import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.PropertyCallExp; import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.Variable; +import org.eclipse.ocl.pivot.VariableDeclaration; import org.eclipse.ocl.pivot.VariableExp; import org.eclipse.ocl.pivot.evaluation.Executor; import org.eclipse.ocl.pivot.ids.IdResolver; @@ -309,7 +310,7 @@ public class LookupFilterGenerator extends AutoCodeGenerator - protected @NonNull VariableExp createThisVariableExp(@NonNull Variable thisVariable) { + protected @NonNull VariableExp createThisVariableExp(@NonNull VariableDeclaration thisVariable) { return PivotUtil.createVariableExp(thisVariable); } diff --git a/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupVisitorsCodeGenerator.java b/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupVisitorsCodeGenerator.java index b1ac8074a6..6d02b694e9 100644 --- a/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupVisitorsCodeGenerator.java +++ b/examples/org.eclipse.ocl.examples.autogen/src/org/eclipse/ocl/examples/autogen/lookup/LookupVisitorsCodeGenerator.java @@ -47,6 +47,7 @@ import org.eclipse.ocl.pivot.PivotFactory; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.Variable; +import org.eclipse.ocl.pivot.VariableDeclaration; import org.eclipse.ocl.pivot.VariableExp; import org.eclipse.ocl.pivot.evaluation.Executor; import org.eclipse.ocl.pivot.ids.IdManager; @@ -279,7 +280,7 @@ public abstract class LookupVisitorsCodeGenerator extends AutoVisitorsCodeGenera return asOperation; } - protected @NonNull VariableExp createThisVariableExp(@NonNull Variable thisVariable) { + protected @NonNull VariableExp createThisVariableExp(@NonNull VariableDeclaration thisVariable) { return PivotUtil.createVariableExp(thisVariable); } @@ -323,7 +324,6 @@ public abstract class LookupVisitorsCodeGenerator extends AutoVisitorsCodeGenera return getSuperVisitorPackageName(); } - @SuppressWarnings("null") protected @NonNull String extractTypeNameFromEnvOp(@NonNull String envOpName) { boolean isGeneralLookup = envOperationName.equals(envOpName); return isGeneralLookup ? "" : envOperationName.substring(envOpName.length() + 1 /*extra underscore */); diff --git a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/lookup/impl/LookupEnvironmentImpl.java b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/lookup/impl/LookupEnvironmentImpl.java index 3379506aee..bf6c4c24d1 100644 --- a/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/lookup/impl/LookupEnvironmentImpl.java +++ b/plugins/org.eclipse.ocl.pivot/emf-gen/org/eclipse/ocl/pivot/internal/lookup/impl/LookupEnvironmentImpl.java @@ -30,7 +30,6 @@ import org.eclipse.ocl.pivot.internal.lookup.LookupTables; import org.eclipse.ocl.pivot.internal.utilities.PivotUtilInternal; import org.eclipse.ocl.pivot.library.collection.CollectionIncludingAllOperation; import org.eclipse.ocl.pivot.library.collection.CollectionIncludingOperation; -import org.eclipse.ocl.pivot.values.CollectionValue; /** * <!-- begin-user-doc --> @@ -184,7 +183,7 @@ public class LookupEnvironmentImpl extends MinimalEObjectImpl.Container implemen @SuppressWarnings("null") final /*@Thrown*/ java.util.@NonNull List<NamedElement> namedElements = this.getNamedElements(); final /*@Thrown*/ org.eclipse.ocl.pivot.values.@NonNull CollectionValue BOXED_namedElements = idResolver.createOrderedSetOfAll(LookupTables.ORD_CLSSid_NamedElement, namedElements); - final /*@Thrown*/ org.eclipse.ocl.pivot.values.@NonNull CollectionValue including = (CollectionValue)CollectionIncludingOperation.INSTANCE.evaluate(BOXED_namedElements, element); + final /*@Thrown*/ org.eclipse.ocl.pivot.values.@NonNull CollectionValue including = CollectionIncludingOperation.INSTANCE.evaluate(BOXED_namedElements, element); final List<NamedElement> UNBOXED_including = including.asEcoreObjects(idResolver, NamedElement.class); assert UNBOXED_including != null; CTORid_namedElements.initValue(symbol_0, UNBOXED_including); diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/ids/IdResolver.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/ids/IdResolver.java index 20ba4c4e03..e1e38a057d 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/ids/IdResolver.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/ids/IdResolver.java @@ -57,29 +57,45 @@ public interface IdResolver extends IdVisitor<Element> @Nullable Object boxedValueOf(@NonNull Object unboxedValue, @NonNull ETypedElement eFeature, @Nullable TypeId typeId); - @NonNull CollectionValue createBagOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfAll */ + @NonNull CollectionValue createBagOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); - @NonNull CollectionValue createBagOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfEach */ + @NonNull CollectionValue createBagOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues); - @NonNull CollectionValue createCollectionOfAll(boolean isOrdered, boolean isUnique, @NonNull TypeId elementTypeId, @NonNull Iterable<? extends Object> unboxedValues); + @NonNull CollectionValue createCollectionOfAll(boolean isOrdered, boolean uniqueElements, @NonNull TypeId elementTypeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); - @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId collectedId, @NonNull Iterable<? extends Object> unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfAll with uniqueElements argument */ + @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); + + @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId typeId, boolean uniqueElements, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); + + // @Deprecated /* @deprecated Use createCollectionOfAll with uniqueElements argument */ + // @NonNull CollectionValue createCollectionOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues); + + @NonNull CollectionValue createCollectionOfEach(@NonNull CollectionTypeId typeId, boolean uniqueElements, @Nullable Object @NonNull ... unboxedValues); @Nullable Object createInstance(@NonNull TypeId typeId, @NonNull String stringValue); @NonNull MapValue createMapOfAll(@NonNull TypeId keyTypeId, @NonNull TypeId valueTypeId, @NonNull Map<@Nullable Object, @Nullable Object> mapEntries); - @NonNull CollectionValue createOrderedSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfAll */ + @NonNull CollectionValue createOrderedSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); - @NonNull CollectionValue createOrderedSetOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfEach */ + @NonNull CollectionValue createOrderedSetOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues); - @NonNull CollectionValue createSequenceOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfAll */ + @NonNull CollectionValue createSequenceOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); - @NonNull CollectionValue createSequenceOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfEach */ + @NonNull CollectionValue createSequenceOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues); - @NonNull CollectionValue createSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfAll */ + @NonNull CollectionValue createSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues); - @NonNull CollectionValue createSetOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues); + @Deprecated /* @deprecated Use createCollectionOfEach */ + @NonNull CollectionValue createSetOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues); void dispose(); @@ -100,7 +116,7 @@ public interface IdResolver extends IdVisitor<Element> /** @deprecated no longer used */ @Deprecated - @NonNull EList<Object> ecoreValuesOfEach(@Nullable Class<?> instanceClass, @NonNull Object... values); + @NonNull EList<Object> ecoreValuesOfEach(@Nullable Class<?> instanceClass, @Nullable Object @NonNull ... values); org.eclipse.ocl.pivot.@NonNull Class getClass(@NonNull TypeId typeId, @Nullable Object context); @@ -112,7 +128,7 @@ public interface IdResolver extends IdVisitor<Element> */ @NonNull Type getDynamicTypeOf(@Nullable Object value); - @Nullable Type getDynamicTypeOf(@NonNull Object @NonNull ... values); + @Nullable Type getDynamicTypeOf(@Nullable Object @NonNull ... values); @Nullable Type getDynamicTypeOf(@NonNull Iterable<?> values); @@ -134,7 +150,7 @@ public interface IdResolver extends IdVisitor<Element> org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value); - org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value, Object... values); + org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value, Object @NonNull ... values); org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value, @NonNull Iterable<?> values); @@ -152,7 +168,7 @@ public interface IdResolver extends IdVisitor<Element> @NonNull Enumerator unboxedValueOf(@NonNull EnumerationLiteralId enumerationLiteralId); - @NonNull EList<Object> unboxedValuesOfAll(@NonNull Collection<? extends Object> boxedValues); + @NonNull EList<Object> unboxedValuesOfAll(@NonNull Collection<@Nullable ? extends Object> boxedValues); - @NonNull EList<Object> unboxedValuesOfEach(@Nullable Object... boxedValues); + @NonNull EList<Object> unboxedValuesOfEach(@Nullable Object @NonNull ... boxedValues); }
\ No newline at end of file diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/BasicEvaluationVisitor.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/BasicEvaluationVisitor.java index 7cd44e4109..ea297c40cb 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/BasicEvaluationVisitor.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/BasicEvaluationVisitor.java @@ -817,8 +817,8 @@ public class BasicEvaluationVisitor extends AbstractEvaluationVisitor } else { Object initValue = initExp.accept(undecoratedVisitor); - if (variable.isCacheNeeded() && (initValue instanceof CollectionValue)) { - ((CollectionValue)initValue).eagerIterable(); + if (variable.isCacheNeeded()) { + CachingAnalysis.initCaching(variable, initValue); } return initValue; } diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/CachingAnalysis.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/CachingAnalysis.java index 14c4098ae5..c41afe9fc2 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/CachingAnalysis.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/evaluation/CachingAnalysis.java @@ -19,30 +19,36 @@ import org.eclipse.emf.ecore.EObject; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.pivot.Element; -import org.eclipse.ocl.pivot.ExpressionInOCL; import org.eclipse.ocl.pivot.LoopExp; import org.eclipse.ocl.pivot.VariableDeclaration; import org.eclipse.ocl.pivot.VariableExp; import org.eclipse.ocl.pivot.ids.CollectionTypeId; import org.eclipse.ocl.pivot.utilities.PivotUtil; import org.eclipse.ocl.pivot.utilities.TreeIterable; +import org.eclipse.ocl.pivot.values.CollectionValue; /** * The CachingAnalysis sets VariableDeclaration.cacheNeeded for colletion variables that are accessed more than once. */ public class CachingAnalysis { - public static void analyze(@NonNull ExpressionInOCL expressionInOCL) { - CachingAnalysis cachingAnalysis = new CachingAnalysis(expressionInOCL); + public static void analyze(@NonNull Element rootElement) { + CachingAnalysis cachingAnalysis = new CachingAnalysis(rootElement); cachingAnalysis.analyze(); } - protected final @NonNull ExpressionInOCL expressionInOCL; + public static void initCaching(@NonNull VariableDeclaration variableDeclaration, Object initValue) { + if (variableDeclaration.isCacheNeeded() && (initValue instanceof CollectionValue)) { + ((CollectionValue)initValue).eagerIterable(); + } + } + + protected final @NonNull Element rootElement; private final @NonNull Map<@NonNull VariableDeclaration, @NonNull Set<@NonNull VariableExp>> variable2users = new HashMap<>(); private final @NonNull Map<@NonNull Element, @Nullable Boolean> element2multiple = new HashMap<>(); - protected CachingAnalysis(@NonNull ExpressionInOCL expressionInOCL) { - this.expressionInOCL = expressionInOCL; + protected CachingAnalysis(@NonNull Element rootElement) { + this.rootElement = rootElement; } protected void addUser(@NonNull VariableDeclaration asVariable, @NonNull VariableExp asVariableExp) { @@ -55,7 +61,7 @@ public class CachingAnalysis } protected void analyze() { - for (@NonNull Object object : new TreeIterable(expressionInOCL, true)) { + for (@NonNull Object object : new TreeIterable(rootElement, true)) { analyzeUsage(object); } for (@NonNull VariableDeclaration asVariable : variable2users.keySet()) { diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AbstractLazyIterator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AbstractLazyIterator.java index efd62cc68f..9e422a2735 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AbstractLazyIterator.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AbstractLazyIterator.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.ocl.pivot.internal.iterators; -import java.util.Collection; import java.util.Map; import java.util.NoSuchElementException; @@ -85,7 +84,7 @@ public abstract class AbstractLazyIterator implements LazyIterator s.append("}"); } - public static <E> void appendIterable(@NonNull StringBuilder s, @NonNull Collection<E> elements, + public static <E> void appendIterable(@NonNull StringBuilder s, @NonNull Iterable<E> elements, @Nullable Map<E, @NonNull ? extends Number> element2elementCount, int sizeLimit) { s.append("{"); boolean isFirst = true; diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsBoxedIterator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsBoxedIterator.java new file mode 100644 index 0000000000..d9f73710c5 --- /dev/null +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsBoxedIterator.java @@ -0,0 +1,62 @@ +/******************************************************************************* + * Copyright (c) 2017 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - Initial API and implementation + *******************************************************************************/ +package org.eclipse.ocl.pivot.internal.iterators; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.ocl.pivot.ids.IdResolver; +import org.eclipse.ocl.pivot.internal.values.LazyCollectionValueImpl; +import org.eclipse.ocl.pivot.values.CollectionValue; +import org.eclipse.ocl.pivot.values.LazyIterator; + +/** + * AsBoxedIterator provides a lazy evaluation of the IdResolver::boxedValueOf operation. + * + * @since 1.3 + */ +public class AsBoxedIterator extends AbstractLazyIterator +{ + public static @NonNull CollectionValue asBoxed(@NonNull CollectionValue sourceValue, @NonNull IdResolver idResolver) { + LazyCollectionValueImpl collectionValue = new LazyCollectionValueImpl(sourceValue.getTypeId(), new AsBoxedIterator(sourceValue, idResolver), null); + return collectionValue; + } + + private final @NonNull CollectionValue sourceValue; + private final @NonNull IdResolver idResolver; + private final @NonNull LazyIterator sourceIterator; + + public AsBoxedIterator(@NonNull CollectionValue sourceValue, @NonNull IdResolver idResolver) { + this.sourceValue = sourceValue; + this.idResolver = idResolver; + this.sourceIterator = sourceValue.lazyIterator(); + } + + @Override + public int getNextCount() { + int hasNextCount = sourceIterator.hasNextCount(); + if (hasNextCount > 0) { + Object element = sourceIterator.next(); + Object boxedElement = idResolver.boxedValueOf(element); + return setNext(boxedElement, hasNextCount); + } + return 0; + } + + @Override + public @NonNull LazyIterator reIterator() { + return new AsBoxedIterator(sourceValue, idResolver); + } + + @Override + public void toString(@NonNull StringBuilder s, int sizeLimit) { + s.append("AsBoxed"); + sourceIterator.reIterator().toString(s, sizeLimit); + } +} diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsEcoreIterator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsEcoreIterator.java index ef57c391cf..b6ba427115 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsEcoreIterator.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/AsEcoreIterator.java @@ -42,14 +42,16 @@ public class AsEcoreIterator extends AbstractLazyIterator int hasNextCount = sourceIterator.hasNextCount(); if (hasNextCount > 0) { Object element = sourceIterator.next(); - if (element instanceof Value) - return setNext(((Value)element).asEcoreObject(idResolver, instanceClass), hasNextCount); - else if (element instanceof EnumerationLiteralId) { - return setNext(idResolver.unboxedValueOf(element), hasNextCount); + Object ecoreElement; + if (element instanceof Value) { + ecoreElement = ((Value)element).asEcoreObject(idResolver, instanceClass); + } else if (element instanceof EnumerationLiteralId) { + ecoreElement = idResolver.unboxedValueOf(element); } else { - return setNext(element, hasNextCount); + ecoreElement = element; } + return setNext(ecoreElement, hasNextCount); } return 0; } diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromArrayIterator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromArrayIterator.java index c440a517d9..72a2b2ed47 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromArrayIterator.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromArrayIterator.java @@ -22,7 +22,7 @@ import org.eclipse.ocl.pivot.values.LazyIterator; */ public class FromArrayIterator extends AbstractLazyIterator { - public static @NonNull CollectionValue create(@NonNull CollectionTypeId collectionTypeId, boolean uniqueElements, @Nullable Object @NonNull [] elements) { + public static @NonNull CollectionValue create(@NonNull CollectionTypeId collectionTypeId, boolean uniqueElements, @Nullable Object @NonNull ... elements) { LazyCollectionValueImpl collectionValue = new LazyCollectionValueImpl(collectionTypeId, new FromArrayIterator(elements), null); if (!uniqueElements && !collectionValue.isSequence()) { collectionValue.eagerIterable(); // uniqueness/counts must be eager diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromCollectionIterator.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromIterableIterator.java index bdcedbe919..c4279a2b0f 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromCollectionIterator.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/iterators/FromIterableIterator.java @@ -10,7 +10,6 @@ *******************************************************************************/ package org.eclipse.ocl.pivot.internal.iterators; -import java.util.Collection; import java.util.Iterator; import org.eclipse.jdt.annotation.NonNull; @@ -21,22 +20,22 @@ import org.eclipse.ocl.pivot.values.CollectionValue; import org.eclipse.ocl.pivot.values.LazyIterator; /** - * FromCollectionIterator provides the loader for a CollectionValue from a Collection. + * FromIterableIterator provides the loader for a CollectionValue from a Collection. */ -public class FromCollectionIterator extends AbstractLazyIterator +public class FromIterableIterator extends AbstractLazyIterator { - public static @NonNull CollectionValue create(@NonNull CollectionTypeId collectionTypeId, boolean uniqueElements, @NonNull Collection<@Nullable ? extends Object> elements) { - LazyCollectionValueImpl collectionValue = new LazyCollectionValueImpl(collectionTypeId, new FromCollectionIterator(elements), null); + public static @NonNull CollectionValue create(@NonNull CollectionTypeId collectionTypeId, boolean uniqueElements, @NonNull Iterable<@Nullable ? extends Object> elements) { + LazyCollectionValueImpl collectionValue = new LazyCollectionValueImpl(collectionTypeId, new FromIterableIterator(elements), null); if (!uniqueElements && !collectionValue.isSequence()) { collectionValue.eagerIterable(); // uniqueness/counts must be eager } return collectionValue; } - private @NonNull Collection<@Nullable ? extends Object> elements; + private @NonNull Iterable<@Nullable ? extends Object> elements; private @NonNull Iterator<@Nullable ? extends Object> iterator; - protected FromCollectionIterator(@NonNull Collection<@Nullable ? extends Object> elements) { + protected FromIterableIterator(@NonNull Iterable<@Nullable ? extends Object> elements) { this.elements = elements; this.iterator = elements.iterator(); } @@ -56,7 +55,7 @@ public class FromCollectionIterator extends AbstractLazyIterator @Override public @NonNull LazyIterator reIterator() { - return new FromCollectionIterator(elements); + return new FromIterableIterator(elements); } @Override diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/executor/AbstractIdResolver.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/executor/AbstractIdResolver.java index af356bdeae..53e8481b44 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/executor/AbstractIdResolver.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/library/executor/AbstractIdResolver.java @@ -81,19 +81,19 @@ import org.eclipse.ocl.pivot.ids.TupleTypeId; import org.eclipse.ocl.pivot.ids.TypeId; import org.eclipse.ocl.pivot.ids.UnspecifiedId; import org.eclipse.ocl.pivot.internal.executor.ExecutorTuplePart; -import org.eclipse.ocl.pivot.internal.values.BagImpl; -import org.eclipse.ocl.pivot.internal.values.OrderedSetImpl; +import org.eclipse.ocl.pivot.internal.iterators.AsBoxedIterator; +import org.eclipse.ocl.pivot.internal.iterators.FromArrayIterator; +import org.eclipse.ocl.pivot.internal.iterators.FromIterableIterator; import org.eclipse.ocl.pivot.utilities.ClassUtil; import org.eclipse.ocl.pivot.utilities.PivotConstants; +import org.eclipse.ocl.pivot.utilities.TypeUtil; import org.eclipse.ocl.pivot.utilities.ValueUtil; -import org.eclipse.ocl.pivot.values.Bag; import org.eclipse.ocl.pivot.values.CollectionValue; import org.eclipse.ocl.pivot.values.IntegerValue; import org.eclipse.ocl.pivot.values.InvalidValueException; import org.eclipse.ocl.pivot.values.LazyCollectionValue; import org.eclipse.ocl.pivot.values.MapValue; import org.eclipse.ocl.pivot.values.OCLValue; -import org.eclipse.ocl.pivot.values.OrderedSet; import org.eclipse.ocl.pivot.values.Unlimited; import org.eclipse.ocl.pivot.values.UnlimitedNaturalValue; import org.eclipse.ocl.pivot.values.Value; @@ -362,40 +362,26 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } else if (unboxedValue.getClass().isArray()) { try { - @NonNull Object @NonNull [] unboxedValues = (@NonNull Object @NonNull [])unboxedValue; + @Nullable Object @NonNull [] unboxedValues = (@Nullable Object @NonNull [])unboxedValue; Type dynamicType = getDynamicTypeOf(unboxedValues); if (dynamicType == null) { dynamicType = standardLibrary.getOclInvalidType(); } TypeId elementTypeId = dynamicType.getTypeId(); CollectionTypeId collectedTypeId = TypeId.SEQUENCE.getSpecializedId(elementTypeId); - return createSequenceOfEach(collectedTypeId, (@NonNull Object @NonNull [])unboxedValue); + return createSequenceOfEach(collectedTypeId, (@Nullable Object @NonNull [])unboxedValue); } catch (IllegalArgumentException e) {} } else if (unboxedValue instanceof Iterable<?>) { - Iterable<?> unboxedValues = (Iterable<?>)unboxedValue; + Iterable<@Nullable ?> unboxedValues = (Iterable<@Nullable ?>)unboxedValue; Type dynamicType = getDynamicTypeOf(unboxedValues); if (dynamicType == null) { dynamicType = standardLibrary.getOclInvalidType(); } TypeId elementTypeId = dynamicType.getTypeId(); - if ((unboxedValue instanceof LinkedHashSet) || (unboxedValue instanceof OrderedSet)) { - CollectionTypeId collectedTypeId = TypeId.ORDERED_SET.getSpecializedId(elementTypeId); - return createOrderedSetOfAll(collectedTypeId, unboxedValues); - } - else if (unboxedValue instanceof Bag) { - CollectionTypeId collectedTypeId = TypeId.BAG.getSpecializedId(elementTypeId); - return createBagOfAll(collectedTypeId, unboxedValues); - } - else if (unboxedValue instanceof Set) { - CollectionTypeId collectedTypeId = TypeId.SET.getSpecializedId(elementTypeId); - return createSetOfAll(collectedTypeId, unboxedValues); - } - else { - CollectionTypeId collectedTypeId = TypeId.SEQUENCE.getSpecializedId(elementTypeId); - return createSequenceOfAll(collectedTypeId, unboxedValues); - } + CollectionTypeId collectedTypeId = TypeUtil.getCollectionTypeId((Iterable<?>)unboxedValue); + return createCollectionOfAll(collectedTypeId.getSpecializedId(elementTypeId), unboxedValues); } /* else if (unboxedValue instanceof EEnumLiteral) { return ValuesUtil.createEnumerationLiteralValue((EEnumLiteral)unboxedValue); @@ -445,9 +431,9 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi public @Nullable Object boxedValueOf(@NonNull Object unboxedValue, @NonNull ETypedElement eFeature, @Nullable TypeId typeId) { EClassifier eClassifier = eFeature.getEType(); if (typeId instanceof CollectionTypeId) { - Collection<?> unboxedValues = (Collection<?>) unboxedValue; + Collection<@Nullable ?> unboxedValues = (Collection<@Nullable ?>) unboxedValue; if (eClassifier instanceof EDataType) { - ArrayList<Object> values = new ArrayList<Object>(unboxedValues.size()); + ArrayList<@Nullable Object> values = new ArrayList<>(unboxedValues.size()); for (Object eVal : unboxedValues) { if (eVal != null) { values.add(boxedValueOf(eVal, eClassifier)); @@ -491,21 +477,13 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public @NonNull CollectionValue createBagOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues) { - Bag<@Nullable Object> boxedValues = new BagImpl<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createBagValue(typeId, boxedValues); + public @NonNull CollectionValue createBagOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + return createCollectionOfAll(typeId, false, unboxedValues); } @Override - public @NonNull CollectionValue createBagOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues) { - Bag<@Nullable Object> boxedValues = new BagImpl<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createBagValue(typeId, boxedValues); + public @NonNull CollectionValue createBagOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues) { + return createCollectionOfEach(typeId, false, unboxedValues); } /** @@ -517,54 +495,31 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi * @return the new collection */ @Override - public @NonNull CollectionValue createCollectionOfAll(boolean isOrdered, boolean isUnique, @NonNull TypeId elementTypeId, @NonNull Iterable<? extends Object> unboxedValues) { - if (isOrdered) { - if (isUnique) { - return createOrderedSetOfAll(TypeId.ORDERED_SET.getSpecializedId(elementTypeId), unboxedValues); - } - else { - return createSequenceOfAll(TypeId.SEQUENCE.getSpecializedId(elementTypeId), unboxedValues); - } - } - else { - if (isUnique) { - return createSetOfAll(TypeId.SET.getSpecializedId(elementTypeId), unboxedValues); - } - else { - return createBagOfAll(TypeId.BAG.getSpecializedId(elementTypeId), unboxedValues); - } - } + public @NonNull CollectionValue createCollectionOfAll(boolean isOrdered, boolean isUnique, @NonNull TypeId elementTypeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + CollectionTypeId collectionTypeId = TypeUtil.getCollectionTypeId(isOrdered, isUnique); + return createCollectionOfAll(collectionTypeId.getSpecializedId(elementTypeId), unboxedValues); } @Override - public @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId collectedId, @NonNull Iterable<? extends Object> unboxedValues) { - CollectionTypeId collectionId = collectedId.getGeneralizedId(); - if (collectionId == TypeId.BAG) { - return createBagOfAll(collectedId, unboxedValues); - } - else if (collectionId == TypeId.ORDERED_SET) { - return createOrderedSetOfAll(collectedId, unboxedValues); - } - else if (collectionId == TypeId.SEQUENCE) { - return createSequenceOfAll(collectedId, unboxedValues); - } - else if (collectionId == TypeId.SET) { - return createSetOfAll(collectedId, unboxedValues); - } - else /*if (collectionId == TypeId.COLLECTION)*/ { - if (unboxedValues instanceof LinkedHashSet<?>) { - return createOrderedSetOfAll(collectedId, unboxedValues); - } - else if (unboxedValues instanceof Set<?>) { - return createSetOfAll(collectedId, unboxedValues); - } - else if (unboxedValues instanceof Bag<?>) { - return createBagOfAll(collectedId, unboxedValues); - } - else /*if (unboxedValues instanceof List<?>)*/ { - return createSequenceOfAll(collectedId, unboxedValues); - } - } + public @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + return createCollectionOfAll(typeId, false, unboxedValues); + } + + @Override + public @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId typeId, boolean uniqueElements, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + CollectionValue unboxedValue = FromIterableIterator.create(typeId, uniqueElements, unboxedValues); + return AsBoxedIterator.asBoxed(unboxedValue, this); + } + + // @Override + // public @NonNull CollectionValue createCollectionOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues) { + // return createCollectionOfEach(typeId, false, unboxedValues); + // } + + @Override + public @NonNull CollectionValue createCollectionOfEach(@NonNull CollectionTypeId typeId, boolean uniqueElements, @Nullable Object @NonNull ... unboxedValues) { + CollectionValue unboxedValue = FromArrayIterator.create(typeId, uniqueElements, unboxedValues); + return AsBoxedIterator.asBoxed(unboxedValue, this); } @Override @@ -583,57 +538,33 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public @NonNull CollectionValue createOrderedSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues) { - OrderedSet<@Nullable Object> boxedValues = new OrderedSetImpl<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createOrderedSetValue(typeId, boxedValues); + public @NonNull CollectionValue createOrderedSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + return createCollectionOfAll(typeId, true, unboxedValues); } @Override - public @NonNull CollectionValue createOrderedSetOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues) { - OrderedSet<@Nullable Object> boxedValues = new OrderedSetImpl<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createOrderedSetValue(typeId, boxedValues); + public @NonNull CollectionValue createOrderedSetOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues) { + return createCollectionOfEach(typeId, false, unboxedValues); } @Override - public @NonNull CollectionValue createSequenceOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues) { - List<@Nullable Object> boxedValues = new ArrayList<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createSequenceValue(typeId, boxedValues); + public @NonNull CollectionValue createSequenceOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + return createCollectionOfAll(typeId, false, unboxedValues); } @Override - public @NonNull CollectionValue createSequenceOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues) { - List<@Nullable Object> boxedValues = new ArrayList<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createSequenceValue(typeId, boxedValues); + public @NonNull CollectionValue createSequenceOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues) { + return createCollectionOfEach(typeId, false, unboxedValues); } @Override - public @NonNull CollectionValue createSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<? extends Object> unboxedValues) { - Set<@Nullable Object> boxedValues = new HashSet<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createSetValue(typeId, boxedValues); + public @NonNull CollectionValue createSetOfAll(@NonNull CollectionTypeId typeId, @NonNull Iterable<@Nullable ? extends Object> unboxedValues) { + return createCollectionOfAll(typeId, true, unboxedValues); } @Override - public @NonNull CollectionValue createSetOfEach(@NonNull CollectionTypeId typeId, @NonNull Object... unboxedValues) { - Set<@Nullable Object> boxedValues = new HashSet<>(); - for (Object unboxedValue : unboxedValues) { - boxedValues.add(boxedValueOf(unboxedValue)); - } - return ValueUtil.createSetValue(typeId, boxedValues); + public @NonNull CollectionValue createSetOfEach(@NonNull CollectionTypeId typeId, @Nullable Object @NonNull ... unboxedValues) { + return createCollectionOfEach(typeId, false, unboxedValues); } @Override @@ -733,7 +664,7 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi /** @deprecated no longer used */ @Deprecated @Override - public @NonNull EList<Object> ecoreValuesOfEach(@Nullable Class<?> instanceClass, @NonNull Object... values) { + public @NonNull EList<Object> ecoreValuesOfEach(@Nullable Class<?> instanceClass, @Nullable Object @NonNull ... values) { Object[] ecoreValues = new Object[values.length]; int i= 0; for (Object value : values) { @@ -825,7 +756,7 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public @Nullable Type getDynamicTypeOf(@NonNull Object @NonNull ... values) { + public @Nullable Type getDynamicTypeOf(@Nullable Object @NonNull ... values) { Type elementType = null; for (Object value : values) { org.eclipse.ocl.pivot.Class valueType = getDynamicTypeOf(value); @@ -1030,7 +961,7 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value, Object... values) { + public org.eclipse.ocl.pivot.@NonNull Class getStaticTypeOf(@Nullable Object value, Object @NonNull ... values) { Object bestTypeId = getTypeKeyOf(value); org.eclipse.ocl.pivot.Class bestType = key2type.get(bestTypeId); assert bestType != null; @@ -1549,7 +1480,7 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public @NonNull EList<Object> unboxedValuesOfAll(@NonNull Collection<? extends Object> boxedValues) { + public @NonNull EList<Object> unboxedValuesOfAll(@NonNull Collection<@Nullable ? extends Object> boxedValues) { Object[] unboxedValues = new Object[boxedValues.size()]; int i= 0; for (Object boxedValue : boxedValues) { @@ -1559,7 +1490,7 @@ public abstract class AbstractIdResolver implements IdResolver.IdResolverExtensi } @Override - public @NonNull EList<Object> unboxedValuesOfEach(@Nullable Object... boxedValues) { + public @NonNull EList<Object> unboxedValuesOfEach(@Nullable Object @NonNull ... boxedValues) { Object[] unboxedValues = new Object[boxedValues.length]; int i= 0; for (Object boxedValue : boxedValues) { diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/LazyCollectionValueImpl.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/LazyCollectionValueImpl.java index 00af830d79..94479b1e6c 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/LazyCollectionValueImpl.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/LazyCollectionValueImpl.java @@ -960,8 +960,8 @@ public class LazyCollectionValueImpl extends ValueImpl implements LazyCollection @Override public synchronized @NonNull MutableIterable cachedIterable() { - List<@Nullable Object> lazyListOfElements2 = lazyListOfElements; - if (lazyListOfElements2 == null) { + List<@Nullable Object> listOfElements = lazyListOfElements; + if (listOfElements == null) { if (lazyIterator) { System.err.println(NameUtil.debugSimpleName(this) + " re-iterating"); // throw new UnsupportedOperationException(); diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/MapValueImpl.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/MapValueImpl.java index 91e4ad6420..2c1ff06e2f 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/MapValueImpl.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/values/MapValueImpl.java @@ -306,7 +306,7 @@ public class MapValueImpl extends ValueImpl implements MapValue //, Iterable<Obj @Override public @NonNull CollectionValue getKeys() { CollectionTypeId setId = TypeId.SET.getSpecializedId(typeId.getValueTypeId()); - return ValueUtil.createCollectionValue(setId, true, keySet()); + return ValueUtil.createCollectionOfAll(setId, true, keySet()); } @Override @@ -317,7 +317,7 @@ public class MapValueImpl extends ValueImpl implements MapValue //, Iterable<Obj @Override public @NonNull CollectionValue getValues() { CollectionTypeId bagId = TypeId.BAG.getSpecializedId(typeId.getValueTypeId()); - return ValueUtil.createCollectionValue(bagId, true, boxedValues.values()); + return ValueUtil.createCollectionOfAll(bagId, true, boxedValues.values()); } @Override diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/logical/BooleanAllInstancesOperation.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/logical/BooleanAllInstancesOperation.java index 62abc9bc79..a545fbdc37 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/logical/BooleanAllInstancesOperation.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/logical/BooleanAllInstancesOperation.java @@ -16,6 +16,7 @@ import org.eclipse.ocl.pivot.evaluation.Evaluator; import org.eclipse.ocl.pivot.evaluation.Executor; import org.eclipse.ocl.pivot.ids.CollectionTypeId; import org.eclipse.ocl.pivot.ids.TypeId; +import org.eclipse.ocl.pivot.internal.iterators.FromArrayIterator; import org.eclipse.ocl.pivot.library.AbstractUntypedUnaryOperation; import org.eclipse.ocl.pivot.values.CollectionValue; @@ -40,6 +41,6 @@ public class BooleanAllInstancesOperation extends AbstractUntypedUnaryOperation @Override public @NonNull CollectionValue evaluate(@NonNull Executor executor, @Nullable Object sourceVal) { // Boolean has two instances: false, true - return executor.getIdResolver().createSetOfEach(SET_BOOLEAN, Boolean.FALSE, Boolean.TRUE); + return FromArrayIterator.create(SET_BOOLEAN, true, Boolean.FALSE, Boolean.TRUE); } } diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclAsSetOperation.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclAsSetOperation.java index 683633eb45..cca40afbf5 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclAsSetOperation.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclAsSetOperation.java @@ -16,6 +16,9 @@ import org.eclipse.ocl.pivot.evaluation.Evaluator; import org.eclipse.ocl.pivot.evaluation.Executor; import org.eclipse.ocl.pivot.ids.CollectionTypeId; import org.eclipse.ocl.pivot.ids.TypeId; +import org.eclipse.ocl.pivot.internal.iterators.AbstractLazyIterator; +import org.eclipse.ocl.pivot.internal.iterators.FromArrayIterator; +import org.eclipse.ocl.pivot.internal.values.LazyCollectionValueImpl; import org.eclipse.ocl.pivot.library.AbstractUnaryOperation; import org.eclipse.ocl.pivot.values.CollectionValue; import org.eclipse.ocl.pivot.values.InvalidValueException; @@ -43,10 +46,10 @@ public class OclAnyOclAsSetOperation extends AbstractUnaryOperation throw (InvalidValueException)sourceVal; } else if (sourceVal == null) { - return executor.getIdResolver().createSetOfEach((CollectionTypeId)returnTypeId); + return new LazyCollectionValueImpl((CollectionTypeId)returnTypeId, AbstractLazyIterator.EMPTY_ITERATOR, null); } else { - return executor.getIdResolver().createSetOfEach((CollectionTypeId)returnTypeId, sourceVal); + return FromArrayIterator.create((CollectionTypeId)returnTypeId, true, sourceVal); } } } diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclTypesOperation.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclTypesOperation.java index 28fea0db1d..568678788c 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclTypesOperation.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/library/oclany/OclAnyOclTypesOperation.java @@ -16,6 +16,7 @@ import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.evaluation.Executor; import org.eclipse.ocl.pivot.ids.CollectionTypeId; import org.eclipse.ocl.pivot.ids.TypeId; +import org.eclipse.ocl.pivot.internal.iterators.FromArrayIterator; import org.eclipse.ocl.pivot.library.AbstractUnaryOperation; import org.eclipse.ocl.pivot.values.CollectionValue; @@ -33,6 +34,6 @@ public class OclAnyOclTypesOperation extends AbstractUnaryOperation @Override public @NonNull CollectionValue evaluate(@NonNull Executor executor, @NonNull TypeId returnTypeId, @Nullable Object sourceVal) { Type dynamicTypeOf = executor.getIdResolver().getDynamicTypeOf(sourceVal); - return executor.getIdResolver().createSetOfEach((CollectionTypeId)returnTypeId, dynamicTypeOf); + return FromArrayIterator.create((CollectionTypeId)returnTypeId, true, dynamicTypeOf); } } diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/TypeUtil.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/TypeUtil.java index 086a227863..bb10fd721f 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/TypeUtil.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/TypeUtil.java @@ -10,7 +10,9 @@ *******************************************************************************/ package org.eclipse.ocl.pivot.utilities; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -45,9 +47,11 @@ import org.eclipse.ocl.pivot.internal.values.CollectionTypeParametersImpl; import org.eclipse.ocl.pivot.internal.values.MapTypeParametersImpl; import org.eclipse.ocl.pivot.types.ParameterTypesImpl; import org.eclipse.ocl.pivot.types.TemplateParametersImpl; +import org.eclipse.ocl.pivot.values.Bag; import org.eclipse.ocl.pivot.values.CollectionTypeParameters; import org.eclipse.ocl.pivot.values.IntegerValue; import org.eclipse.ocl.pivot.values.MapTypeParameters; +import org.eclipse.ocl.pivot.values.OrderedSet; import org.eclipse.ocl.pivot.values.UnlimitedNaturalValue; public class TypeUtil @@ -136,6 +140,40 @@ public class TypeUtil return firstInheritance.isSuperInheritanceOf(secondInheritance); } + public static @NonNull CollectionTypeId getCollectionTypeId(@NonNull Iterable<?> unboxedValue) { + if ((unboxedValue instanceof LinkedHashSet) || (unboxedValue instanceof OrderedSet)) { + return TypeId.ORDERED_SET; + } + else if (unboxedValue instanceof Bag) { + return TypeId.BAG; + } + else if (unboxedValue instanceof Set) { + return TypeId.SET; + } + else { + return TypeId.SEQUENCE; + } + } + + public static @NonNull CollectionTypeId getCollectionTypeId(boolean isOrdered, boolean isUnique) { + if (isOrdered) { + if (isUnique) { + return TypeId.ORDERED_SET; + } + else { + return TypeId.SEQUENCE; + } + } + else { + if (isUnique) { + return TypeId.SET; + } + else { + return TypeId.BAG; + } + } + } + /** * @deprecated add isNullFree argument */ diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/ValueUtil.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/ValueUtil.java index 55ca25b8f3..b81d468f30 100644 --- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/ValueUtil.java +++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/ValueUtil.java @@ -43,8 +43,8 @@ import org.eclipse.ocl.pivot.ids.TupleTypeId; import org.eclipse.ocl.pivot.ids.TypeId; import org.eclipse.ocl.pivot.internal.iterators.AbstractLazyIterator; import org.eclipse.ocl.pivot.internal.iterators.FromArrayIterator; -import org.eclipse.ocl.pivot.internal.iterators.FromCollectionIterator; import org.eclipse.ocl.pivot.internal.iterators.FromIntegerRangesIterator; +import org.eclipse.ocl.pivot.internal.iterators.FromIterableIterator; import org.eclipse.ocl.pivot.internal.resource.StandaloneProjectMap; import org.eclipse.ocl.pivot.internal.values.BagImpl; import org.eclipse.ocl.pivot.internal.values.BigIntegerValueImpl; @@ -553,15 +553,20 @@ public abstract class ValueUtil return FromIntegerRangesIterator.create(typeId, false, new @NonNull Object[]{values}); } - @Deprecated /* @deprecated Use createCollectionValue */ + @Deprecated /* @deprecated Use createCollectionOfAll */ public static @NonNull CollectionValue createBagValue(@NonNull CollectionTypeId typeId, @NonNull Bag<@Nullable ? extends Object> boxedValues) { - return createCollectionValue(typeId, false, boxedValues); + return createCollectionOfAll(typeId, false, boxedValues); } public static @NonNull MutableIterable createCollectionAccumulatorValue(@NonNull CollectionTypeId collectedId) { return new LazyCollectionValueImpl(collectedId, AbstractLazyIterator.EMPTY_ITERATOR, null).mutableIterable(); } + public static @NonNull CollectionValue createCollectionOfAll(@NonNull CollectionTypeId typeId, boolean uniqueElements, @NonNull Collection<@Nullable ? extends Object> boxedValues) { + checkValid(boxedValues); + return FromIterableIterator.create(typeId, uniqueElements, boxedValues); + } + public static @NonNull CollectionValue createCollectionOfEach(@NonNull CollectionTypeId typeId, boolean uniqueElements, @Nullable Object @NonNull ... boxedValues) { checkValid(boxedValues); return FromArrayIterator.create(typeId, uniqueElements, boxedValues); @@ -572,11 +577,6 @@ public abstract class ValueUtil return FromIntegerRangesIterator.create(typeId, uniqueElements, boxedValues); } - public static @NonNull CollectionValue createCollectionValue(@NonNull CollectionTypeId typeId, boolean uniqueElements, @NonNull Collection<@Nullable ? extends Object> boxedValues) { - checkValid(boxedValues); - return FromCollectionIterator.create(typeId, uniqueElements, boxedValues); - } - public static @NonNull InvalidValueException createInvalidValue(@NonNull Exception e) { if (e instanceof InvalidValueException) { return (InvalidValueException)e; @@ -621,9 +621,9 @@ public abstract class ValueUtil return createCollectionRange(typeId, false, values); } - @Deprecated /* @deprecated Use createCollectionValue */ + @Deprecated /* @deprecated Use createCollectionOfAll */ public static @NonNull CollectionValue createOrderedSetValue(@NonNull CollectionTypeId typeId, @NonNull Collection<@Nullable ? extends Object> boxedValues) { - return createCollectionValue(typeId, false, boxedValues); + return createCollectionOfAll(typeId, false, boxedValues); } public static @NonNull IntegerRange createRange(@NonNull IntegerValue firstInteger, @NonNull IntegerValue lastInteger) { @@ -649,9 +649,9 @@ public abstract class ValueUtil return createCollectionRange(typeId, false, values); } - @Deprecated /* @deprecated Use createCollectionValue */ + @Deprecated /* @deprecated Use createCollectionOfAll */ public static @NonNull CollectionValue createSequenceValue(@NonNull CollectionTypeId typeId, @NonNull List<@Nullable ? extends Object> boxedValues) { - return createCollectionValue(typeId, false, boxedValues); + return createCollectionOfAll(typeId, false, boxedValues); } @Deprecated /* @deprecated Use createCollectionAccumulatorValue */ @@ -669,9 +669,9 @@ public abstract class ValueUtil return createCollectionRange(typeId, false, values); } - @Deprecated /* @deprecated Use createCollectionValue */ + @Deprecated /* @deprecated Use createCollectionOfAll */ public static @NonNull CollectionValue createSetValue(@NonNull CollectionTypeId typeId, @NonNull Collection<@Nullable ? extends Object> boxedValues) { - return createCollectionValue(typeId, false, boxedValues); + return createCollectionOfAll(typeId, false, boxedValues); } public static @NonNull TupleValue createTupleValue(@NonNull TupleTypeId typeId, @NonNull Map<@NonNull ? extends TuplePartId, @Nullable Object> values) { |