Pārlūkot izejas kodu

Remove ISCTExtension (#2110)

Removed the Interface ISCTExtension, because its obsolete and the class
STextExtensions alone is enough. Therefore replaced the injections of
the interface with the injections of the classes.
Despite this, the method "getScopeElement" was extracted from the
STextExtensions to the STextScopeProvider because this was the only
place where the methods was used. Also a getStatechart wrapper method
was recreated in the STextScopeProvider, so that this method can be
overridden in the SCTUnitScopeProvider.

This fixes #2110
jthoene 7 gadi atpakaļ
vecāks
revīzija
e67cf5b75a

+ 0 - 6
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/STextRuntimeModule.java

@@ -25,8 +25,6 @@ import org.yakindu.base.types.inferrer.ITypeSystemInferrer;
 import org.yakindu.base.types.typesystem.GenericTypeSystem;
 import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.model.sgraph.resource.SCTLinker;
-import org.yakindu.sct.model.stext.extensions.ISCTExtensions;
-import org.yakindu.sct.model.stext.extensions.STextExtensions;
 import org.yakindu.sct.model.stext.inferrer.STextTypeInferrer;
 import org.yakindu.sct.model.stext.naming.StextNameProvider;
 import org.yakindu.sct.model.stext.resource.SCTResourceDescriptionStrategy;
@@ -107,10 +105,6 @@ public class STextRuntimeModule extends org.yakindu.sct.model.stext.AbstractSTex
 	public Class<? extends ITypeSystemInferrer> bindITypeSystemInferrer() {
 		return STextTypeInferrer.class;
 	}
-	
-	public Class<? extends ISCTExtensions> bindISCTExtensions() {
-		return STextExtensions.class;
-	}
 
 	@Override
 	public Class<? extends ITransientValueService> bindITransientValueService() {

+ 0 - 34
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/extensions/ISCTExtensions.java

@@ -1,34 +0,0 @@
-/**
- * Copyright (c) 2018 committers of YAKINDU 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:
- *     committers of YAKINDU - initial API and implementation
- */
-package org.yakindu.sct.model.stext.extensions;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.yakindu.sct.model.sgraph.ScopedElement;
-import org.yakindu.sct.model.sgraph.SpecificationElement;
-import org.yakindu.sct.model.sgraph.Statechart;
-
-import com.google.inject.ImplementedBy;
-
-/**
- * @author jonathan thoene - Initial contribution and API
- * 
- */
-@ImplementedBy(STextExtensions.class)
-public interface ISCTExtensions {
-	public SpecificationElement getContextElement(EObject context);
-	
-	public ScopedElement getScopedElement(EObject context);
-	
-	public Statechart getStatechart(EObject context);
-	
-	public Statechart getStatechart(final Resource context);
-}

+ 2 - 12
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/extensions/STextExtensions.java

@@ -15,18 +15,16 @@ import org.eclipse.emf.ecore.resource.Resource;
 import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.xtext.EcoreUtil2;
 import org.yakindu.sct.model.sgraph.SGraphPackage;
-import org.yakindu.sct.model.sgraph.ScopedElement;
 import org.yakindu.sct.model.sgraph.SpecificationElement;
 import org.yakindu.sct.model.sgraph.Statechart;
 import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
-import org.yakindu.sct.model.stext.stext.StatechartSpecification;
 
 /**
  * @author jonathan thoene - Initial contribution and API
  * 
  */
 
-public class STextExtensions implements ISCTExtensions{
+public class STextExtensions {
 	public SpecificationElement getContextElement(EObject context) {
 		final ContextElementAdapter provider = getContextElementAdapter(context.eResource());
 
@@ -36,13 +34,6 @@ public class STextExtensions implements ISCTExtensions{
 			return (SpecificationElement) provider.getElement();
 		}
 	}
-	
-	public ScopedElement getScopedElement(EObject context) {
-		ScopedElement scopedElement = EcoreUtil2.getContainerOfType(context, ScopedElement.class);
-		if (EcoreUtil.getRootContainer(context) instanceof StatechartSpecification && scopedElement != null)
-			return scopedElement;
-		return getStatechart(context);
-	}
 
 	public Statechart getStatechart(EObject context) {
 		final ContextElementAdapter provider = getContextElementAdapter(context.eResource());
@@ -68,7 +59,6 @@ public class STextExtensions implements ISCTExtensions{
 	}
 
 	protected ContextElementAdapter getContextElementAdapter(Resource context) {
-		return (ContextElementAdapter) EcoreUtil.getExistingAdapter(context,
-				ContextElementAdapter.class);
+		return (ContextElementAdapter) EcoreUtil.getExistingAdapter(context, ContextElementAdapter.class);
 	}
 }

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

@@ -43,7 +43,7 @@ import org.yakindu.base.types.resource.TypedResourceDescriptionStrategy;
 import org.yakindu.base.types.typesystem.ITypeSystem;
 import org.yakindu.sct.domain.extension.DomainRegistry;
 import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.model.stext.extensions.ISCTExtensions;
+import org.yakindu.sct.model.stext.extensions.STextExtensions;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport;
 import org.yakindu.sct.model.stext.stext.ImportScope;
 import org.yakindu.sct.model.stext.stext.StatechartSpecification;
@@ -77,7 +77,7 @@ public class STextGlobalScopeProvider extends ImportUriGlobalScopeProvider {
 	@Inject
 	private ImportedResourceCache resourceDescriptionCache;
 	@Inject
-	private ISCTExtensions utils;
+	private STextExtensions utils;
 
 	public void setCache(IResourceScopeCache cache) {
 		this.cache = cache;

+ 18 - 6
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/scoping/STextScopeProvider.java

@@ -16,6 +16,7 @@ import java.util.List;
 import org.eclipse.emf.common.util.EList;
 import org.eclipse.emf.ecore.EObject;
 import org.eclipse.emf.ecore.EReference;
+import org.eclipse.emf.ecore.util.EcoreUtil;
 import org.eclipse.xtext.EcoreUtil2;
 import org.eclipse.xtext.naming.IQualifiedNameProvider;
 import org.eclipse.xtext.naming.QualifiedName;
@@ -43,10 +44,11 @@ import org.yakindu.sct.model.sgraph.ScopedElement;
 import org.yakindu.sct.model.sgraph.SpecificationElement;
 import org.yakindu.sct.model.sgraph.State;
 import org.yakindu.sct.model.sgraph.Statechart;
-import org.yakindu.sct.model.stext.extensions.ISCTExtensions;
+import org.yakindu.sct.model.stext.extensions.STextExtensions;
 import org.yakindu.sct.model.stext.scoping.ContextPredicateProvider.EmptyPredicate;
 import org.yakindu.sct.model.stext.stext.InterfaceScope;
 import org.yakindu.sct.model.stext.stext.InternalScope;
+import org.yakindu.sct.model.stext.stext.StatechartSpecification;
 
 import com.google.common.base.Predicate;
 import com.google.common.collect.Lists;
@@ -71,10 +73,10 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	private ContextPredicateProvider predicateProvider;
 	
 	@Inject
-	protected ISCTExtensions utils;
+	protected STextExtensions utils;
 
 	public IScope scope_ActiveStateReferenceExpression_value(EObject context, EReference reference) {
-		Statechart statechart = utils.getStatechart(context);
+		Statechart statechart = getStatechart(context);
 		if (statechart == null)
 			return IScope.NULLSCOPE;
 		List<State> allStates = EcoreUtil2.getAllContentsOfType(statechart, State.class);
@@ -187,7 +189,7 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	 */
 	protected IScope getNamedTopLevelScope(final EObject context, EReference reference) {
 		List<EObject> scopeCandidates = Lists.newArrayList();
-		ScopedElement scopedElement = utils.getScopedElement(context);
+		ScopedElement scopedElement = getScopedElement(context);
 		if (scopedElement == null)
 			return IScope.NULLSCOPE;
 		EList<Scope> scopes = scopedElement.getScopes();
@@ -207,7 +209,7 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 	 */
 	protected IScope getUnnamedTopLevelScope(final EObject context, EReference reference) {
 		List<EObject> scopeCandidates = Lists.newArrayList();
-		ScopedElement scopedElement = utils.getScopedElement(context);
+		ScopedElement scopedElement = getScopedElement(context);
 		if (scopedElement == null)
 			return IScope.NULLSCOPE;
 		EList<Scope> scopes = scopedElement.getScopes();
@@ -226,6 +228,16 @@ public class STextScopeProvider extends ExpressionsScopeProvider {
 		IScope scope = getDelegate().getScope(context, reference);
 		return Scopes.scopeFor(scopeCandidates, scope);
 	}
-
+	
+	protected ScopedElement getScopedElement(EObject context) {
+		ScopedElement scopedElement = EcoreUtil2.getContainerOfType(context, ScopedElement.class);
+		if (EcoreUtil.getRootContainer(context) instanceof StatechartSpecification && scopedElement != null)
+			return scopedElement;
+		return getStatechart(context);
+	}
+	
+	protected Statechart getStatechart(EObject context) {
+		return utils.getStatechart(context);
+	}
 
 }

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

@@ -21,7 +21,7 @@ import org.eclipse.xtext.scoping.impl.ImportNormalizer;
 import org.eclipse.xtext.scoping.impl.ImportedNamespaceAwareLocalScopeProvider;
 import org.yakindu.base.types.Package;
 import org.yakindu.sct.model.sgraph.Scope;
-import org.yakindu.sct.model.stext.extensions.ISCTExtensions;
+import org.yakindu.sct.model.stext.extensions.STextExtensions;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport;
 import org.yakindu.sct.model.stext.stext.ImportScope;
 import org.yakindu.sct.model.stext.stext.StateSpecification;
@@ -40,7 +40,7 @@ public class StextImportAwareScopeProvider extends ImportedNamespaceAwareLocalSc
 	@Inject
 	private IPackageImport2URIMapper mapper;
 
-	@Inject ISCTExtensions utils;
+	@Inject STextExtensions utils;
 	
 	@Override
 	public IScope getScope(EObject context, EReference reference) {

+ 2 - 2
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/validation/STextJavaValidator.java

@@ -79,7 +79,7 @@ import org.yakindu.sct.model.sgraph.Vertex;
 import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource;
 import org.yakindu.sct.model.sgraph.util.ContextElementAdapter;
 import org.yakindu.sct.model.sgraph.validation.SGraphJavaValidator;
-import org.yakindu.sct.model.stext.extensions.ISCTExtensions;
+import org.yakindu.sct.model.stext.extensions.STextExtensions;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper;
 import org.yakindu.sct.model.stext.scoping.IPackageImport2URIMapper.PackageImport;
 import org.yakindu.sct.model.stext.services.STextGrammarAccess;
@@ -139,7 +139,7 @@ public class STextJavaValidator extends AbstractSTextJavaValidator implements ST
 	@Inject(optional = true)
 	private IPackageImport2URIMapper mapper;
 	@Inject
-	protected ISCTExtensions utils;
+	protected STextExtensions utils;
 
 	@Check(CheckType.FAST)
 	public void checkExpression(VariableDefinition expression) {