Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3f5c366bd268b447d887e0213f4b1a0f9f9bb57d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/******************************************************************************
 * Copyright (c) 2006, 2020 Borland Software Corporation, CEA LIST, Artal
 * 
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/ 
 * 
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors: 
 *    Artem Tikhomirov (Borland) - initial API and implementation
 *    Aurelien Didier (ARTAL) - aurelien.didier51@gmail.com - Bug 569174
 *    Etienne ALLOGO (ARTAL) - etienne.allogo@artal.fr - Bug 569174 - newline characters preference api consistency
 *****************************************************************************/
package org.eclipse.papyrus.gmf.internal.common.codegen;

import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.emf.codegen.jet.JETEmitter;
import org.eclipse.emf.codegen.jet.JETException;

/**
 * @author artem
 */
public class JETEmitterAdapter implements TextEmitter {
	private final JETEmitter myEmitter;

	public JETEmitterAdapter(JETEmitter emitter){
		myEmitter = emitter;
	}
	
	public String generate(IProgressMonitor monitor, Object[] params, String lineSeparator) throws InterruptedException, InvocationTargetException {
		try {
			if (monitor != null && monitor.isCanceled()) {
				throw new InterruptedException();
			}
			return myEmitter.generate(monitor, adaptArgumentsForSkeleton(params));
		} catch (JETException ex) {
			throw new InvocationTargetException(ex);
		}
	}

	/**
	 * JET's generate() method usually takes single argument as input, unless overriden in skeleton 
	 */
	protected Object[] adaptArgumentsForSkeleton(Object[] params) {
		if (params == null || params.length <= 1) {
			return params;
		}
		// more than one argument, hence need to wrap into single object
		return new Object[] { params };
	}
}

Back to the top