-
Notifications
You must be signed in to change notification settings - Fork 3
/
eclipseGenerator.mtl
205 lines (181 loc) · 7.09 KB
/
eclipseGenerator.mtl
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
[comment encoding = UTF-8 /]
[module eclipseGenerator('http://www.eclipse.org/acceleo/4.0')/]
[import org::eclipse::acceleo::aql::ide::ui::module::requests::requests/]
[import org::eclipse::acceleo::aql::ide::ui::module::services::Services/]
[**
* Generate the plugin.xml file.
* @param projectUIName the UI project name
*/]
[template public eclipseGeneratorFile(module : acceleo::Module, projectUIName : String)]
[file (projectUIName + '/src/' + projectUIName.replaceAll('\\.', '/') + '/' + module.getEclipseClassName() + '.java', overwrite, 'UTF-8')]
[protected ('copyright') startTagPrefix('//') endTagPrefix('//')]
[/protected]
package [projectUIName/];
[protected ('imports') startTagPrefix('//') endTagPrefix('//')]
import java.io.File;
import java.io.PrintStream;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.acceleo.aql.evaluation.GenerationResult;
import org.eclipse.acceleo.aql.ide.ui.dialog.AbstractResourceSelectionDialog;
import org.eclipse.acceleo.aql.ide.ui.dialog.FolderSelectionDialog;
import org.eclipse.acceleo.query.ast.TypeLiteral;
import org.eclipse.acceleo.query.runtime.namespace.IQualifiedNameQueryEnvironment;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.emf.common.util.Diagnostic;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.ui.PlatformUI;
[let package = module.getJavaPackage()]
[if (package.size() <> 0)]
import [package/].[module.getClassName()/];
[else]
import [module.getClassName()/];
[/if]
[/let]
import [module.getReceiverQualifiedClassName()/];
[/protected]
/**
* Eclipse launcher for [module.getQualifiedName()/].
*
* @author [''.getUserName()/]
* @generated
*/
public class [module.getEclipseClassName()/] extends [module.getClassName()/] {
/**
* The selected value.
* @generated
*/
private final List<EObject> value;
/**
* Constructor.
*
* @param selected
* the selected {@link [module.getReceiverClassName()/]}
* @generated
*/
public MainGeneratorEclipse([module.getReceiverClassName()/] selected) {
super(Collections.emptyList(), getTarget(selected));
this.value = Collections.singletonList(selected);
}
/**
* @generated
*/
@Override
protected List<EObject> getValues(IQualifiedNameQueryEnvironment queryEnvironment,
Map<EClass, List<EObject>> valuesCache, TypeLiteral type, ResourceSet resourceSetForModels) {
return value;
}
/**
* Gets the target folder for the selected {@link [module.getReceiverClassName()/]}.
*
* @param selected
* the model {@link [module.getReceiverClassName()/]}
* @return the target folder for the selected {@link [module.getReceiverClassName()/]}
* @generated
*/
private static String getTarget([module.getReceiverClassName()/] selected) {
final String res;
final AbstractResourceSelectionDialog dialog = new FolderSelectionDialog(PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getShell(), "Select the destination folder", "");
final int dialogResult = dialog.open();
if ((dialogResult == IDialogConstants.OK_ID) && dialog.getFileName() != null && !dialog.getFileName()
.isEmpty()) {
final Path location = new Path(dialog.getFileName());
IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
if (location.segmentCount() == 1) {
res = workspaceRoot.getProject(location.segment(0)).getLocation().toFile().getAbsolutePath();
} else {
res = workspaceRoot.getFolder(location).getLocation().toFile().getAbsolutePath();
}
} else {
res = null;
}
return res;
}
/**
* @generated
*/
@Override
public void generate() {
if (target != null) {
super.generate();
}
}
/**
* Prints the diagnostics for the given {@link GenerationResult}.
*
* @param generationResult
* the {@link GenerationResult}
* @generated
*/
protected void printDiagnostics(GenerationResult generationResult) {
if (generationResult.getDiagnostic().getSeverity() > Diagnostic.INFO) {
printDiagnostic(generationResult.getDiagnostic());
}
}
/**
* Prints the given {@link Diagnostic} for the given {@link PrintStream}.
*
* @param stream
* the {@link PrintStream}
* @param diagnostic
* the {@link Diagnostic}
* @param indentation
* the current indentation
* @generated
*/
protected void printDiagnostic(Diagnostic diagnostic) {
if (diagnostic.getMessage() != null) {
switch (diagnostic.getSeverity()) {
case Diagnostic.INFO:
Activator.getDefault().log(new Status(IStatus.INFO, diagnostic.getSource(), diagnostic
.getMessage(), diagnostic.getException()));
break;
case Diagnostic.WARNING:
Activator.getDefault().log(new Status(IStatus.WARNING, diagnostic.getSource(), diagnostic
.getMessage(), diagnostic.getException()));
break;
case Diagnostic.ERROR:
Activator.getDefault().log(new Status(IStatus.ERROR, diagnostic.getSource(), diagnostic
.getMessage(), diagnostic.getException()));
break;
}
}
for (Diagnostic child : diagnostic.getChildren()) {
printDiagnostic(child);
}
}
/**
* @generated
*/
@Override
protected void afterGeneration(GenerationResult generationResult) {
super.afterGeneration(generationResult);
// refresh if the generated files are in the workspace
final File targetFolder = new File(target);
final IContainer targetWorkspaceContainer = ResourcesPlugin.getWorkspace().getRoot()
.getContainerForLocation(new Path(targetFolder.getAbsolutePath()));
if (targetWorkspaceContainer != null) {
try {
targetWorkspaceContainer.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch (CoreException e) {
Activator.getDefault().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "could not refresh "
+ targetWorkspaceContainer.getFullPath(), e));
}
}
}
}
[/file]
[/template]