|
@@ -1,3 +1,14 @@
|
|
|
+/**
|
|
|
+ * 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;
|
|
@@ -25,6 +36,12 @@ 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
|
|
@@ -32,9 +49,16 @@ public class ImportResolver {
|
|
|
@Inject
|
|
|
private IResourceDescriptions resourceDescriptions;
|
|
|
|
|
|
- public <T extends EObject> List<T> getImportedElementsOfType(Import importedNamespace, Class<T> type) {
|
|
|
+ /**
|
|
|
+ * 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 = getPackageForImport(importedNamespace.eResource(), importedNamespace.getImportedNamespace());
|
|
|
+ Package importedPackage = getPackageForNamespace(importDeclaration.eResource(), importDeclaration.getImportedNamespace());
|
|
|
if (importedPackage != null) {
|
|
|
TreeIterator<EObject> iter = importedPackage.eAllContents();
|
|
|
while (iter.hasNext()) {
|
|
@@ -47,7 +71,14 @@ public class ImportResolver {
|
|
|
return varDefs;
|
|
|
}
|
|
|
|
|
|
- public Package getPackageForImport(Resource contextResource, String namespace) {
|
|
|
+ /**
|
|
|
+ * 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(".*")) {
|