tarendt | fabd522 | 2012-10-02 19:53:28 +0000 | [diff] [blame] | 1 | <%@ jet package="org.eclipse.emf.refactor.metrics" class="HenshinCalculateClass" |
tarendt | 20ed307 | 2012-10-03 11:01:36 +0000 | [diff] [blame] | 2 | imports="org.eclipse.emf.refactor.metrics.henshin.core.HenshinMetricInfo"%> |
tarendt | fabd522 | 2012-10-02 19:53:28 +0000 | [diff] [blame] | 3 | <%HenshinMetricInfo info = (HenshinMetricInfo) argument; %> |
| 4 | package <%=info.getPackage()%>; |
| 5 | |
| 6 | import java.io.IOException; |
| 7 | import java.net.URL; |
| 8 | import java.util.Collections; |
| 9 | import java.util.List; |
| 10 | |
| 11 | import org.eclipse.core.runtime.FileLocator; |
| 12 | import org.eclipse.core.runtime.Path; |
| 13 | import org.eclipse.emf.ecore.EObject; |
| 14 | import org.eclipse.emf.refactor.metrics.henshin.managers.HenshinManager; |
| 15 | import org.eclipse.emf.refactor.metrics.interfaces.IMetricCalculator; |
| 16 | |
| 17 | |
| 18 | public 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 | } |