[580139] Eliminate pre-lookup for Type-type arguments
diff --git a/plugins/org.eclipse.ocl.pivot/.settings/.api_filters b/plugins/org.eclipse.ocl.pivot/.settings/.api_filters
index ff62169..905475d 100644
--- a/plugins/org.eclipse.ocl.pivot/.settings/.api_filters
+++ b/plugins/org.eclipse.ocl.pivot/.settings/.api_filters
@@ -1471,6 +1471,19 @@
             </message_arguments>
         </filter>
     </resource>
+    <resource path="src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.java" type="org.eclipse.ocl.pivot.internal.messages.PivotMessagesInternal">
+        <filter id="336658481">
+            <message_arguments>
+                <message_argument value="org.eclipse.ocl.pivot.internal.messages.PivotMessagesInternal"/>
+                <message_argument value="UnresolvedElement_ERROR_"/>
+            </message_arguments>
+        </filter>
+        <filter id="1143996420">
+            <message_arguments>
+                <message_argument value="UnresolvedElement_ERROR_"/>
+            </message_arguments>
+        </filter>
+    </resource>
     <resource path="src/org/eclipse/ocl/pivot/internal/resource/ASResourceImpl.java" type="org.eclipse.ocl.pivot.internal.resource.ASResourceImpl">
         <filter id="336658481">
             <message_arguments>
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/attributes/ClassAttribution.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/attributes/ClassAttribution.java
index e6224b2..ef0c517 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/attributes/ClassAttribution.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/attributes/ClassAttribution.java
@@ -37,14 +37,6 @@
 		environmentView.addAllOperations(targetClass, null);
 		environmentView.addAllProperties(targetClass, null);
 		environmentView.addAllStates(targetClass);
-//		if (!environmentView.hasFinalResult()) {
-//			MetamodelManager metamodelManager = environmentView.getMetamodelManager();
-//			Type metatype = metamodelManager.getPivotType(targetClass.eClass().getName());		// FIXME getMetaType
-//			if (metatype != null) {
-//				environmentView.addAllOperations(metatype, FeatureFilter.SELECT_STATIC);
-//				environmentView.addAllProperties(metatype, FeatureFilter.SELECT_STATIC);
-//			}
-//		}
 		return scopeView.getParent();
 	}
 }
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.java
index 294a41e..27704e7 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.java
@@ -248,6 +248,7 @@
 	public static String MissingLibraryURI_ERROR_;
 	public static String RedundantIterator_WARNING_;
 	public static String UnknownContextType_ERROR_;
+	public static String UnresolvedElement_ERROR_;
 	public static String UnresolvedImport_ERROR_;
 	public static String UnresolvedInclude_ERROR_;
 	public static String UnresolvedIterationCall_ERROR_;
@@ -256,7 +257,7 @@
 	public static String UnresolvedOperation_ERROR_;
 	public static String UnresolvedOperationCall_ERROR_;
 	public static String UnresolvedProperty_ERROR_;
-	@Deprecated /* @deprecated ststic distinction eleminated */
+	@Deprecated /* @deprecated static distinction eleminated */
 	public static String UnresolvedStaticOperationCall_ERROR_;
 	@Deprecated /* @deprecated ststic distinction eleminated */
 	public static String UnresolvedStaticProperty_ERROR_;
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.properties b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.properties
index 0b2278a..42931f6 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.properties
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/messages/PivotMessagesInternal.properties
@@ -1442,6 +1442,16 @@
 #   1 - the ExpressionInOCL role within the parent/context object
 #
 UnknownContextType_ERROR_ = Unknown context type for ''{0}'' {1}
+
+#
+# Indicates that the element referenced by a name expression could
+# not be found in the type on which the property is called.
+# args:
+#   0 - the name of the type on which the property was called
+#   1 - the name of the property
+#
+UnresolvedElement_ERROR_ = Unresolved Element ''{0}::{1}''
+
 #
 # Indicates that the resource referenced by a model import declaration could
 # not be resolved.
@@ -1514,6 +1524,7 @@
 #   1 - the name of the property
 #
 UnresolvedProperty_ERROR_ = Unresolved Property ''{0}::{1}''
+
 #
 # Indicates that the static operation referenced by an operation call expression could
 # not be found in the type on which the operation is called.
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/scoping/EnvironmentView.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/scoping/EnvironmentView.java
index fb9ca71..0f59a54 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/scoping/EnvironmentView.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/internal/scoping/EnvironmentView.java
@@ -981,7 +981,12 @@
 		if (getName() == null) {
 			return false; // No name means search full hierarchy
 		}
-		return true;
+		for (Object object : contentsByName.values()) {
+			if (!(object instanceof Property) || !((Property)object).isIsImplicit()) { // See Bug 580139 - generalize to isExplicit
+				return true;
+			}
+		}
+		return false;
 	}
 
 	public boolean isQualifier() {
diff --git a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
index bd89f76..7484497 100644
--- a/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
+++ b/plugins/org.eclipse.ocl.pivot/src/org/eclipse/ocl/pivot/utilities/PivotUtil.java
@@ -116,6 +116,7 @@
 import org.eclipse.ocl.pivot.internal.manager.PivotExecutorManager;
 import org.eclipse.ocl.pivot.internal.resource.EnvironmentFactoryAdapter;
 import org.eclipse.ocl.pivot.internal.scoping.EnvironmentView;
+import org.eclipse.ocl.pivot.internal.scoping.EnvironmentView.DiagnosticWrappedException;
 import org.eclipse.ocl.pivot.internal.utilities.AS2Moniker;
 import org.eclipse.ocl.pivot.internal.utilities.EnvironmentFactoryInternal;
 import org.eclipse.ocl.pivot.internal.utilities.EnvironmentFactoryInternal.EnvironmentFactoryInternalExtension;
@@ -906,7 +907,7 @@
 				s.append(": ");
 			}
 			s.append(diagnostic.getMessage());
-			for (Object obj : diagnostic.getData()) {
+		/*	for (Object obj : diagnostic.getData()) {
 				s.append(newLine);
 				s.append("\t");
 				//				if (obj instanceof Throwable) {
@@ -915,10 +916,22 @@
 				//				else {
 				s.append(obj);
 				//				}
+			} */
+			List<?> datas = diagnostic.getData();
+			if (datas != null) {
+				for (Object data : datas) {
+					if (data instanceof Throwable)  {
+						Throwable cause = ((Throwable)data).getCause();
+						if ((cause != null) && (cause != data)) {
+							s.append(newLine + "\t" + cause.toString());
+						}
+					}
+				}
 			}
 			for (Diagnostic childDiagnostic : diagnostic.getChildren()) {
 				if (childDiagnostic != null) {
-					formatDiagnostic(s, childDiagnostic, newLine + "\t");
+					String childNewLine = newLine + "\t";
+					formatDiagnostic(s, childDiagnostic, childNewLine);
 				}
 			}
 		}
@@ -951,6 +964,12 @@
 				} catch (Exception e) {}	// UnsupportedOperationException was normal for Bug 380232 fixed in Xtext 2.9
 				s.append(": ");
 				s.append(diagnostic.getMessage());
+				if (diagnostic instanceof DiagnosticWrappedException)  {
+					Throwable cause = ((DiagnosticWrappedException)diagnostic).getCause();
+					if ((cause != null) && (cause != diagnostic)) {
+						s.append(" - " + cause.toString());
+					}
+				}
 			}
 		}
 		return s.toString();
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
index e420bd6..ac2decf 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/cs2as/CS2AS.java
@@ -277,6 +277,12 @@
 		}
 	}
 
+	public static @Nullable EClassifier getElementType(@NonNull PathNameCS pathNameCS) {
+		List<PathElementCS> path = pathNameCS.getOwnedPathElements();
+		int iSize = path.size();
+		return iSize > 0 ? path.get(iSize-1).getElementType() : null;
+	}
+
 	public static MessageBinder getMessageBinder() {
 		return messageBinder;
 	}
diff --git a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/scoping/BaseScopeView.java b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/scoping/BaseScopeView.java
index a0eca44..ab99901 100644
--- a/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/scoping/BaseScopeView.java
+++ b/plugins/org.eclipse.ocl.xtext.base/src/org/eclipse/ocl/xtext/base/scoping/BaseScopeView.java
@@ -146,7 +146,7 @@
 	protected final @NonNull ElementCS target;							// CS node in which a lookup is to be performed
 	protected final @Nullable ElementCS child;							// CS node from which a lookup is to be performed
 	protected final @NonNull EReference targetReference;				// The AST reference to the location at which the lookup is to be stored
-	protected final boolean isQualified;
+	protected final boolean isQualified;								// FIXME always false
 	private Attribution attribution = null;								// Lazily computed Attributes helper for the target CS node
 
 	private final @Nullable ParserContext parserContext;		// FIXME only non-null for API compatibility
diff --git a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
index 1432aba..25276dc 100644
--- a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
+++ b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/cs2as/EssentialOCLCSLeft2RightVisitor.java
@@ -520,6 +520,23 @@
 		return csRoot;
 	}
 
+	protected boolean isAssociationClassCallExp(@NonNull NameExpCS csNameExp) {		// See Bug 423905
+		List<SquareBracketedClauseCS> csSquareBracketedClauses = csNameExp.getOwnedSquareBracketedClauses();
+		if (csSquareBracketedClauses.size() == 0) {
+			return false;
+		}
+		if (csSquareBracketedClauses.size() == 1) {
+			List<ExpCS> csTerms = csSquareBracketedClauses.get(0).getOwnedTerms();
+			if (csTerms.size() == 1) {
+				ExpCS csTerm = csTerms.get(0);
+				if (csTerm instanceof NumberLiteralExpCS) {	// only numerics ambiguous * / .. are MultiplicityCS
+					return false;
+				}
+			}
+		}
+		return true;
+	}
+
 	protected boolean isInvalidType(@Nullable Type type) {
 		return (type == null) || (type instanceof InvalidType)
 				|| ((type instanceof CollectionType) && (((CollectionType)type).getElementType() instanceof InvalidType));
@@ -553,7 +570,7 @@
 		return callExp;
 	}
 
-	protected Element resolveAssociationClassCallExp(@NonNull NameExpCS csNameExp) {
+	protected Element resolveAssociationClassCallExp(@NonNull NameExpCS csNameExp) {			// See Bug 423905
 		//		PathNameCS pathName = csNameExp.getPathName();
 		RoundBracketedClauseCS csRoundBracketedClause = csNameExp.getOwnedRoundBracketedClause();
 		List<SquareBracketedClauseCS> csSquareBracketedClauses = csNameExp.getOwnedSquareBracketedClauses();
@@ -727,7 +744,7 @@
 			}
 			propertyScopeFilter = new PropertyScopeFilter(csSquareBracketedClauses);	// FIXME nonStatic
 		}
-		// FIXME Qualified navigation
+		// FIXME Qualified navigation See Bug 423905
 		Property resolvedProperty = context.lookupProperty(csNameExp, ownedPathName, propertyScopeFilter);
 		if ((resolvedProperty != null) && !resolvedProperty.eIsProxy()) {
 			if (resolvedProperty.getType() instanceof Stereotype) {			// FIXME Bug 578010 - M2 properties need reification with correct types at M1
@@ -1207,25 +1224,7 @@
 			else if (csArgument.getRole() == NavigationRole.EXPRESSION) {
 				ExpCS csName = csArgument.getOwnedNameExpression();
 				if (csName != null) {
-					OCLExpression arg = null;
-					boolean isType = false;
-					if (csName instanceof NameExpCS) {
-						if ((parameters != null) && argIndex < parameters.size()) {
-							Parameter parameter = parameters.get(argIndex);
-							if (parameter.isIsTypeof() || (parameter.getTypeId() == standardLibrary.getOclTypeType().getTypeId())) {
-								NameExpCS csNameExp = (NameExpCS)csName;
-								PathNameCS csPathName = csNameExp.getOwnedPathName();
-								Type type = context.getConverter().lookupType(csNameExp, ClassUtil.nonNullState(csPathName));
-								if (type != null) {
-									isType = true;
-									arg = resolveTypeExp(csNameExp, type);
-								}
-							}
-						}
-					}
-					if (!isType) {
-						arg = context.visitLeft2Right(OCLExpression.class, csName);
-					}
+					OCLExpression arg = context.visitLeft2Right(OCLExpression.class, csName);
 					if (arg != null) {
 						context.installPivotUsage(csArgument, arg);
 					}
@@ -2117,7 +2116,7 @@
 		if (csNameExp.getOwnedCurlyBracketedClause() != null) {
 			return resolveShadowExp(csNameExp);
 		}
-		else if (csNameExp.getOwnedSquareBracketedClauses().size() > 0) {
+		else if (isAssociationClassCallExp(csNameExp)) {
 			return resolveAssociationClassCallExp(csNameExp);
 		}
 		else if (csRoundBracketedClause != null) {
diff --git a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/scoping/EssentialOCLScoping.java b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/scoping/EssentialOCLScoping.java
index 18f3e35..8f55a25 100644
--- a/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/scoping/EssentialOCLScoping.java
+++ b/plugins/org.eclipse.ocl.xtext.essentialocl/src/org/eclipse/ocl/xtext/essentialocl/scoping/EssentialOCLScoping.java
@@ -122,11 +122,19 @@
 					}
 				}
 				else {
-					messageTemplate = /*csNameExp.getSourceTypeValue() != null ? PivotMessagesInternal.UnresolvedStaticProperty_ERROR_ :*/ PivotMessagesInternal.UnresolvedProperty_ERROR_;
+					EClassifier elementType = CS2AS.getElementType(pathName);
+					if (elementType == PivotPackage.Literals.PROPERTY) {
+						messageTemplate = /*csNameExp.getSourceTypeValue() != null ? PivotMessagesInternal.UnresolvedStaticProperty_ERROR_ :*/ PivotMessagesInternal.UnresolvedProperty_ERROR_;
+					}
+					else {
+						assert elementType == PivotPackage.Literals.ELEMENT;
+						messageTemplate = /*csNameExp.getSourceTypeValue() != null ? PivotMessagesInternal.UnresolvedStaticElement_ERROR_ :*/ PivotMessagesInternal.UnresolvedElement_ERROR_;
+					}
 				}
 				if (csNameExp.getSourceTypeValue() != null) {
 					sourceType = csNameExp.getSourceTypeValue();
 				}
+				linkText = pathName.toString();
 			}
 			else if (csContext instanceof TypeNameExpCS) {
 				messageTemplate = PivotMessagesInternal.UnresolvedType_ERROR_;
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/DelegatesTest.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/DelegatesTest.java
index a005369..b439e6f 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/DelegatesTest.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/DelegatesTest.java
@@ -576,7 +576,7 @@
 		//
 		delegate = factory.createQueryDelegate(companyClass, variables, badName);
 		executeWithException2(delegate, acme, null, getErrorsInMessage(PivotConstantsInternal.QUERY_ROLE, "company::Company", badName) +
-			StringUtil.bind("1:1: " + PivotMessagesInternal.UnresolvedProperty_ERROR_, "", badName));
+			StringUtil.bind("1:1: " + PivotMessagesInternal.UnresolvedElement_ERROR_, "", badName));
 		//
 		//	Definition of undeclared variable
 		//
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateConstructsTest4.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateConstructsTest4.java
index e42edbe..e8689fb 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateConstructsTest4.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateConstructsTest4.java
@@ -104,7 +104,7 @@
 		ocl.assertQueryEquals(null, 4/2+5*3, "4/2 + let a : Integer = 5 in a * 3");
 		ocl.assertQueryEquals(null, 4/2+3*5*7, "4/2 + (let a : Integer = 5 in 3 * (let b : Integer = 7 in a * b))");
 		ocl.assertSemanticErrorQuery(null, "4/2 + (let a : Integer = 5 in 3) * (let b : Integer = 7 in a * b)",
-			PivotMessagesInternal.UnresolvedProperty_ERROR_, "", "a");
+			PivotMessagesInternal.UnresolvedElement_ERROR_, "", "a");
 		ocl.assertQueryEquals(null, 4/2+3*5*7, "4/2 + let a : Integer = 5 in 3 * let b : Integer = 7 in a * b");
 		ocl.assertQueryEquals(null, (64.0 / 16) / (8 / 4), "(64 / 16) / (let b : Integer = 0 in 8 / (let c : Integer = 0 in 4 ))");
 		ocl.assertQueryEquals(null, (64.0 / 16) / (8 / 4), "64 / 16 / let b : Integer = 0 in 8 / let c : Integer = 0 in 4");
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateModelOperationsTest4.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateModelOperationsTest4.java
index 6096ae2..b144a41 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateModelOperationsTest4.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateModelOperationsTest4.java
@@ -389,7 +389,7 @@
 		OrderedSetValue kids1 = idResolver.createOrderedSetOfEach(TypeId.ORDERED_SET.getSpecializedId(children1Type.getTypeId()), children1);
 		OrderedSetValue kids2 = idResolver.createOrderedSetOfEach(TypeId.ORDERED_SET.getSpecializedId(children2Type.getTypeId()), children2);
 		//
-		ocl.assertSemanticErrorQuery(parentType, "parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, "", "parent");
+		ocl.assertSemanticErrorQuery(parentType, "parent", PivotMessagesInternal.UnresolvedElement_ERROR_, "", "parent");
 		ocl.assertSemanticErrorQuery(parentType, "self.parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, parentType, "parent");
 		ocl.assertQueryEquals(parent, parentType, "Parent");
 		ocl.assertSemanticErrorQuery(parentType, "self.Parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, parentType, "Parent");
@@ -410,7 +410,7 @@
 		ocl.assertQueryEquals(parent, children2Type, "Children2");
 		ocl.assertSemanticErrorQuery(parentType, "self.Children2", PivotMessagesInternal.UnresolvedProperty_ERROR_, parentType, "Children2");
 		//
-		ocl.assertSemanticErrorQuery(child1Type, "parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, "", "parent");
+		ocl.assertSemanticErrorQuery(child1Type, "parent", PivotMessagesInternal.UnresolvedElement_ERROR_, "", "parent");
 		ocl.assertQueryEquals(child2, parentType, "Parent");
 		ocl.assertSemanticErrorQuery(child1Type, "self.parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, child1Type, "parent");
 		ocl.assertQueryEquals(child1, parent, "self.Parent");
@@ -420,7 +420,7 @@
 		ocl.assertQueryEquals(child2, parent, "self.parent");
 		ocl.assertSemanticErrorQuery(child2Type, "self.Parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, child2Type, "Parent");
 		//
-		ocl.assertSemanticErrorQuery(children1Type, "parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, "", "parent");
+		ocl.assertSemanticErrorQuery(children1Type, "parent", PivotMessagesInternal.UnresolvedElement_ERROR_, "", "parent");
 		ocl.assertQueryEquals(children1, parentType, "Parent");
 		ocl.assertSemanticErrorQuery(children1Type, "self.parent", PivotMessagesInternal.UnresolvedProperty_ERROR_, children1Type, "parent");
 		ocl.assertQueryEquals(children1, parent, "self.Parent");
diff --git a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateUMLTest4.java b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateUMLTest4.java
index c2e7e6b..dbd9956 100644
--- a/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateUMLTest4.java
+++ b/tests/org.eclipse.ocl.examples.xtext.tests/src/org/eclipse/ocl/examples/pivot/tests/EvaluateUMLTest4.java
@@ -37,6 +37,7 @@
 import org.eclipse.ocl.pivot.ids.TypeId;
 import org.eclipse.ocl.pivot.internal.manager.MetamodelManagerInternal;
 import org.eclipse.ocl.pivot.internal.messages.PivotMessagesInternal;
+import org.eclipse.ocl.pivot.internal.utilities.EnvironmentFactoryInternal.EnvironmentFactoryInternalExtension;
 import org.eclipse.ocl.pivot.resource.ProjectManager;
 import org.eclipse.ocl.pivot.uml.UMLStandaloneSetup;
 import org.eclipse.ocl.pivot.uml.internal.es2as.UML2AS;
@@ -192,7 +193,7 @@
 		EObject context = ocl.statefulEFactory.create(ocl.c1Class);
 		org.eclipse.ocl.pivot.Class contextType = metamodelManager.getASOfEcore(org.eclipse.ocl.pivot.Class.class, ocl.c1Class);
 		assert contextType != null;
-		ocl.assertSemanticErrorQuery(contextType, "self.oclIsInState(S2b)", PivotMessagesInternal.UnresolvedProperty_ERROR_, "Model::C1", "S2b");
+		ocl.assertSemanticErrorQuery(contextType, "self.oclIsInState(S2b)", PivotMessagesInternal.UnresolvedElement_ERROR_, "Model::C1", "S2b");
 		ocl.assertQueryInvalid(context, "self.oclIsInState(S1a)", StringUtil.bind(PivotMessagesInternal.FailedToEvaluate_ERROR_, "OclAny::oclIsInState(OclState[?]) : Boolean[1]", "C1", "self.oclIsInState(S1a)"), UnsupportedOperationException.class);
 		ocl.dispose();
 	}
@@ -286,6 +287,39 @@
 	}
 
 	/**
+	 * Tests uses of allInstances on a stereotype
+	 */
+	@Test public void test_type_literals_Bug580140() throws Exception {
+		UMLStandaloneSetup.init();
+		MyOCL ocl = createOCLWithProjectMap();
+		EObject umlTrain = doLoadUML(ocl, getTestModelURI("models/uml/Bug485225.uml"), "_zKtRgLUyEeWSV7DXeOPrdA"); //RootElement.Train1");
+		assert umlTrain != null;
+		org.eclipse.ocl.pivot.Class asTrain = ((EnvironmentFactoryInternalExtension)ocl.getEnvironmentFactory()).getASOf(org.eclipse.ocl.pivot.Class.class, umlTrain);
+		assert asTrain != null;
+		//
+		ocl.assertValidQuery(asTrain, "self.oclIsKindOf(Train1)");
+		ocl.assertValidQuery(asTrain, "self.oclIsKindOf(Train2)");
+		ocl.assertValidQuery(asTrain, "self.oclIsKindOf(RootElement::Train1)");		// Correct Class => true
+		ocl.assertValidQuery(asTrain, "self.oclIsKindOf(RootElement::Train2)");		// Sibling class => false
+		ocl.assertValidQuery(asTrain, "self.oclIsKindOf(TestProfile::Train)");		// Stereotype metaclass => false
+		ocl.assertSemanticErrorQuery(asTrain, "self.oclIsKindOf(Train)", PivotMessagesInternal.UnresolvedElement_ERROR_, "RootElement::Train1", "Train");
+		ocl.assertSemanticErrorQuery(asTrain, "self.oclIsKindOf(RootElement::Train)", PivotMessagesInternal.UnresolvedElement_ERROR_, "RootElement::Train1", "RootElement::Train");
+		//
+		ocl.assertValidQuery(asTrain, "let t = Train1 in self.oclIsKindOf(t)");
+		ocl.assertValidQuery(asTrain, "let t = Train2 in self.oclIsKindOf(t)");
+		ocl.assertValidQuery(asTrain, "let t = RootElement::Train1 in self.oclIsKindOf(t)");
+		ocl.assertValidQuery(asTrain, "let t = RootElement::Train2 in self.oclIsKindOf(t)");
+		ocl.assertValidQuery(asTrain, "let t = TestProfile::Train in self.oclIsKindOf(t)");
+		ocl.assertSemanticErrorQuery(asTrain, "let t = Train in self.oclIsKindOf(t)", PivotMessagesInternal.UnresolvedElement_ERROR_, "", "Train");
+		ocl.assertSemanticErrorQuery(asTrain, "let t = RootElement::Train in self.oclIsKindOf(t)", PivotMessagesInternal.UnresolvedElement_ERROR_, "", "RootElement::Train");
+		//
+		//	aTrain = ... no Ecore instance available
+		//	ocl.assertQueryEquals(aTrain, false, "let t = TestProfile::Train in self.oclIsKindOf(t)");
+		//	ocl.assertQueryEquals(aTrain, false, "self.oclIsKindOf(TestProfile::Train)");
+		ocl.dispose();
+	}
+
+	/**
 	 * Tests uses of allInstances on a signal
 	 */
 	@Test public void test_signal_allinstances_Bug496210() throws Exception {