Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorashatalin2009-01-14 13:54:22 -0500
committerashatalin2009-01-14 13:54:22 -0500
commit24b6f8c3b1f33a45a0942bbc18df97fd3bb36d35 (patch)
treed7e734e3d74aa9046c721134694ce4a491738869
parentf436367aae36e0babe7b9c3e99a94b2912d6caf7 (diff)
downloadorg.eclipse.gmf-tooling-24b6f8c3b1f33a45a0942bbc18df97fd3bb36d35.tar.gz
org.eclipse.gmf-tooling-24b6f8c3b1f33a45a0942bbc18df97fd3bb36d35.tar.xz
org.eclipse.gmf-tooling-24b6f8c3b1f33a45a0942bbc18df97fd3bb36d35.zip
Throwing specific exception in case of ambiguous xpand definitions to report this problem as compilation error (to the ProblemsView) instead of runtime .log file.
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/XpandFacade.java3
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/Definition.java4
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/ExpandStatement.java77
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/AmbiguousDefinitionException.java34
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/EvaluationException.java6
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContext.java2
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContextImpl.java5
-rw-r--r--plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/PolymorphicResolver.java7
8 files changed, 95 insertions, 43 deletions
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/XpandFacade.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/XpandFacade.java
index 16e5d06a1..28340ae48 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/XpandFacade.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/XpandFacade.java
@@ -15,6 +15,7 @@ import java.util.HashSet;
import java.util.Set;
import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.gmf.internal.xpand.model.AmbiguousDefinitionException;
import org.eclipse.gmf.internal.xpand.model.AnalysationIssue;
import org.eclipse.gmf.internal.xpand.model.EvaluationException;
import org.eclipse.gmf.internal.xpand.model.ExecutionContext;
@@ -42,7 +43,7 @@ public class XpandFacade {
this.ctx = ctx;
}
- public void evaluate(final String definitionName, final Object targetObject, Object[] params) {
+ public void evaluate(final String definitionName, final Object targetObject, Object[] params) throws AmbiguousDefinitionException {
params = params == null ? new Object[0] : params;
final EClassifier targetType = BuiltinMetaModel.getType(getContext(), targetObject);
final EClassifier[] paramTypes = new EClassifier[params.length];
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/Definition.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/Definition.java
index 40e8696d5..aaf8eabd0 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/Definition.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/Definition.java
@@ -48,7 +48,7 @@ public class Definition extends AbstractDefinition implements XpandDefinition {
@Override
public String toString() {
- return getOwner().getFullyQualifiedName() + TypeNameUtil.NS_DELIM + getName() + getParamString() + " FOR " + type.toString();
+ return getOwner().getFullyQualifiedName() + TypeNameUtil.NS_DELIM + getName() + getParamString() + " FOR " + type.getName();
}
private String getParamString() {
@@ -63,6 +63,6 @@ public class Definition extends AbstractDefinition implements XpandDefinition {
buff.append(",");
}
}
- return buff.toString();
+ return buff.append(")").toString();
}
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/ExpandStatement.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/ExpandStatement.java
index 3775ed9a5..dbce863d6 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/ExpandStatement.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/ast/ExpandStatement.java
@@ -18,6 +18,7 @@ import java.util.Set;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.gmf.internal.xpand.XpandFacade;
+import org.eclipse.gmf.internal.xpand.model.AmbiguousDefinitionException;
import org.eclipse.gmf.internal.xpand.model.AnalysationIssue;
import org.eclipse.gmf.internal.xpand.model.EvaluationException;
import org.eclipse.gmf.internal.xpand.model.ExecutionContext;
@@ -90,11 +91,15 @@ public class ExpandStatement extends Statement {
if ((targetType == null) || Arrays.asList(paramTypes).contains(null)) {
return;
}
- final XpandDefinition def = ctx.findDefinition(definition, targetType, paramTypes);
- if (def == null) {
- issues.add(new AnalysationIssue(AnalysationIssue.Type.DEFINITION_NOT_FOUND,
- "Couldn't find definition " + definition + getParamTypeString(paramTypes)
- + " for type " + targetType.getName(), this));
+ try {
+ final XpandDefinition def = ctx.findDefinition(definition, targetType, paramTypes);
+ if (def == null) {
+ issues.add(new AnalysationIssue(AnalysationIssue.Type.DEFINITION_NOT_FOUND,
+ "Couldn't find definition " + definition + getParamTypeString(paramTypes)
+ + " for type " + targetType.getName(), this));
+ }
+ } catch (AmbiguousDefinitionException e) {
+ issues.add(new AnalysationIssue(AnalysationIssue.Type.DEFINITION_NOT_FOUND, e.getMessage(), this));
}
}
@@ -107,35 +112,41 @@ public class ExpandStatement extends Statement {
final String sep = (String) (separator != null ? separator.evaluate(ctx) : null);
Object targetObject = null;
XpandFacade xpandFacade = new XpandFacade(ctx);
- if (isForeach) {
- targetObject = target.evaluate(ctx);
- if (!(targetObject instanceof Collection)) {
- throw new EvaluationException("Collection expected!", this, target.getCST());
- }
-
- final Collection<?> col = (Collection<?>) targetObject;
- for (final Iterator<?> iter = col.iterator(); iter.hasNext();) {
- xpandFacade.evaluate(definition, iter.next(), params);
- if ((sep != null) && iter.hasNext()) {
- ctx.getScope().getOutput().write(sep);
- }
- }
+ try {
+ if (isForeach) {
+ targetObject = target.evaluate(ctx);
+ if (!(targetObject instanceof Collection)) {
+ throw new EvaluationException("Collection expected!", this, target.getCST());
+ }
+
+ final Collection<?> col = (Collection<?>) targetObject;
+ for (final Iterator<?> iter = col.iterator(); iter.hasNext();) {
+
+ xpandFacade.evaluate(definition, iter.next(), params);
+ if ((sep != null) && iter.hasNext()) {
+ ctx.getScope().getOutput().write(sep);
+ }
+ }
+
+ } else {
+ if (target != null) {
+ targetObject = target.evaluate(ctx);
+ } else {
+ final Variable var = ctx.getImplicitVariable();
+ targetObject = var.getValue();
+ }
+ if (targetObject != null) {
+ xpandFacade.evaluate(definition, targetObject, params);
+ } else {
+ // XXX logInfo that feature value is null or conditionally fail?
+ // perhaps, could check if target is feature and multiplicity of the feature is at least 1 and fail then?
+ // though all these checks are not template's tasks
+ }
+ }
+ } catch (AmbiguousDefinitionException e) {
+ throw new EvaluationException(e.getMessage(), this);
+ }
- } else {
- if (target != null) {
- targetObject = target.evaluate(ctx);
- } else {
- final Variable var = ctx.getImplicitVariable();
- targetObject = var.getValue();
- }
- if (targetObject != null) {
- xpandFacade.evaluate(definition, targetObject, params);
- } else {
- // XXX logInfo that feature value is null or conditionally fail?
- // perhaps, could check if target is feature and multiplicity of the feature is at least 1 and fail then?
- // though all these checks are not template's tasks
- }
- }
}
private String getParamTypeString(final EClassifier[] paramTypes) {
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/AmbiguousDefinitionException.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/AmbiguousDefinitionException.java
new file mode 100644
index 000000000..323452688
--- /dev/null
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/AmbiguousDefinitionException.java
@@ -0,0 +1,34 @@
+/**
+ * Copyright (c) 2009 Borland Software Corp.
+ *
+ * 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:
+ * Alexander Shatalin (Borland) - initial API and implementation
+ */
+package org.eclipse.gmf.internal.xpand.model;
+
+public class AmbiguousDefinitionException extends Exception {
+
+ private XpandDefinition definition1;
+
+ private XpandDefinition definition2;
+
+ public AmbiguousDefinitionException(XpandDefinition candidate1, XpandDefinition candidate2) {
+ super("Ambiguous definitions " + candidate1.toString() + " and " + candidate2.toString());
+ definition1 = candidate1;
+ definition2 = candidate2;
+ }
+
+ public XpandDefinition getDefinition1() {
+ return definition1;
+ }
+
+ public XpandDefinition getDefinition2() {
+ return definition2;
+ }
+
+}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/EvaluationException.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/EvaluationException.java
index 9b160ec9b..68d2df069 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/EvaluationException.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/EvaluationException.java
@@ -38,7 +38,11 @@ public class EvaluationException extends RuntimeException {
location = location(element) + " [" + node.getStartOffset() + ".." + node.getEndOffset() + "]";
}
- private static String location(SyntaxElement element) {
+ public EvaluationException(AmbiguousDefinitionException e) {
+ this(e.getMessage(), null);
+ }
+
+ private static String location(SyntaxElement element) {
if (element == null) {
return "";
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContext.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContext.java
index 8bc270749..1ba2ad352 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContext.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContext.java
@@ -40,7 +40,7 @@ public interface ExecutionContext {
Set<QvtExtension> getAllExtensions();
// may return null if no definition found
- XpandDefinition findDefinition(String name, EClassifier target, EClassifier[] paramTypes);
+ XpandDefinition findDefinition(String name, EClassifier target, EClassifier[] paramTypes) throws AmbiguousDefinitionException;
EcoreEnvironment getOCLEnvironment();
Set<Module> getImportedModules();
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContextImpl.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContextImpl.java
index 1a8856bdb..21ea91060 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContextImpl.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/model/ExecutionContextImpl.java
@@ -132,7 +132,7 @@ public final class ExecutionContextImpl implements ExecutionContext {
return allExtensions;
}
- public XpandDefinition findDefinition(String name, EClassifier target, EClassifier[] paramTypes) {
+ public XpandDefinition findDefinition(String name, EClassifier target, EClassifier[] paramTypes) throws AmbiguousDefinitionException {
String templateName;
boolean localCall = !TypeNameUtil.isQualifiedName(name);
if (localCall) {
@@ -189,9 +189,10 @@ public final class ExecutionContextImpl implements ExecutionContext {
* @param target
* @param paramTypes
* @return
+ * @throws AmbiguousDefinitionException
*/
private static XpandDefinition findDefinition(final XpandDefinition[] definitions, final String name, final EClassifier target,
- EClassifier[] paramTypes, final ExecutionContext ctx) {
+ EClassifier[] paramTypes, final ExecutionContext ctx) throws AmbiguousDefinitionException {
if (paramTypes == null) {
paramTypes = new EClassifier[0];
}
diff --git a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/PolymorphicResolver.java b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/PolymorphicResolver.java
index 14d74bd88..93b6a1e87 100644
--- a/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/PolymorphicResolver.java
+++ b/plugins/org.eclipse.gmf.xpand/src/org/eclipse/gmf/internal/xpand/util/PolymorphicResolver.java
@@ -18,6 +18,7 @@ import java.util.HashMap;
import java.util.List;
import org.eclipse.emf.ecore.EClassifier;
+import org.eclipse.gmf.internal.xpand.model.AmbiguousDefinitionException;
import org.eclipse.gmf.internal.xpand.model.XpandDefinition;
import org.eclipse.ocl.ecore.EcoreEnvironment;
@@ -27,7 +28,7 @@ import org.eclipse.ocl.ecore.EcoreEnvironment;
*/
public class PolymorphicResolver {
- public static XpandDefinition filterDefinition(final HashMap<XpandDefinition, List<EClassifier>> resolvedDefs, EClassifier targetType, List<EClassifier> paramTypes, EcoreEnvironment env) {
+ public static XpandDefinition filterDefinition(final HashMap<XpandDefinition, List<EClassifier>> resolvedDefs, EClassifier targetType, List<EClassifier> paramTypes, EcoreEnvironment env) throws AmbiguousDefinitionException {
final List<EClassifier> allParams = new ArrayList<EClassifier>();
allParams.add(targetType);
allParams.addAll(paramTypes);
@@ -50,8 +51,7 @@ public class PolymorphicResolver {
try {
return filterWithComparator(candidateDefinition, comparator);
} catch (IllegalStateException ex) {
- throw new RuntimeException("Ambiguous definitions " + candidateDefinition.get(0).toString() + " and "
- + candidateDefinition.get(1).toString() + " for param types " + paramTypes);
+ throw new AmbiguousDefinitionException(candidateDefinition.get(0), candidateDefinition.get(1));
}
}
@@ -74,4 +74,5 @@ public class PolymorphicResolver {
}
}
}
+
}

Back to the top