Package: TemplateInvocationSpec

TemplateInvocationSpec

nameinstructionbranchcomplexitylinemethod
TemplateInvocationSpec()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
accept(Visitor)
M: 28 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 10 C: 0
0%
M: 1 C: 0
0%
toString()
M: 55 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 12 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2008, 2012 Obeo.
3: * All rights reserved. This program and the accompanying materials
4: * are made available under the terms of the Eclipse Public License v1.0
5: * which accompanies this distribution, and is available at
6: * http://www.eclipse.org/legal/epl-v10.html
7: *
8: * Contributors:
9: * Obeo - initial API and implementation
10: *******************************************************************************/
11: package org.eclipse.acceleo.model.mtl.impl.spec;
12:
13: import java.util.List;
14:
15: import org.eclipse.acceleo.model.mtl.Template;
16: import org.eclipse.acceleo.model.mtl.impl.TemplateInvocationImpl;
17: import org.eclipse.emf.ecore.EClassifier;
18: import org.eclipse.ocl.EvaluationVisitorDecorator;
19: import org.eclipse.ocl.ecore.OCLExpression;
20: import org.eclipse.ocl.parser.ValidationVisitor;
21: import org.eclipse.ocl.util.ToStringVisitor;
22: import org.eclipse.ocl.utilities.Visitor;
23:
24: /**
25: * Specializes the implementation of the TemplateInvocation so that its accept() method delegates the
26: * evaluation to our visitor.
27: *
28: * @author <a href="mailto:laurent.goubet@obeo.fr">Laurent Goubet</a>
29: */
30: public class TemplateInvocationSpec extends TemplateInvocationImpl {
31:         /**
32:          * We know the visitor will be a decorator if the MTLEvaluationVisitor is in use (expected behavior of the
33:          * MTL evaluation engine). This ensures we delegate the call to this decorator.
34:          *
35:          * @param v
36:          * The current evaluation visitor.
37:          * @param <T>
38:          * see {@link OCLExpression#accept(Visitor)}.
39:          * @param <U>
40:          * see {@link OCLExpression#accept(Visitor)}.
41:          * @return Result of this TemplateInvocation evaluation.
42:          */
43:         @Override
44:         @SuppressWarnings("unchecked")
45:         public <T, U extends Visitor<T, ?, ?, ?, ?, ?, ?, ?, ?, ?>> T accept(U v) {
46:                 T result;
47:•                if (v instanceof EvaluationVisitorDecorator<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) {
48:                         result = (T)((EvaluationVisitorDecorator<T, EClassifier, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>)v)
49:                                         .visitExpression(this);
50:•                } else if (v instanceof ToStringVisitor<?, ?, ?, ?, ?, ?, ?, ?, ?>) {
51:                         result = (T)toString();
52:•                } else if (v instanceof ValidationVisitor<?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?>) {
53:                         result = (T)Boolean.TRUE;
54:                 } else {
55:                         throw new UnsupportedOperationException();
56:                 }
57:                 return result;
58:         }
59:
60:         /**
61:          * {@inheritDoc}
62:          *
63:          * @see org.eclipse.acceleo.model.mtl.impl.TemplateInvocationImpl#toString()
64:          */
65:         @Override
66:         public String toString() {
67:                 final Template temp = getDefinition();
68:                 final List<OCLExpression> args = getArgument();
69:
70:                 final StringBuilder toString = new StringBuilder(""); //$NON-NLS-1$
71:•                if (temp != null) {
72:                         toString.append(temp.getName());
73:                 }
74:                 toString.append('(');
75:•                for (int i = 0; i < args.size(); i++) {
76:                         toString.append(args.get(i).toString());
77:•                        if (i + 1 < args.size()) {
78:                                 toString.append(',');
79:                         }
80:                 }
81:                 toString.append(')');
82:                 return toString.toString();
83:         }
84: }