Commit 76c40d6e authored by Leonard Faecke's avatar Leonard Faecke
Browse files

+ Added parameter analysis to function analysis

parent 4f926f3e
Loading
Loading
Loading
Loading
+41 −18
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.HashMap;
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.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -18,7 +15,6 @@ import com.google.common.base.Stopwatch;

import de.ugoe.cs.swe.common.MiscTools;
import de.ugoe.cs.swe.common.logging.LoggingInterface;
import de.ugoe.cs.swe.tTCN3.AltConstruct;
import de.ugoe.cs.swe.tTCN3.FunctionDef;
import de.ugoe.cs.swe.tTCN3.ModuleDefinition;
import de.ugoe.cs.swe.tTCN3.TTCN3File;
@@ -140,11 +136,7 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
				if(constant.getType().getPre() == null) {
					name = "Constant:Non-Primitive";
				}
				if(output.getOutput().containsKey(name)) {
					output.getOutput().replace(name, output.getOutput().get(name) + 1);
				} else {
					output.getOutput().put(name, 1);
				}
				addToOutput(output, name);
			}
		}
		System.out.println("Constants done");
@@ -155,27 +147,58 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
		List<FunctionDef> f = EcoreUtil2.getAllContentsOfType(module, FunctionDef.class);
		if(f.size() > 0) {
			for(FunctionDef function : f) {
				String identifier = "FunctionReturn:";
				
				// Return type:
				String id = "FunctionReturn:";
				//There is both Return:void and Return:null -> null is non primitive?
				//If type.pre == "null" is non primitive, how to get?
				//If type.pre == "null" is non primitive, how to get? -> now only marked as "non-primitive" (is more information even useful?)
				if(function.getReturnType() != null) {
					if(function.getReturnType().getType().getPre() == null) 
						identifier += "Non-Primitive";
						id += "Non-Primitive";
						//System.out.println("Unknown: " +function.getReturnType().getType().eClass().getInstanceClassName());
					else identifier += function.getReturnType().getType().getPre();
					else id += function.getReturnType().getType().getPre();
				} else {
					identifier += "void";
					id += "void";
				}
				if(output.getOutput().containsKey(identifier)) {
					output.getOutput().replace(identifier, output.getOutput().get(identifier) + 1);
				addToOutput(output, id);
				
				// Parameters per function and types:
				if(function.getParameterList() != null) {
					EList<FunctionFormalPar> params = function.getParameterList().getParams();
					for(FunctionFormalPar p : params) {
						id = "FunctionParam:";
						if(p.getValue() == null) {
							id += "NoVal";
						} else {
					output.getOutput().put(identifier, 1);
							if(p.getValue().getType().getPre() == null) {
								id += "Non-Primitive";
							} else {
								id += p.getValue().getType().getPre();
							}
						}
						addToOutput(output, id);
					}
					id = function.getParameterList().getParams().size()+"ParamsInFunction";
				} else {
					id = "0ParamsInFunction";
				}
				addToOutput(output, id);
				
				
			}
		}
		System.out.println("Functions done");
	}
	
	
	private void addToOutput(TTCN3Usage output, String identifier) {
		if(output.getOutput().containsKey(identifier)) {
			output.getOutput().replace(identifier, output.getOutput().get(identifier) + 1);
		} else {
			output.getOutput().put(identifier, 1);
		}
	}
	
	@Override
	public TTCN3Usage call() throws Exception {
		return analyze();