Browse Source

#162 : open ImportResolver API to get the possibility to reduce EFS
dependencies

Johannes Dicks 9 years ago
parent
commit
48884235b3

+ 0 - 36
plugins/org.yakindu.base.expressions/.launch/Launch Runtime Eclipse.launch

@@ -1,36 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<launchConfiguration type="org.eclipse.pde.ui.RuntimeWorkbench">
-<booleanAttribute key="append.args" value="true"/>
-<booleanAttribute key="askclear" value="true"/>
-<booleanAttribute key="automaticAdd" value="true"/>
-<booleanAttribute key="automaticValidate" value="false"/>
-<stringAttribute key="bad_container_name" value="/org.yakindu.base.expressions/.launch/"/>
-<stringAttribute key="bootstrap" value=""/>
-<stringAttribute key="checked" value="[NONE]"/>
-<booleanAttribute key="clearConfig" value="false"/>
-<booleanAttribute key="clearws" value="false"/>
-<booleanAttribute key="clearwslog" value="false"/>
-<stringAttribute key="configLocation" value="${workspace_loc}/.metadata/.plugins/org.eclipse.pde.core/Launch Runtime Eclipse"/>
-<booleanAttribute key="default" value="true"/>
-<booleanAttribute key="includeOptional" value="true"/>
-<stringAttribute key="location" value="${workspace_loc}/../runtime-EclipseXtext"/>
-<listAttribute key="org.eclipse.debug.ui.favoriteGroups">
-<listEntry value="org.eclipse.debug.ui.launchGroup.debug"/>
-<listEntry value="org.eclipse.debug.ui.launchGroup.run"/>
-</listAttribute>
-<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/>
-<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}"/>
-<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
-<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xms40m -Xmx512m -XX:MaxPermSize=256m &#13;&#10;-Dorg.eclipse.epp.internal.mpc.core.service.DefaultCatalogService.url=http://localhost:8080"/>
-<stringAttribute key="pde.version" value="3.3"/>
-<stringAttribute key="product" value="org.eclipse.platform.ide"/>
-<booleanAttribute key="show_selected_only" value="false"/>
-<stringAttribute key="templateConfig" value="${target_home}/configuration/config.ini"/>
-<booleanAttribute key="tracing" value="false"/>
-<booleanAttribute key="useCustomFeatures" value="false"/>
-<booleanAttribute key="useDefaultConfig" value="true"/>
-<booleanAttribute key="useDefaultConfigArea" value="true"/>
-<booleanAttribute key="useProduct" value="true"/>
-<booleanAttribute key="usefeatures" value="false"/>
-</launchConfiguration>

+ 136 - 136
plugins/org.yakindu.sct.model.stext/src/org/yakindu/sct/model/stext/util/ImportResolver.java

@@ -1,136 +1,136 @@
-/**
- * Copyright (c) 2014 itemis AG 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:
- * 	itemis AG - initial API and implementation
- *  
- */
-package org.yakindu.sct.model.stext.util;
-
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.IResourceVisitor;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.emf.common.util.TreeIterator;
-import org.eclipse.emf.common.util.URI;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
-import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
-import org.eclipse.xtext.resource.IContainer;
-import org.eclipse.xtext.resource.IEObjectDescription;
-import org.eclipse.xtext.resource.IResourceDescription;
-import org.eclipse.xtext.resource.IResourceDescriptions;
-import org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions;
-import org.yakindu.base.types.Package;
-import org.yakindu.base.types.TypesPackage;
-import org.yakindu.sct.model.stext.stext.Import;
-
-import com.google.common.collect.Lists;
-import com.google.inject.Inject;
-
-/**
- * Convenience class for retrieving imported elements in the statechart's import scope.
- * 
- * @author Thomas Kutz
- *
- */
-public class ImportResolver {
-
-	@Inject
-	private IContainer.Manager containerManager;
-	@Inject
-	private IResourceDescriptions resourceDescriptions;
-
-	/**
-	 * Returns for a given {@link Import} declaration all elements of given type that are defined in the imported {@link Package}.
-	 * 
-	 * @param importDeclaration the import declaration within an import scope
-	 * @param type type of imported elements to be returned
-	 * @return imported elements of given type
-	 */
-	public <T extends EObject> List<T> getImportedElementsOfType(Import importDeclaration, Class<T> type) {
-		List<T> varDefs = Lists.newArrayList();
-		Package importedPackage = getPackageForNamespace(importDeclaration.eResource(), importDeclaration.getImportedNamespace());
-		if (importedPackage != null) {
-			TreeIterator<EObject> iter = importedPackage.eAllContents();
-			while (iter.hasNext()) {
-				EObject next = iter.next();
-				if (type.isInstance(next)) {
-					varDefs.add(type.cast(next));
-				}
-			}
-		}
-		return varDefs;
-	}
-
-	/**
-	 * Returns for a given namespace the {@link Package}.
-	 * 
-	 * @param contextResource the resource used to decide which packages are visible
-	 * @param namespace name of the package to be returned; ending wildcards (.*) will be trimmed
-	 * @return first found package with name as defined in namespace
-	 */
-	public Package getPackageForNamespace(Resource contextResource, String namespace) {
-		initResourceDescriptions(contextResource);
-		// remove wildcard
-		if (namespace.endsWith(".*")) {
-			namespace = namespace.substring(0, namespace.length() - 2);
-		}
-		URI uri = contextResource.getURI();
-		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
-		if (resourceDescription == null) {
-			// no resource description could be found, so package cannot be resolved anyway
-			return null;
-		}
-		for (IContainer container : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
-			final Iterable<IResourceDescription> currentDescriptions = container.getResourceDescriptions();
-			for (IResourceDescription resDesc : currentDescriptions) {
-				Iterable<IEObjectDescription> visiblePackages = resDesc
-						.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
-				for (IEObjectDescription pkgDesc : visiblePackages) {
-					if (pkgDesc.getName().toString().equals(namespace)) {
-						return (Package) pkgDesc.getEObjectOrProxy();
-					}
-				}
-			}
-		}
-		return null;
-	}
-
-	private void initResourceDescriptions(Resource contextResource) {
-		if (resourceDescriptions instanceof ResourceSetBasedResourceDescriptions) {
-			ResourceSet rset = buildResourceSet(contextResource);
-			((ResourceSetBasedResourceDescriptions) resourceDescriptions).setContext(rset);
-		}
-	}
-
-	private ResourceSet buildResourceSet(Resource contextResource) {
-		final ResourceSet rset = new ResourceSetImpl();
-		IProject project = WorkspaceSynchronizer.getFile(contextResource).getProject();
-		try {
-			project.accept(new IResourceVisitor() {
-				public boolean visit(IResource resource) throws CoreException {
-					if ("types".equals(resource.getFileExtension())) {
-						String filePath = resource.getFullPath().toString();
-						rset.createResource(URI.createPlatformResourceURI(filePath, true));
-					}
-					return true;
-				}
-			});
-
-		} catch (CoreException e) {
-			e.printStackTrace();
-		}
-		rset.getResources().add(contextResource);
-
-		return rset;
-	}
-}
+/**
+ * Copyright (c) 2014 itemis AG 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:
+ * 	itemis AG - initial API and implementation
+ *  
+ */
+package org.yakindu.sct.model.stext.util;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IResourceVisitor;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.emf.common.util.TreeIterator;
+import org.eclipse.emf.common.util.URI;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
+import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
+import org.eclipse.xtext.resource.IContainer;
+import org.eclipse.xtext.resource.IEObjectDescription;
+import org.eclipse.xtext.resource.IResourceDescription;
+import org.eclipse.xtext.resource.IResourceDescriptions;
+import org.eclipse.xtext.resource.impl.ResourceSetBasedResourceDescriptions;
+import org.yakindu.base.types.Package;
+import org.yakindu.base.types.TypesPackage;
+import org.yakindu.sct.model.stext.stext.Import;
+
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+
+/**
+ * Convenience class for retrieving imported elements in the statechart's import scope.
+ * 
+ * @author Thomas Kutz
+ *
+ */
+public class ImportResolver {
+
+	@Inject
+	private IContainer.Manager containerManager;
+	@Inject
+	private IResourceDescriptions resourceDescriptions;
+
+	/**
+	 * Returns for a given {@link Import} declaration all elements of given type that are defined in the imported {@link Package}.
+	 * 
+	 * @param importDeclaration the import declaration within an import scope
+	 * @param type type of imported elements to be returned
+	 * @return imported elements of given type
+	 */
+	public <T extends EObject> List<T> getImportedElementsOfType(Import importDeclaration, Class<T> type) {
+		List<T> varDefs = Lists.newArrayList();
+		Package importedPackage = getPackageForNamespace(importDeclaration.eResource(), importDeclaration.getImportedNamespace());
+		if (importedPackage != null) {
+			TreeIterator<EObject> iter = importedPackage.eAllContents();
+			while (iter.hasNext()) {
+				EObject next = iter.next();
+				if (type.isInstance(next)) {
+					varDefs.add(type.cast(next));
+				}
+			}
+		}
+		return varDefs;
+	}
+
+	/**
+	 * Returns for a given namespace the {@link Package}.
+	 * 
+	 * @param contextResource the resource used to decide which packages are visible
+	 * @param namespace name of the package to be returned; ending wildcards (.*) will be trimmed
+	 * @return first found package with name as defined in namespace
+	 */
+	public Package getPackageForNamespace(Resource contextResource, String namespace) {
+		initResourceDescriptions(contextResource);
+		// remove wildcard
+		if (namespace.endsWith(".*")) {
+			namespace = namespace.substring(0, namespace.length() - 2);
+		}
+		URI uri = contextResource.getURI();
+		IResourceDescription resourceDescription = resourceDescriptions.getResourceDescription(uri);
+		if (resourceDescription == null) {
+			// no resource description could be found, so package cannot be resolved anyway
+			return null;
+		}
+		for (IContainer container : containerManager.getVisibleContainers(resourceDescription, resourceDescriptions)) {
+			final Iterable<IResourceDescription> currentDescriptions = container.getResourceDescriptions();
+			for (IResourceDescription resDesc : currentDescriptions) {
+				Iterable<IEObjectDescription> visiblePackages = resDesc
+						.getExportedObjectsByType(TypesPackage.Literals.PACKAGE);
+				for (IEObjectDescription pkgDesc : visiblePackages) {
+					if (pkgDesc.getName().toString().equals(namespace)) {
+						return (Package) pkgDesc.getEObjectOrProxy();
+					}
+				}
+			}
+		}
+		return null;
+	}
+
+	private void initResourceDescriptions(Resource contextResource) {
+		if (resourceDescriptions instanceof ResourceSetBasedResourceDescriptions) {
+			ResourceSet rset = buildResourceSet(contextResource);
+			((ResourceSetBasedResourceDescriptions) resourceDescriptions).setContext(rset);
+		}
+	}
+
+	protected ResourceSet buildResourceSet(Resource contextResource) {
+		final ResourceSet rset = new ResourceSetImpl();
+		IProject project = WorkspaceSynchronizer.getFile(contextResource).getProject();
+		try {
+			project.accept(new IResourceVisitor() {
+				public boolean visit(IResource resource) throws CoreException {
+					if ("types".equals(resource.getFileExtension())) {
+						String filePath = resource.getFullPath().toString();
+						rset.createResource(URI.createPlatformResourceURI(filePath, true));
+					}
+					return true;
+				}
+			});
+
+		} catch (CoreException e) {
+			e.printStackTrace();
+		}
+		rset.getResources().add(contextResource);
+
+		return rset;
+	}
+}