Commit 4f926f3e authored by Leonard Faecke's avatar Leonard Faecke
Browse files

+ Added basic analysis of functions

* Changed reocorded constant type from "null" to "Non-Primitive"
parent 6b59ac1f
Loading
Loading
Loading
Loading
+44 −21
Original line number Diff line number Diff line
@@ -60,23 +60,6 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
					+ ", " +EcoreUtil2.getAllContentsOfType(module, ComponentDef.class).size()
					+ ", " +EcoreUtil2.getAllContentsOfType(module, ConstDef.class).size()
					);
			//repeated counting inefficient, refactor into variables later
			if(EcoreUtil2.getAllContentsOfType(module, ConstDef.class).size() > 0) {
				Map<String, Integer> constants = new HashMap<String, Integer>();
				for(ConstDef constant : EcoreUtil2.getAllContentsOfType(module, ConstDef.class)) {
					String name = constant.getType().getPre();
					if(constants.containsKey(name)) {
						constants.replace(name, constants.get(name) + 1);
					} else {
						constants.put(name, 1);
					}
				}
				System.out.println("Printing types of constants:");
				Set<String> names = constants.keySet();
				for(String name : names) {
					System.out.println(name + ": " + constants.get(name));
				}
			}
			
			*/
			//TODO: very inefficient, better to traverse tree once, e.g.
@@ -124,6 +107,7 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
				output.getOutput().put(eClassName, 1);
			}
			
			//can't cast correctly dynamically? -> add to set, then analyze all manually using getAllContentsOfType
			
			toAnalyze.add(d.getDef().eClass().getInstanceClass());
		}
@@ -132,17 +116,30 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
		//Perhaps some list of classes kept globally, easy to change and append?
		if(toAnalyze.contains(ConstDef.class)) {
			countConstants(module, output);
			toAnalyze.remove(ConstDef.class);
		}
		if(toAnalyze.contains(FunctionDef.class)) {
			analyzeFunctions(module, output);
			toAnalyze.remove(FunctionDef.class);
		}
		if(toAnalyze.size() > 0) {
			System.out.println("Unanalyzed definitions:");
			for(Class<?> a : toAnalyze) {
				System.out.println(a);
			}
		}
		//if(...) ...
		
		System.out.println("Definitions done");
	}
	
	private void countConstants(TTCN3Module module, TTCN3Usage output) {
		List<ConstDef> c =EcoreUtil2.getAllContentsOfType(module, ConstDef.class);
		if(c.size() > 0) {
		System.out.println("Counting constants");
		List<ConstDef> c = EcoreUtil2.getAllContentsOfType(module, ConstDef.class); //not very efficient
		if(c.size() > 0) { //technically not necessary, as long as this function is called in count definitions
			for(ConstDef constant : c) {
				String name = "Constant:" + constant.getType().getPre(); //Added "Constant:" to identifier for better readability of output
				if(constant.getType().getPre() == null) {
					name = "Constant:Non-Primitive";
				}
				if(output.getOutput().containsKey(name)) {
					output.getOutput().replace(name, output.getOutput().get(name) + 1);
				} else {
@@ -150,8 +147,34 @@ public class UsageAnalyzer implements Callable<TTCN3Usage> {
				}
			}
		}
		System.out.println("Constants done");
	}
	
	private void analyzeFunctions(TTCN3Module module, TTCN3Usage output) {
		System.out.println("Counting functions");
		List<FunctionDef> f = EcoreUtil2.getAllContentsOfType(module, FunctionDef.class);
		if(f.size() > 0) {
			for(FunctionDef function : f) {
				String identifier = "FunctionReturn:";
				//There is both Return:void and Return:null -> null is non primitive?
				//If type.pre == "null" is non primitive, how to get?
				if(function.getReturnType() != null) {
					if(function.getReturnType().getType().getPre() == null) 
						identifier += "Non-Primitive";
						//System.out.println("Unknown: " +function.getReturnType().getType().eClass().getInstanceClassName());
					else identifier += function.getReturnType().getType().getPre();
				} else {
					identifier += "void";
				}
				if(output.getOutput().containsKey(identifier)) {
					output.getOutput().replace(identifier, output.getOutput().get(identifier) + 1);
				} else {
					output.getOutput().put(identifier, 1);
				}
			}
		}
		System.out.println("Functions done");
	}
	
	@Override
	public TTCN3Usage call() throws Exception {