瀏覽代碼

Merge pull request #981 from Yakindu/issue_invalid_inference_result

inference result may be null for invalid types
Andreas Mülder 9 年之前
父節點
當前提交
e9a3c18a71

+ 4 - 0
plugins/org.yakindu.base.types/src/org/yakindu/base/types/inferrer/ITypeSystemInferrer.java

@@ -13,6 +13,7 @@ package org.yakindu.base.types.inferrer;
 import java.util.ArrayList;
 import java.util.List;
 
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.emf.ecore.EObject;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.validation.IValidationIssueAcceptor;
@@ -36,10 +37,13 @@ public interface ITypeSystemInferrer {
 		private List<InferenceResult> bindings = new ArrayList<>();
 
 		protected InferenceResult(Type type) {
+			Assert.isNotNull(type);
 			this.type = type;
 		}
 
 		protected InferenceResult(Type type, List<InferenceResult> bindings) {
+			Assert.isNotNull(type);
+			Assert.isNotNull(bindings);
 			this.type = type;
 			this.bindings.addAll(bindings);
 		}

+ 4 - 2
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/scoping/STextScopeProvider.java

@@ -34,6 +34,7 @@ import org.yakindu.base.types.ComplexType;
 import org.yakindu.base.types.EnumerationType;
 import org.yakindu.base.types.Type;
 import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
+import org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult;
 import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
 import org.yakindu.sct.model.sgraph.Scope;
@@ -133,12 +134,13 @@ public class STextScopeProvider extends AbstractDeclarativeScopeProvider {
 		}
 
 		IScope scope = IScope.NULLSCOPE;
-		Type ownerType = typeInferrer.infer(owner).getType();
+		InferenceResult result = typeInferrer.infer(owner);
+		Type ownerType = result != null ? result.getType() : null;
 
 		if (element instanceof Scope) {
 			scope = Scopes.scopeFor(((Scope) element).getDeclarations());
 			return new FilteringScope(scope, predicate);
-		}else{
+		}else if(ownerType != null){
 			scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
 			scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType),scope);
 		}

+ 4 - 1
test-plugins/org.yakindu.sct.model.stext.test/src/org/yakindu/sct/model/stext/test/util/AbstractTypeInferrerTest.java

@@ -58,7 +58,10 @@ public abstract class AbstractTypeInferrerTest extends AbstractSTextTest {
 
 	@Deprecated
 	protected Type inferType(String expression, String parserRule, String scopes) {
-		return inferTypeResult(expression, parserRule, scopes).getType();
+ 		InferenceResult inferTypeResult = inferTypeResult(expression, parserRule, scopes);
+		if(inferTypeResult == null)
+			return null;
+		return inferTypeResult.getType();
 	}
 	
 	protected InferenceResult inferTypeResult(String expression, String parserRule, String scopes) {