diff options
author | Frank HERMANN | 2014-10-02 06:56:50 +0000 |
---|---|---|
committer | Frank HERMANN | 2014-10-02 06:56:50 +0000 |
commit | fda70e8499a87ab11b32765a23376a3b15caf54c (patch) | |
tree | 4de20b035c76bbf9f131086f936512e94795a87a /plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples | |
parent | 8b78e6477bcc2f86163bfc7c8243d87a59922008 (diff) | |
download | org.eclipse.emft.henshin-fda70e8499a87ab11b32765a23376a3b15caf54c.tar.gz org.eclipse.emft.henshin-fda70e8499a87ab11b32765a23376a3b15caf54c.tar.xz org.eclipse.emft.henshin-fda70e8499a87ab11b32765a23376a3b15caf54c.zip |
JavaImports example: added check for possible Null-Pointer exception
If the example rule application fails to execute, then the graph may not
have any node. This case will now throw a corresponding Runtime
exception. This is relevant, e.g., if this example is used as a test
case for engine updates.
Change-Id: I849b01c2ec6c3eb96d6bb1e2f1502091a3a0f840
Signed-off-by: Frank HERMANN <frank.hermann-henshin@outlook.com>
Diffstat (limited to 'plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples')
-rw-r--r-- | plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/javaimports/JavaImportsExample.java | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/javaimports/JavaImportsExample.java b/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/javaimports/JavaImportsExample.java index 3d088049d..b916623e8 100644 --- a/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/javaimports/JavaImportsExample.java +++ b/plugins/org.eclipse.emf.henshin.examples/src/org/eclipse/emf/henshin/examples/javaimports/JavaImportsExample.java @@ -9,6 +9,8 @@ */ package org.eclipse.emf.henshin.examples.javaimports; +import java.util.Iterator; + import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.henshin.interpreter.EGraph; import org.eclipse.emf.henshin.interpreter.Engine; @@ -59,7 +61,17 @@ public class JavaImportsExample { app.setParameterValue("x", value); InterpreterUtil.executeOrDie(app); - EObject newObj = graph.iterator().next(); + + + // retrieve the node that was created by the rule + Iterator<EObject> graphIt =graph.iterator(); + EObject newObj = null; + if(graphIt.hasNext()) + newObj = graphIt.next(); + if(newObj==null) + throw new RuntimeException("Unexpected result of rule application: no graph node was created (expected one node)"); + + // retrieve the attribute value of the node and check the expected result String newValue = (String) newObj.eGet(newObj.eClass().getEStructuralFeature("stringValue")); if (!newValue.equals(value.toUpperCase())) { throw new RuntimeException("Unexpected string value: \"" + newValue + "\" (expected \"" |