[510180] Distinguish true EBoolean / EBooleanObject
diff --git a/plugins/org.eclipse.ocl.pivot/.options b/plugins/org.eclipse.ocl.pivot/.options
index bc63607..35158b0 100644
--- a/plugins/org.eclipse.ocl.pivot/.options
+++ b/plugins/org.eclipse.ocl.pivot/.options
@@ -30,6 +30,9 @@
 # Trace maintenance of CompletePackages 
 org.eclipse.ocl.pivot/completePackages=false
 
+# Trace conversion of not-optional primitive types such as EBoolean
+org.eclipse.ocl.pivot/ecore2as/notOptional=false
+
 # Trace maintenance of cached evaluations 
 org.eclipse.ocl.pivot/evaluations=false
 
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreReferenceVisitor.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreReferenceVisitor.java
index dd3502e..9f7de5e 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreReferenceVisitor.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreReferenceVisitor.java
@@ -61,20 +61,25 @@
 	{
 		public final @Nullable Type type;
 		public final boolean isRequired;
-		
+
 		public OptionalType(@Nullable Type type, boolean isRequired) {
 			this.type = type;
 			this.isRequired = isRequired;
 		}
 	}
-	
+
 	private static final Logger logger = Logger.getLogger(AS2EcoreReferenceVisitor.class);
 
-	protected final @NonNull AS2EcoreTypeRefVisitor typeRefVisitor;
-	
+	protected final @NonNull AS2EcoreTypeRefVisitor typeRefVisitor;				// Optional
+	/**
+	 * @since 1.3
+	 */
+	protected final @NonNull AS2EcoreTypeRefVisitor requiredTypeRefVisitor;		// Required
+
 	public AS2EcoreReferenceVisitor(@NonNull AS2Ecore context) {
 		super(context);
-		typeRefVisitor = new AS2EcoreTypeRefVisitor(context);
+		typeRefVisitor = new AS2EcoreTypeRefVisitor(context, false);
+		requiredTypeRefVisitor = new AS2EcoreTypeRefVisitor(context, true);
 	}
 
 	protected @Nullable OptionalType addPropertyRedefinitionEAnnotations(@NonNull EStructuralFeature eStructuralFeature, @NonNull Property pivotProperty) {
@@ -229,8 +234,17 @@
 		}
 	}
 
+	/* @deprecated provide isRequired argument */
+	@Deprecated
 	protected void setEType(@NonNull ETypedElement eTypedElement, @NonNull Type pivotType) {
-		EObject eObject = typeRefVisitor.safeVisit(pivotType);
+		setEType(eTypedElement, pivotType, false);
+	}
+
+	/**
+	 * @since 1.3
+	 */
+	protected void setEType(@NonNull ETypedElement eTypedElement, @NonNull Type pivotType, boolean isRequired) {
+		EObject eObject = (isRequired ? requiredTypeRefVisitor : typeRefVisitor).safeVisit(pivotType);
 		if (eObject instanceof EGenericType) {
 			eTypedElement.setEGenericType((EGenericType)eObject);
 		}
@@ -245,7 +259,7 @@
 		else {
 			@SuppressWarnings("unused")
 			EObject eObject2 = typeRefVisitor.safeVisit(pivotType);
-//			throw new IllegalArgumentException("Unsupported pivot type '" + pivotType + "' in AS2Ecore Reference pass");
+			//			throw new IllegalArgumentException("Unsupported pivot type '" + pivotType + "' in AS2Ecore Reference pass");
 		}
 	}
 
@@ -304,7 +318,7 @@
 			}
 			eTypedElement.setUnique(true);
 			eTypedElement.setOrdered(true);		// Ecore default
-			setEType(eTypedElement, pivotType);
+			setEType(eTypedElement, pivotType, isRequired);
 		}
 	}
 
@@ -485,13 +499,13 @@
 			if (pivotType == null) {
 				return null;				// Occurs for Operation return type
 			}
-//			setEType(eTypedElement, pivotType);
+			//			setEType(eTypedElement, pivotType);
 			setETypeAndMultiplicity(eTypedElement, pivotType, pivotTypedElement.isIsRequired());
 		}
 		return null;
 	}
-	
-/*	@Override
+
+	/*	@Override
 	public Object caseEAnnotation(EAnnotation eAnnotation) {
 		AnnotationCS csAnnotation = (AnnotationCS) deferMap.get(eAnnotation);
 		for (ModelElementCSRef csReference : csAnnotation.getReferences()) {
@@ -503,7 +517,7 @@
 		return null;
 	} */
 
-/*	@Override
+	/*	@Override
 	public Object caseEGenericType(EGenericType eGenericType) {
 		TypedTypeRefCS csTypeRef = (TypedTypeRefCS) deferMap.get(eGenericType);
 		TypeCS typeRef = csTypeRef.getType();
@@ -522,7 +536,7 @@
 		return null;
 	} */
 
-/*	@Override
+	/*	@Override
 	public Object caseEReference(EReference eReference) {
 		OCLinEcoreReferenceCS csReference = (OCLinEcoreReferenceCS) deferMap.get(eReference);
 		ReferenceCSRef csOpposite = csReference.getOpposite();
@@ -541,17 +555,17 @@
 		return null;
 	} */
 
-//	@Override
-//	public Object caseETypeParameter(ETypeParameter eTypeParameter) {
-//		TypeParameterCS csTypeParameter = (TypeParameterCS) deferMap.get(eTypeParameter);
-/*			ClassifierRef classifierRef = csTypedElement.getType();
+	//	@Override
+	//	public Object caseETypeParameter(ETypeParameter eTypeParameter) {
+	//		TypeParameterCS csTypeParameter = (TypeParameterCS) deferMap.get(eTypeParameter);
+	/*			ClassifierRef classifierRef = csTypedElement.getType();
 		if (classifierRef != null) {
 			EClassifier eClassifier = resolveClassifierRef(classifierRef);
 			if (eClassifier != null) {
 				eTypedElement.setEType(eClassifier);
 			}
 		} */
-//		return null;
-//	}
-	
+	//		return null;
+	//	}
+
 }
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreTypeRefVisitor.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreTypeRefVisitor.java
index 2c796f0..d6cc364 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreTypeRefVisitor.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/as2es/AS2EcoreTypeRefVisitor.java
@@ -48,15 +48,29 @@
 import org.eclipse.ocl.pivot.values.Unlimited;
 
 public class AS2EcoreTypeRefVisitor
-	extends AbstractExtendingVisitor<EObject, AS2Ecore>
+extends AbstractExtendingVisitor<EObject, AS2Ecore>
 {
 	protected final @NonNull PivotMetamodelManager metamodelManager;
 	protected final @NonNull StandardLibraryInternal standardLibrary;
-	
+	/**
+	 * @since 1.3
+	 */
+	protected final boolean isRequired;
+
+	/* @deprecated provide isRequired argument */
+	@Deprecated
 	public AS2EcoreTypeRefVisitor(@NonNull AS2Ecore context) {
+		this(context, true);
+	}
+
+	/**
+	 * @since 1.3
+	 */
+	public AS2EcoreTypeRefVisitor(@NonNull AS2Ecore context, boolean isRequired) {
 		super(context);
 		this.metamodelManager = context.getMetamodelManager();
 		this.standardLibrary = context.getStandardLibrary();
+		this.isRequired = isRequired;
 	}
 
 	public EGenericType resolveEGenericType(org.eclipse.ocl.pivot.@NonNull Class type) {
@@ -170,8 +184,8 @@
 		Number upper = pivotType.getUpper();
 		if ((lower != null) && (upper != null) && ((lower.longValue() != 0) || !(upper instanceof  Unlimited))) {
 			// FIXME Ecore does not support nested multiplicities
-//			eGenericType.setLower(lower.longValue());
-//			eGenericType.setUpper(upper instanceof Unlimited) ? -1 : upper.longValue());
+			//			eGenericType.setLower(lower.longValue());
+			//			eGenericType.setUpper(upper instanceof Unlimited) ? -1 : upper.longValue());
 		}
 		return eGenericType;
 	}
@@ -185,7 +199,7 @@
 		else {
 			return OCLstdlibPackage.Literals.OCL_INVALID;
 		}
-	}	
+	}
 
 	@Override
 	public EObject visitMapType(@NonNull MapType object) {
@@ -230,7 +244,7 @@
 					return EcorePackage.Literals.ESTRING;
 				}
 				else if (aType == standardLibrary.getBooleanType()) {
-					return EcorePackage.Literals.EBOOLEAN;
+					return isRequired ? EcorePackage.Literals.EBOOLEAN : EcorePackage.Literals.EBOOLEAN_OBJECT;
 				}
 				else if (aType == standardLibrary.getIntegerType()) {
 					return EcorePackage.Literals.EBIG_INTEGER;
@@ -271,10 +285,10 @@
 		return eGenericType;
 	}
 
-//	@Override
-//	public EObject visitTupleType(@NonNull TupleType object) {
-//		return getOCLstdlibType(/*TypeId.OCL_VOID_NAME*/"OclTuple", object);
-//	}	
+	//	@Override
+	//	public EObject visitTupleType(@NonNull TupleType object) {
+	//		return getOCLstdlibType(/*TypeId.OCL_VOID_NAME*/"OclTuple", object);
+	//	}
 
 	@Override
 	public EObject visitVoidType(@NonNull VoidType pivotType) {
@@ -285,5 +299,5 @@
 		else {
 			return OCLstdlibPackage.Literals.OCL_VOID;
 		}
-	}	
+	}
 }
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/AbstractExternal2AS.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/AbstractExternal2AS.java
index 4d7f1cd..cedaee0 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/AbstractExternal2AS.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/AbstractExternal2AS.java
@@ -13,12 +13,14 @@
 import org.eclipse.emf.common.util.EMap;
 import org.eclipse.emf.ecore.EAnnotation;
 import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EClassifier;
 import org.eclipse.emf.ecore.EFactory;
 import org.eclipse.emf.ecore.EGenericType;
 import org.eclipse.emf.ecore.EModelElement;
 import org.eclipse.emf.ecore.ENamedElement;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EOperation;
+import org.eclipse.emf.ecore.ETypedElement;
 import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.jdt.annotation.NonNull;
@@ -41,13 +43,29 @@
 	protected AbstractExternal2AS(@NonNull EnvironmentFactoryInternal environmentFactory) {
 		super(environmentFactory);
 	}
-	
+
 	public abstract void addGenericType(@NonNull EGenericType eObject);
 
 	public abstract void addMapping(@NonNull EObject eObject, @NonNull Element pivotElement);
 
 	protected abstract Model basicGetPivotModel();
 
+	/**
+	 * @since 1.3
+	 */
+	public boolean cannotBeOptional(@NonNull ETypedElement eTypedElement) {	// Fixes Bug 510180, Ecore does not prohibit optional primitive types
+		EClassifier eType = eTypedElement.getEType();
+		if (eType != null) {
+			Class<?> instanceClass = eType.getInstanceClass();
+			if ((instanceClass != null) && ((instanceClass == boolean.class) || (instanceClass == byte.class)
+					|| (instanceClass == double.class) || (instanceClass == float.class)
+					|| (instanceClass == int.class) || (instanceClass == long.class) || (instanceClass == short.class))) {
+				return true;
+			}
+		}
+		return false;
+	}
+
 	@Override
 	public void dispose() {
 		Model pivotModel2 = basicGetPivotModel();
@@ -61,7 +79,7 @@
 		}
 		metamodelManager.removeExternalResource(this);
 	}
-	
+
 	public abstract void error(@NonNull String message);
 
 	/**
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
index 832460c..9240e9c 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2AS.java
@@ -68,14 +68,21 @@
 import org.eclipse.ocl.pivot.resource.ProjectManager.IProjectDescriptor;
 import org.eclipse.ocl.pivot.resource.ProjectManager.IProjectDescriptor.IProjectDescriptorExtension;
 import org.eclipse.ocl.pivot.resource.ProjectManager.IResourceDescriptor;
+import org.eclipse.ocl.pivot.util.PivotPlugin;
 import org.eclipse.ocl.pivot.utilities.ClassUtil;
 import org.eclipse.ocl.pivot.utilities.NameUtil;
 import org.eclipse.ocl.pivot.utilities.ParserException;
 import org.eclipse.ocl.pivot.utilities.PivotConstants;
 import org.eclipse.ocl.pivot.utilities.PivotUtil;
+import org.eclipse.ocl.pivot.utilities.TracingOption;
 
 public class Ecore2AS extends AbstractExternal2AS
 {
+	/**
+	 * @since 1.3
+	 */
+	public static final @NonNull TracingOption NOT_OPTIONAL = new TracingOption(PivotPlugin.PLUGIN_ID, "ecore2as/notOptional");
+
 	public static @NonNull Ecore2AS getAdapter(@NonNull Resource resource, @NonNull EnvironmentFactoryInternal environmentFactory) {
 		External2AS adapter = findAdapter(resource, environmentFactory);
 		Ecore2AS castAdapter = (Ecore2AS) adapter;
@@ -87,10 +94,10 @@
 
 	/**
 	 * Convert an (annotated) Ecore resource to a Pivot Model.
-	 * @param alias 
-	 * 
+	 * @param alias
+	 *
 	 * @param ecoreResource the annotated Ecore resource
-	 * 
+	 *
 	 * @return the Pivot root package
 	 */
 	public static @NonNull Model importFromEcore(@NonNull EnvironmentFactoryInternal environmentFactory, String alias, @NonNull Resource ecoreResource) {
@@ -129,14 +136,14 @@
 		}
 		Ecore2AS conversion = getAdapter(ecoreResource, environmentFactory);
 		conversion.loadImports(ecoreResource);
-//		if (asMetamodels != null) {
-//			
-//		}
+		//		if (asMetamodels != null) {
+		//
+		//		}
 		PivotMetamodelManager metamodelManager = environmentFactory.getMetamodelManager();
 		conversion.pivotModel = PivotUtil.createModel(ecoreASResource.getURI().toString());
-//		conversion.installImports();
+		//		conversion.installImports();
 		conversion.update(ecoreASResource, ClassUtil.nonNullEMF(ecoreResource.getContents()));
-		
+
 		AliasAdapter ecoreAdapter = AliasAdapter.findAdapter(ecoreResource);
 		if (ecoreAdapter != null) {
 			Map<EObject, String> ecoreAliasMap = ecoreAdapter.getAliasMap();
@@ -153,7 +160,7 @@
 		return conversion;
 	}
 
-/*	public static Ecore2AS createConverter(MetamodelManager metamodelManager, Resource ecoreResource) {
+	/*	public static Ecore2AS createConverter(MetamodelManager metamodelManager, Resource ecoreResource) {
 		EList<Adapter> eAdapters = ecoreResource.eAdapters();
 		Ecore2AS conversion = (Ecore2AS) EcoreUtil.getAdapter(eAdapters, Ecore2AS.class);
 		if (conversion == null) {
@@ -164,10 +171,10 @@
 	} */
 
 	/**
-	 * Convert an (annotated) Ecore object to a pivot element. 
-	 * 
+	 * Convert an (annotated) Ecore object to a pivot element.
+	 *
 	 * @param eObject the annotated Ecore object
-	 * 
+	 *
 	 * @return the pivot element
 	 */
 	public static Element importFromEcore(@NonNull EnvironmentFactoryInternal environmentFactory, String alias, @NonNull EObject eObject) {
@@ -192,26 +199,26 @@
 	 * Set of all Ecore objects requiring further work during the reference pass.
 	 */
 	private Set<@NonNull EObject> referencers = null;
-	
+
 	/**
 	 * Set of all converters used during session.
 	 */
 	private Set<@NonNull Ecore2AS> allConverters = new HashSet<@NonNull Ecore2AS>();
-	
+
 	/**
 	 * List of all generic types.
 	 */
 	private List<@NonNull EGenericType> genericTypes = null;
-	
+
 	private List<Resource.@NonNull Diagnostic> errors = null;
-	
+
 	protected final @NonNull Resource ecoreResource;
-	
+
 	protected Model pivotModel = null;						// Set by importResource
-	protected final Ecore2ASDeclarationSwitch declarationPass = new Ecore2ASDeclarationSwitch(this);	
+	protected final Ecore2ASDeclarationSwitch declarationPass = new Ecore2ASDeclarationSwitch(this);
 	protected final Ecore2ASReferenceSwitch referencePass = new Ecore2ASReferenceSwitch(this);
 	private HashMap</*@NonNull*/ EClassifier, @NonNull Type> ecore2asMap = null;
-	
+
 	/**
 	 * The loadableURI of the ecoreResource, which may differ from ecoreResource.getURI() when
 	 * ecoreResource is an installed package whose nsURI may not be globally registered. The accessible
@@ -219,7 +226,7 @@
 	 * *.ecore's rather than the missing nsURI regisyrations.
 	 */
 	private URI ecoreURI = null;
-	
+
 	/**
 	 * All imported EPackages identified by AS_METAMODEL_ANNOTATION_SOURCE annotations.
 	 */
@@ -229,29 +236,29 @@
 	 * All imported EObjects identified as IMPORT_ANNOTATION_SOURCE annotations.
 	 */
 	private Set<EObject> importedEObjects = null;
-	
+
 	public Ecore2AS(@NonNull Resource ecoreResource, @NonNull EnvironmentFactoryInternal environmentFactory) {
 		super(environmentFactory);
 		this.ecoreResource = ecoreResource;
 		this.environmentFactory.addExternal2AS(this);
 	}
-	
+
 	protected void addCreated(@NonNull EObject eObject, @NonNull Element pivotElement) {
 		@SuppressWarnings("unused")
 		Element oldElement = newCreateMap.put(eObject, pivotElement);
-//		if (eObject instanceof ENamedElement) {
-//			assert (oldElement == null) || (oldElement == pivotElement) || ((oldElement instanceof DataType) && (((DataType)oldElement).getBehavioralType() == pivotElement));
-//		}
-//		else {
-//			assert oldElement == null;
-//		}
+		//		if (eObject instanceof ENamedElement) {
+		//			assert (oldElement == null) || (oldElement == pivotElement) || ((oldElement instanceof DataType) && (((DataType)oldElement).getBehavioralType() == pivotElement));
+		//		}
+		//		else {
+		//			assert oldElement == null;
+		//		}
 	}
 
 	@Override
 	public void addGenericType(@NonNull EGenericType eObject) {
 		genericTypes.add(eObject);
 	}
-	
+
 	@Override
 	public void addMapping(@NonNull EObject eObject, @NonNull Element pivotElement) {
 		if (pivotElement instanceof PivotObjectImpl) {
@@ -264,14 +271,14 @@
 				pivotElement1 = pivotType;	// remap to the library type
 			}
 		}
-//		Element pivotElement2 = pivotElement;
-//		if (pivotElement instanceof DataType) {
-//			Type behavioralType = ((DataType)pivotElement).getBehavioralType();
-//			if (behavioralType != null) {
-//				pivotElement2 = behavioralType;
-//			}
-//		}
-//		assert pivotElement1 == pivotElement2;
+		//		Element pivotElement2 = pivotElement;
+		//		if (pivotElement instanceof DataType) {
+		//			Type behavioralType = ((DataType)pivotElement).getBehavioralType();
+		//			if (behavioralType != null) {
+		//				pivotElement2 = behavioralType;
+		//			}
+		//		}
+		//		assert pivotElement1 == pivotElement2;
 		addCreated(eObject, pivotElement1);
 	}
 
@@ -369,33 +376,33 @@
 	}
 
 	public Type getASType(@NonNull EObject eObject) {
-			Element pivotElement = newCreateMap.get(eObject);
-			if (pivotElement == null) {
-				Resource resource = eObject.eResource();
-				if ((resource != ecoreResource) && (resource != null)) {
-					Ecore2AS converter = getAdapter(resource, environmentFactory);
-					if (allConverters.add(converter)) {
-						converter.getASModel();
-	//					allEClassifiers.addAll(converter.allEClassifiers);
-	//					allNames.addAll(converter.allNames);
-						for (Map.Entry<@NonNull EObject, @NonNull Element> entry : converter.newCreateMap.entrySet()) {
-							newCreateMap.put(entry.getKey(), entry.getValue());
-						}
+		Element pivotElement = newCreateMap.get(eObject);
+		if (pivotElement == null) {
+			Resource resource = eObject.eResource();
+			if ((resource != ecoreResource) && (resource != null)) {
+				Ecore2AS converter = getAdapter(resource, environmentFactory);
+				if (allConverters.add(converter)) {
+					converter.getASModel();
+					//					allEClassifiers.addAll(converter.allEClassifiers);
+					//					allNames.addAll(converter.allNames);
+					for (Map.Entry<@NonNull EObject, @NonNull Element> entry : converter.newCreateMap.entrySet()) {
+						newCreateMap.put(entry.getKey(), entry.getValue());
 					}
 				}
-				pivotElement = newCreateMap.get(eObject);
 			}
-			if (pivotElement == null) {
-				error("Unresolved " + eObject);
-			}
-			else if (!(pivotElement instanceof Type)) {
-				error("Incompatible " + eObject);
-			}
-			else {
-				return (Type) pivotElement;
-			}
-			return null;
+			pivotElement = newCreateMap.get(eObject);
 		}
+		if (pivotElement == null) {
+			error("Unresolved " + eObject);
+		}
+		else if (!(pivotElement instanceof Type)) {
+			error("Incompatible " + eObject);
+		}
+		else {
+			return (Type) pivotElement;
+		}
+		return null;
+	}
 
 	/**
 	 * Return the baseURI of ecoreResource against which its imports should be resolved.
@@ -465,7 +472,7 @@
 			org.eclipse.ocl.pivot.Package asLibrary = standardLibrary.getPackage();
 			newCreateMap.put(libraryEPackage, asLibrary);
 			List<org.eclipse.ocl.pivot.Class> ownedType = asLibrary.getOwnedClasses();
-//			int prefix = LibraryConstants.ECORE_STDLIB_PREFIX.length();
+			//			int prefix = LibraryConstants.ECORE_STDLIB_PREFIX.length();
 			for (@SuppressWarnings("null")@NonNull EClassifier eClassifier : libraryEPackage.getEClassifiers()) {
 				String name = environmentFactory.getTechnology().getOriginalName(eClassifier); //.substring(prefix);
 				Type asType = NameUtil.getNameable(ownedType, name);
@@ -477,40 +484,40 @@
 			return ClassUtil.nonNullModel(containingRoot);
 		}
 		@NonNull ASResource asResource = metamodelManager.getResource(pivotURI, ASResource.ECORE_CONTENT_TYPE);
-//		try {
-			if ((metamodelManager.getLibraryResource() == null) && isPivot(ecoreContents)) {
-				String nsURI = ((EPackage)ecoreContents.iterator().next()).getNsURI();
-				if (nsURI != null) {
-					String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
-					OCLstdlib library = OCLstdlib.create(stdlibASUri);
-					metamodelManager.installResource(library);
-//					metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
-				}
+		//		try {
+		if ((metamodelManager.getLibraryResource() == null) && isPivot(ecoreContents)) {
+			String nsURI = ((EPackage)ecoreContents.iterator().next()).getNsURI();
+			if (nsURI != null) {
+				String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
+				OCLstdlib library = OCLstdlib.create(stdlibASUri);
+				metamodelManager.installResource(library);
+				//					metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
 			}
-			URI uri = ecoreURI != null ? ecoreURI : ecoreResource.getURI();
-			Model pivotModel2 = null;
-			if (asResource.getContents().size() > 0) { 
-				EObject eObject = asResource.getContents().get(0);
-				if (eObject instanceof Model) {
-					pivotModel2 = (Model) eObject;
-				}
+		}
+		URI uri = ecoreURI != null ? ecoreURI : ecoreResource.getURI();
+		Model pivotModel2 = null;
+		if (asResource.getContents().size() > 0) {
+			EObject eObject = asResource.getContents().get(0);
+			if (eObject instanceof Model) {
+				pivotModel2 = (Model) eObject;
 			}
-			if (pivotModel2 == null) {
-				pivotModel2 = pivotModel = PivotUtil.createModel(uri.toString());
-			}
-			pivotModel = pivotModel2;
-//			installImports();
-			newCreateMap = synthesizeCreateMap(asResource);
-			if (newCreateMap == null) {
-				update(asResource, ecoreContents);
-			}
-//		}
-//		catch (Exception e) {
-//			if (errors == null) {
-//				errors = new ArrayList<Resource.Diagnostic>();
-//			}
-//			errors.add(new XMIException("Failed to load '" + pivotURI + "'", e));
-//		}
+		}
+		if (pivotModel2 == null) {
+			pivotModel2 = pivotModel = PivotUtil.createModel(uri.toString());
+		}
+		pivotModel = pivotModel2;
+		//			installImports();
+		newCreateMap = synthesizeCreateMap(asResource);
+		if (newCreateMap == null) {
+			update(asResource, ecoreContents);
+		}
+		//		}
+		//		catch (Exception e) {
+		//			if (errors == null) {
+		//				errors = new ArrayList<Resource.Diagnostic>();
+		//			}
+		//			errors.add(new XMIException("Failed to load '" + pivotURI + "'", e));
+		//		}
 		List<Diagnostic> errors2 = errors;
 		if (errors2 != null) {
 			asResource.getErrors().addAll(ClassUtil.nullFree(errors2));
@@ -636,11 +643,11 @@
 		if ((asMetamodels != null) && (metamodelManager.getLibraryResource() == null)) {
 			String nsURI = asMetamodels.iterator().next().getNsURI();
 			if (nsURI != null) {
-//				String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
+				//				String stdlibASUri = LibraryConstants.STDLIB_URI + PivotConstants.DOT_OCL_AS_FILE_EXTENSION;
 				OCLstdlib library = OCLstdlib.getDefault(); //create(stdlibASUri, "ocl", "ocl", nsURI);
-//				metamodelManager.addPackageNsURISynonym(OCLstdlib.STDLIB_URI, PivotConstants.METAMODEL_URI);
+				//				metamodelManager.addPackageNsURISynonym(OCLstdlib.STDLIB_URI, PivotConstants.METAMODEL_URI);
 				metamodelManager.installResource(library);
-//				metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
+				//				metamodelManager.installAs(nsURI, OCLstdlibTables.PACKAGE);
 			}
 		}
 	}
@@ -697,7 +704,7 @@
 			return uri;
 		}
 		StandaloneProjectMap projectMap = (StandaloneProjectMap)projectManager;
-/*		if (baseURI == null) {
+		/*		if (baseURI == null) {
 			IPackageDescriptor packageDescriptor = projectManager.getPackageDescriptor(URI.createURI(ePackage.getNsURI()));
 			if (packageDescriptor == null) {
 				return uri;
@@ -721,7 +728,7 @@
 									break;
 								}
 							}
-								
+
 							break;
 						}
 					}
@@ -736,7 +743,7 @@
 		referencers.add(eObject);
 	}
 
-/*	protected void refreshAnnotation(NamedElement pivotElement, String key, String value) {
+	/*	protected void refreshAnnotation(NamedElement pivotElement, String key, String value) {
 		String source = PIVOT_URI;
 		Annotation pivotAnnotation = null;
 		for (Annotation annotation : pivotElement.getOwnedAnnotation()) {
@@ -781,7 +788,7 @@
 		assert oldElement == null;
 		return castElement;
 	}
-	
+
 	protected Type resolveDataType(@NonNull EDataType eClassifier) {
 		Type pivotType = getEcore2ASMap().get(eClassifier);
 		if (pivotType == null) {
@@ -800,7 +807,7 @@
 		if (unspecializedPivotType == null) {
 			return null;
 		}
- 		List<@NonNull Type> templateArguments = new ArrayList<@NonNull Type>();
+		List<@NonNull Type> templateArguments = new ArrayList<@NonNull Type>();
 		for (EGenericType eTypeArgument : eTypeArguments) {
 			if (eTypeArgument != null) {
 				Type typeArgument = resolveType(resolvedSpecializations, eTypeArgument);
@@ -809,7 +816,7 @@
 				}
 			}
 		}
-		org.eclipse.ocl.pivot.Class unspecializedPivotClass = unspecializedPivotType.isClass(); 
+		org.eclipse.ocl.pivot.Class unspecializedPivotClass = unspecializedPivotType.isClass();
 		assert unspecializedPivotClass != null;			// FIXME
 		return metamodelManager.getLibraryType(unspecializedPivotClass, templateArguments);
 	}
@@ -844,7 +851,7 @@
 			assert eGenericType.getETypeArguments().isEmpty();
 			pivotType = resolveDataType((EDataType) eClassifier);
 		}
-		else { 
+		else {
 			assert eGenericType.getETypeArguments().isEmpty();
 			pivotType = resolveSimpleType(eClassifier);
 		}
@@ -872,13 +879,13 @@
 		assert eGenericType.getEClassifier() == null;
 		EClassifier eClassifier = eGenericType.getERawType();
 		assert eClassifier == EcorePackage.Literals.EJAVA_OBJECT;
-/*			WildcardTypeRefCS csTypeRef = BaseCSFactory.eINSTANCE.createWildcardTypeRefCS();
+		/*			WildcardTypeRefCS csTypeRef = BaseCSFactory.eINSTANCE.createWildcardTypeRefCS();
 			setOriginalMapping(csTypeRef, eObject);
 //			csTypeRef.setExtends(doSwitchAll(eGenericType.getExtends()));
 //			csTypeRef.setSuper(doSwitchAll(eGenericType.getSuper()));
 			return csTypeRef; */
 		return metamodelManager.createWildcardType(null, null);		// FIXME bounds
-/*		org.eclipse.ocl.pivot.Class pivotElement = PivotFactory.eINSTANCE.createClass();
+		/*		org.eclipse.ocl.pivot.Class pivotElement = PivotFactory.eINSTANCE.createClass();
 		String name = PivotConstants.WILDCARD_NAME;
 		EStructuralFeature eFeature = eGenericType.eContainmentFeature();
 		if ((eFeature != null) && eFeature.isMany()) {
@@ -889,7 +896,7 @@
 				name += index;
 			}
 		}
-		pivotElement.setName(name);		
+		pivotElement.setName(name);
 		return pivotElement; */
 	}
 
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASDeclarationSwitch.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASDeclarationSwitch.java
index fd33e20..656fbca 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASDeclarationSwitch.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASDeclarationSwitch.java
@@ -84,6 +84,7 @@
 import org.eclipse.ocl.pivot.internal.utilities.Technology;
 import org.eclipse.ocl.pivot.util.DerivedConstants;
 import org.eclipse.ocl.pivot.utilities.ClassUtil;
+import org.eclipse.ocl.pivot.utilities.NameUtil;
 import org.eclipse.ocl.pivot.utilities.PivotConstants;
 import org.eclipse.ocl.pivot.utilities.PivotUtil;
 
@@ -750,16 +751,9 @@
 		}
 		copyAnnotatedElement(pivotElement, eTypedElement, excludedAnnotations2);
 		int lower = eTypedElement.getLowerBound();
-		if (lower == 0) {
-			EClassifier eType = eTypedElement.getEType();
-			if (eType != null) {
-				Class<?> instanceClass = eType.getInstanceClass();
-				if ((instanceClass != null) && ((instanceClass == boolean.class) || (instanceClass == byte.class)
-						|| (instanceClass == double.class) || (instanceClass == float.class)
-						|| (instanceClass == int.class) || (instanceClass == long.class) || (instanceClass == short.class))) {
-					lower = 1;				// Fixes Bug 510180, Ecore does not prohibit optional primitive types
-				}
-			}
+		if ((lower == 0) && converter.cannotBeOptional(eTypedElement)) {
+			Ecore2AS.NOT_OPTIONAL.println(NameUtil.qualifiedNameFor(eTypedElement) + " converted to not-optional");
+			lower = 1;
 		}
 		int upper = eTypedElement.getUpperBound();
 		pivotElement.setIsRequired((upper == 1) && (lower == 1));
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASReferenceSwitch.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASReferenceSwitch.java
index f11b930..8a2c60c 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASReferenceSwitch.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/ecore/es2as/Ecore2ASReferenceSwitch.java
@@ -467,6 +467,21 @@
 				int lower = eObject.getLowerBound();
 				int upper = eObject.getUpperBound();
 				if (upper == 1) {
+					if (lower == 0) {
+						if (converter.cannotBeOptional(eObject)) {
+							lower = 1;
+							Ecore2AS.NOT_OPTIONAL.println(NameUtil.qualifiedNameFor(eObject) + " converted to not-optional");
+						}
+						else {
+							EClassifier eClassifier = eType.getEClassifier();
+							if (eClassifier instanceof EDataType) {
+								Class<?> instanceClass = ((EDataType)eClassifier).getInstanceClass();
+								if ((instanceClass == Boolean.class) && (pivotType.getESObject() == EcorePackage.Literals.EBOOLEAN_OBJECT)) {
+									pivotType = standardLibrary.getBooleanType();		// Correct Ecore's BooleanObject but not UML's BooleanObject
+								}
+							}
+						}
+					}
 					isRequired = lower == 1;
 				}
 				else {
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/utilities/ElementUtil.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/utilities/ElementUtil.java
index 4421c39..7048c10 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/utilities/ElementUtil.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/utilities/ElementUtil.java
@@ -83,7 +83,7 @@
 public class ElementUtil
 {
 	private static final String delegateExtensionPoints[] = {
-//		EcorePlugin.CONVERSION_DELEGATE_PPID, -- not available in EMF 2.7
+		//		EcorePlugin.CONVERSION_DELEGATE_PPID, -- not available in EMF 2.7
 		EcorePlugin.INVOCATION_DELEGATE_PPID,
 		EcorePlugin.QUERY_DELEGATE_PPID,
 		EcorePlugin.SETTING_DELEGATE_PPID,
@@ -108,12 +108,12 @@
 		if (csTypeRef == null) {
 			return null;
 		}
-//		if (csTypeRef instanceof CollectionTypeRefCS) {
-//			Type csType = ((CollectionTypeRefCS)csTypeRef).getType();
-//			if (csType instanceof CollectionType) {
-//				return ((CollectionType)csType).getName();
-//			}
-//		}
+		//		if (csTypeRef instanceof CollectionTypeRefCS) {
+		//			Type csType = ((CollectionTypeRefCS)csTypeRef).getType();
+		//			if (csType instanceof CollectionType) {
+		//				return ((CollectionType)csType).getName();
+		//			}
+		//		}
 		//FIXME Obsolete compatibility
 		MultiplicityCS csMultiplicity = csTypeRef.getOwnedMultiplicity();
 		if (csMultiplicity == null) {
@@ -149,7 +149,7 @@
 			return unique ? TypeId.SET_NAME : TypeId.BAG_NAME;
 		}
 	}
-	
+
 	public static @Nullable ModelElementCS getCsElement(@NonNull Element asElement) {
 		Resource asResource = asElement.eResource();
 		if (asResource == null) {
@@ -199,7 +199,7 @@
 		}
 		return delegationModes;
 	}
-	
+
 	public static @Nullable RootCSAttribution getDocumentAttribution(@NonNull ElementCS context) {
 		for (ElementCS target = context, parent; (parent = target.getParent()) != null; target = parent) {
 			Attribution attribution = PivotUtilInternal.getAttribution(parent);
@@ -250,7 +250,7 @@
 
 	/**
 	 * Extract the first embedded ExpressionInOCL.
-	 * @throws ParserException 
+	 * @throws ParserException
 	 */
 	public static @Nullable ExpressionInOCL getFirstQuery(@NonNull PivotMetamodelManager metamodelManager, BaseCSResource csResource) throws ParserException {
 		CS2AS cs2as = csResource.findCS2AS();
@@ -328,12 +328,12 @@
 					return 1;
 				}
 			}
-			return 0;			// OCL legacy allows null even though UML lowerBound() default is 1. 
+			return 0;			// OCL legacy allows null even though UML lowerBound() default is 1.
 		}
 		return csMultiplicity.getLower();
 	}
 
-	public static @Nullable <T extends NamedElementCS> T getNamedElementCS(@NonNull Collection<T> namedElements, @NonNull String name) {
+	public static @Nullable <@NonNull T extends NamedElementCS> T getNamedElementCS(@NonNull Collection<T> namedElements, @NonNull String name) {
 		for (T namedElement : namedElements) {
 			if (name.equals(namedElement.getName())) {
 				return namedElement;
@@ -380,7 +380,7 @@
 
 	public static @Nullable String getText(@NonNull ElementCS csElement, /*@NonNull*/ EReference feature) {
 		@SuppressWarnings("null")@NonNull List<INode> nodes = NodeModelUtils.findNodesForFeature(csElement, feature);
-//		assert (nodes.size() == 1;
+		//		assert (nodes.size() == 1;
 		if (nodes.isEmpty()) {
 			return null;
 		}
@@ -463,8 +463,8 @@
 
 	public static boolean isPrimitiveInstanceClass(@NonNull EDataType esObject) {
 		Class<?> instanceClass = esObject.getInstanceClass();
-		return (instanceClass == byte.class) || (instanceClass == char.class) || (instanceClass == double.class) || (instanceClass == float.class)
-				|| (instanceClass == int.class) || (instanceClass == long.class) || (instanceClass == short.class);
+		return (instanceClass == boolean.class) || (instanceClass == byte.class) || (instanceClass == char.class) || (instanceClass == double.class)
+				|| (instanceClass == float.class) || (instanceClass == int.class) || (instanceClass == long.class) || (instanceClass == short.class);
 	}
 
 	public static boolean isRequired(@Nullable TypedRefCS csTypeRef) {