blob: bb6ec0be069e082ec7ee0a18409b03082fa09a28 (
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
|
package org.eclipse.papyrus.uml.textedit.tests;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.command.ICommand;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.papyrus.uml.xtext.integration.DefaultXtextDirectEditorConfiguration;
public class XTextEditorTester<T extends EObject> {
protected DefaultXtextDirectEditorConfiguration editor;
public XTextEditorTester(DefaultXtextDirectEditorConfiguration editor){
this.editor = editor;
}
public T parseText(T initialElement, String textToParse) throws Exception{
IParser parser = editor.createParser(initialElement);
ICommand parseCommand = parser.getParseCommand(new EObjectAdapter(initialElement), textToParse, 0);
parseCommand.execute(new NullProgressMonitor(), null);
return initialElement;
}
public T parseText(final EObject parentElement, final T initialElement, final String textToParse) throws Exception {
IParser parser = editor.createParser(parentElement);
ICommand parseCommand = parser.getParseCommand(new EObjectAdapter(initialElement), textToParse, 0);
if (null != parseCommand) {
parseCommand.execute(new NullProgressMonitor(), null);
}
return initialElement;
}
public String getInitialText(T element){
return editor.getTextToEdit(element);
}
public String getParentInitialText(final Object element) {
return editor.getTextToEdit(element);
}
}
|