diff options
Diffstat (limited to 'plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.xpand/src/org/eclipse/papyrus/gmf/internal/xpand/model/Scope.java')
-rw-r--r-- | plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.xpand/src/org/eclipse/papyrus/gmf/internal/xpand/model/Scope.java | 179 |
1 files changed, 0 insertions, 179 deletions
diff --git a/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.xpand/src/org/eclipse/papyrus/gmf/internal/xpand/model/Scope.java b/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.xpand/src/org/eclipse/papyrus/gmf/internal/xpand/model/Scope.java deleted file mode 100644 index bdf2c05cf1b..00000000000 --- a/plugins/toolsmiths/gmf-tooling/org.eclipse.papyrus.gmf.xpand/src/org/eclipse/papyrus/gmf/internal/xpand/model/Scope.java +++ /dev/null @@ -1,179 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2008, 2020 Borland Software Corporation, CEA LIST, Artal - * - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Artem Tikhomirov (Borland) - initial API and implementation - * Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174 - *****************************************************************************/ -package org.eclipse.papyrus.gmf.internal.xpand.model; - -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; - -import org.eclipse.emf.ecore.EPackage; -import org.eclipse.emf.ecore.EcorePackage; -import org.eclipse.emf.ecore.impl.EPackageRegistryImpl; -import org.eclipse.m2m.internal.qvt.oml.evaluator.ImportToNonTransformCtxHelper; -import org.eclipse.papyrus.gmf.internal.xpand.Activator; -import org.eclipse.papyrus.gmf.internal.xpand.ResourceManager; -import org.eclipse.papyrus.gmf.internal.xpand.eval.EvaluationListener; -import org.eclipse.papyrus.gmf.internal.xpand.util.TypeNameUtil; -import org.eclipse.papyrus.gmf.internal.xpand.xtend.ast.QvtResource; - -/** - * @author artem - */ -public class Scope { - - private final Map<String, Variable> globalVars = new HashMap<String, Variable> (); - - private final ResourceManager resourceManager; - - private final Output output; - - private final List<XpandAdvice> registeredAdvices = new LinkedList<XpandAdvice>(); - - private EvaluationListener evaluationListener; - - public Scope(ResourceManager resourceManager, Collection<Variable> globalVars, Output output) { - assert resourceManager != null; - // FIXME output != null is only important for evaluation cases, for analyze, null is perfectly ok - // assert output != null; - this.resourceManager = resourceManager; - this.output = output; - if (globalVars != null) { - for (Variable v : globalVars) { - this.globalVars.put(v.getName(), v); - } - } - } - - // FIXME next two are for tests - protected Scope() { - resourceManager = null; - output = null; - } - - protected Scope(Output out) { - resourceManager = null; - output = out; - } - - // [artem] if not null, should be notified about entering/leaving xpand ast elements - public EvaluationListener getEvaluationListener() { - return evaluationListener; - } - - public void setEvaluationListener(EvaluationListener listener) { - this.evaluationListener = listener; - } - - public Variable getGlobalVariable(String name) { - return globalVars.get(name); - } - - public Collection<String> getGlobalVarNames() { - return globalVars.keySet(); - } - - // never null - private ResourceManager getResourceManager() { - return resourceManager; - } - - // never null - public Output getOutput() { - return output; - } - - public List<XpandAdvice> getAdvices() { - return registeredAdvices; - } - - public void registerAdvices(final String fullyQualifiedName) { - final XpandResource tpl = findTemplate(fullyQualifiedName); - if (tpl == null) { - throw new RuntimeException("Couldn't find template : " + fullyQualifiedName); - } - final XpandAdvice[] as = tpl.getAdvices(); - for (final XpandAdvice advice : as) { - if (registeredAdvices.contains(advice)) { - Activator.logWarn("advice " + advice.toString() + " allready registered!"); - } else { - registeredAdvices.add(advice); - } - } - } - - public XpandResource findTemplate(String templateName, String contextTemplate) { - assert templateName != null; - assert contextTemplate != null; - if (getResourceManager() == null) { - // HACK for tests - // FIXME once dealt with Scope with null rm, should remove this. (fix tests to use RM) - return null; - } - String[] possibleNames; - if (!TypeNameUtil.isQualifiedName(contextTemplate)) { - possibleNames = new String[] { templateName }; - } else { - String contextNS = TypeNameUtil.withoutLastSegment(contextTemplate); - possibleNames = new String[] { templateName, contextNS + TypeNameUtil.NS_DELIM + templateName }; - } - for (String name : possibleNames) { - final XpandResource tpl = findTemplate(name); - if (tpl != null) { - return tpl; - } - } - return null; - } - - public XpandResource findTemplate(String templateName) { - XpandResource resource = getResourceManager().loadXpandResource(templateName); - if (resource instanceof StatefulResource && !((StatefulResource) resource).isInitialized()) { - ((StatefulResource) resource).initialize(this); - } - return resource; - } - - public QvtResource findExtension(String extensionName) { - return getResourceManager().loadQvtResource(extensionName); - } - - public EPackage.Registry createPackageRegistry(String[] metamodelURIs) { - assert metamodelURIs != null; - // TODO respect meta-models imported not only with nsURI - EPackage.Registry result = new EPackageRegistryImpl(); - for (String namespace : metamodelURIs) { - EPackage pkg = Activator.findMetaModel(namespace); - if (pkg != null) { - result.put(namespace, pkg); - } - } - if (result.isEmpty()) { - // hack for tests - result.put(EcorePackage.eNS_URI, EcorePackage.eINSTANCE); - } - return result; - } - - private ImportToNonTransformCtxHelper modulesImportHelper; - /*package-local*/ ImportToNonTransformCtxHelper getImportsHelper() { - if (modulesImportHelper == null) { - modulesImportHelper = new ImportToNonTransformCtxHelper(); - } - return modulesImportHelper; - } - -} |