Loading de.ugoe.cs.swe.T3Q/src/de/ugoe/cs/swe/T3Q/UsageAnalyzer.java +48 −0 Original line number Diff line number Diff line package de.ugoe.cs.swe.T3Q; import java.util.List; import java.util.Map; import java.util.Set; import java.util.ArrayList; import java.util.HashSet; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.ENamedElement; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.EcoreUtil2; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import de.ugoe.cs.swe.common.MiscTools; import de.ugoe.cs.swe.common.logging.LoggingInterface; Loading Loading @@ -39,6 +47,10 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> { EcoreUtil.resolveAll(this.resource); //get root element EObject model = this.resource.getContents().get(0); //adjust method name, parameters, etc. as needed genericAnalysisExample(model); //collect basic stats (keep in mind multi-threaded processing, need to collect output in a file or in output), //for initial basic testing single-threaded mode should provide first results //System.out.println("Module, FunctionDef, AltConstruct, RecordDefNamed, ComponentDef, ConstDef"); Loading Loading @@ -76,6 +88,42 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> { return output; } private void genericAnalysisExample(EObject model) { //-------------------------------------------------------- //TODO: per file, total //These should be all the e-classes available -> init / compare with collected //initialise all with count 0 Map<String, Long> counts = TTCN3Package.eINSTANCE.eContents() .stream().map(e -> ((ENamedElement)e).getName()) .collect(Collectors.toMap(e->e, v->0L)) ; //sample generic collector (could probably be improved further but it gets the job done) ArrayList<EObject> nodes = Lists.newArrayList(model.eAllContents()); //group and count encountered by name Map<String, Long> grouped = nodes.stream() .collect(Collectors .groupingBy(e->e.eClass().getName(), Collectors.counting())); //integrate into all grouped.forEach((k,v) -> counts.put(k, v)); //dump sorted // counts.entrySet().stream() // .sorted(Comparator.comparing(Entry::getKey)) // .forEach(e -> System.out.println(e.getKey()+" : "+e.getValue())) // ; //create basic json Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(counts); System.out.println(json); //TODO: store as file or return and integrate //-------------------------------------------------------- } /** * Counts all definitions within a module. Loading Loading
de.ugoe.cs.swe.T3Q/src/de/ugoe/cs/swe/T3Q/UsageAnalyzer.java +48 −0 Original line number Diff line number Diff line package de.ugoe.cs.swe.T3Q; import java.util.List; import java.util.Map; import java.util.Set; import java.util.ArrayList; import java.util.HashSet; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.ENamedElement; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.xtext.EcoreUtil2; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import de.ugoe.cs.swe.common.MiscTools; import de.ugoe.cs.swe.common.logging.LoggingInterface; Loading Loading @@ -39,6 +47,10 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> { EcoreUtil.resolveAll(this.resource); //get root element EObject model = this.resource.getContents().get(0); //adjust method name, parameters, etc. as needed genericAnalysisExample(model); //collect basic stats (keep in mind multi-threaded processing, need to collect output in a file or in output), //for initial basic testing single-threaded mode should provide first results //System.out.println("Module, FunctionDef, AltConstruct, RecordDefNamed, ComponentDef, ConstDef"); Loading Loading @@ -76,6 +88,42 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> { return output; } private void genericAnalysisExample(EObject model) { //-------------------------------------------------------- //TODO: per file, total //These should be all the e-classes available -> init / compare with collected //initialise all with count 0 Map<String, Long> counts = TTCN3Package.eINSTANCE.eContents() .stream().map(e -> ((ENamedElement)e).getName()) .collect(Collectors.toMap(e->e, v->0L)) ; //sample generic collector (could probably be improved further but it gets the job done) ArrayList<EObject> nodes = Lists.newArrayList(model.eAllContents()); //group and count encountered by name Map<String, Long> grouped = nodes.stream() .collect(Collectors .groupingBy(e->e.eClass().getName(), Collectors.counting())); //integrate into all grouped.forEach((k,v) -> counts.put(k, v)); //dump sorted // counts.entrySet().stream() // .sorted(Comparator.comparing(Entry::getKey)) // .forEach(e -> System.out.println(e.getKey()+" : "+e.getValue())) // ; //create basic json Gson gson = new GsonBuilder().setPrettyPrinting().create(); String json = gson.toJson(counts); System.out.println(json); //TODO: store as file or return and integrate //-------------------------------------------------------- } /** * Counts all definitions within a module. Loading