blob: 22530e063bb24d94085dcaa4cac5e01cbf0950ca [file] [log] [blame]
tarendtfabd5222012-10-02 19:53:28 +00001<%@ jet package="org.eclipse.emf.refactor.metrics" class="HenshinCalculateClass"
tarendt20ed3072012-10-03 11:01:36 +00002imports="org.eclipse.emf.refactor.metrics.henshin.core.HenshinMetricInfo"%>
tarendtfabd5222012-10-02 19:53:28 +00003<%HenshinMetricInfo info = (HenshinMetricInfo) argument; %>
4package <%=info.getPackage()%>;
5
6import java.io.IOException;
7import java.net.URL;
8import java.util.Collections;
9import java.util.List;
10
11import org.eclipse.core.runtime.FileLocator;
12import org.eclipse.core.runtime.Path;
13import org.eclipse.emf.ecore.EObject;
14import org.eclipse.emf.refactor.metrics.henshin.managers.HenshinManager;
15import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator;
16
17
18public final class <%=info.getClassName()%> implements IMetricCalculator {
19
20 private String transformationPath =
21 getFullPath("transformations/<%=info.getTransformationName()%>");
22
23 private EObject context;
24
25 @Override
26 public void setContext(List<EObject> context) {
27 this.context = context.get(0);
28 }
29
30 @Override
31 public double calculate() {
32 return HenshinManager.run(transformationPath, this.context);
33 }
34
35 private String getFullPath(String transformationPath){
36 URL url = FileLocator.find(<%=info.getProjectName().toLowerCase()%>.Activator.getDefault().getBundle(), new Path(transformationPath), Collections.EMPTY_MAP);
37 URL fileUrl = null;
38 try {
39 fileUrl = FileLocator.toFileURL(url);
40 }
41 catch (IOException e) {
42 e.printStackTrace();
43 }
44 return fileUrl.getPath();
45 }
46}