Commit 224d1947 authored by Daniel Honsel's avatar Daniel Honsel
Browse files

started to improve initializing process of data structures

parent 50c110a4
Loading
Loading
Loading
Loading
+131 −0
Original line number Diff line number Diff line
package de.ugoe.cs.swe.T3Q;

import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.Resource.Diagnostic;
import org.eclipse.emf.ecore.util.Diagnostician;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.xtext.validation.FeatureBasedDiagnostic;

import com.google.common.base.Stopwatch;

import de.ugoe.cs.swe.common.MiscTools;
import de.ugoe.cs.swe.common.logging.LoggingInterface.LogLevel;
import de.ugoe.cs.swe.validation.TTCN3StatisticsProvider;

public class Analyzer implements Callable<String> {
	private final Resource resource;

	public Analyzer(Resource resource) {
		this.resource = resource;
	}

	private String analyze() {
		String output = "";
		final Stopwatch stopwatch = Stopwatch.createUnstarted();
		
		stopwatch.start();
		EcoreUtil.resolveAll(this.resource);
		validate(this.resource);
		// TODO: make this configurable for debug purposes
		for (Diagnostic d : this.resource.getErrors()) {
			TTCN3StatisticsProvider.getInstance().incrementCountUniversal();
//			logger.logInformation(this.resource.getURI(), d.getLine(), d.getLine(),
//					MessageClass.UNIVERSAL, d.getMessage());
		}
		for (Diagnostic d : this.resource.getWarnings()) {
			TTCN3StatisticsProvider.getInstance().incrementCountUniversal();
//			logger.logInformation(this.resource.getURI(), d.getLine(), d.getLine(),
//					MessageClass.UNIVERSAL, d.getMessage());
		}

		stopwatch.stop();

		System.out.println("Analyzing  file: " + this.resource.getURI().devicePath().replaceFirst("///", "") 
				+ " took: "
				+ stopwatch.elapsed(TimeUnit.MILLISECONDS)
				+ " ms ("
				+ MiscTools.secondsToString(stopwatch.elapsed(TimeUnit.SECONDS)) + " minutes).");		
		
		return output;
	}

	private void validate(Resource resource) {
		EObject model = resource.getContents().get(0);
		org.eclipse.emf.common.util.Diagnostic diagnostic = null;
		diagnostic = Diagnostician.INSTANCE .validate(model);
		
		FeatureBasedDiagnostic featureDiagnostic = null;

		for (org.eclipse.emf.common.util.Diagnostic d : diagnostic
				.getChildren()) {
			switch (d.getSeverity()) {
			case org.eclipse.emf.common.util.Diagnostic.ERROR:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
//				logger.logError(resource.getURI(),
//						Integer.parseInt(featureDiagnostic.getIssueData()[0]),
//						Integer.parseInt(featureDiagnostic.getIssueData()[1]),
//						MessageClass.valueOf(featureDiagnostic.getIssueCode()),
//						featureDiagnostic.getMessage());
				break;
			case org.eclipse.emf.common.util.Diagnostic.WARNING:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
//				logger.logWarning(resource.getURI(),
//						Integer.parseInt(featureDiagnostic.getIssueData()[0]),
//						Integer.parseInt(featureDiagnostic.getIssueData()[1]),
//						MessageClass.valueOf(featureDiagnostic.getIssueCode()),
//						featureDiagnostic.getMessage(),
//						featureDiagnostic.getIssueData()[2]);
				break;
			case org.eclipse.emf.common.util.Diagnostic.INFO:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
				switch (LogLevel.valueOf(featureDiagnostic.getIssueData()[3])) {
				case INFORMATION:
//					logger.logInformation(
//							resource.getURI(),
//							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
//							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
//							MessageClass.valueOf(featureDiagnostic
//									.getIssueCode()), featureDiagnostic
//									.getMessage(), featureDiagnostic
//									.getIssueData()[2]);
					break;
				case FIXME:
//					logger.logFix(
//							resource.getURI(),
//							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
//							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
//							MessageClass.valueOf(featureDiagnostic
//									.getIssueCode()), featureDiagnostic
//									.getMessage(), featureDiagnostic
//									.getIssueData()[2]);
					break;
				case DEBUG:
//					logger.logDebug(
//							resource.getURI(),
//							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
//							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
//							MessageClass.valueOf(featureDiagnostic
//									.getIssueCode()), featureDiagnostic
//									.getMessage(), featureDiagnostic
//									.getIssueData()[2]);
					break;
				default:
					break;

				}
				break;
			default:
				break;
			}
		}
	}	
	
	@Override
	public String call() throws Exception {
		return analyze();
	}
}
+2 −2
Original line number Diff line number Diff line
@@ -6,8 +6,8 @@ import java.util.concurrent.Callable;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.resource.SynchronizedXtextResourceSet;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.resource.XtextResourceSet;

import de.ugoe.cs.swe.common.MiscTools;
import de.ugoe.cs.swe.validation.TTCN3StatisticsProvider;
@@ -20,7 +20,7 @@ public class FileParser implements Callable<Resource> {
	}

	private Resource parseFile() {
		final XtextResourceSet resourceSet = new XtextResourceSet();
		final SynchronizedXtextResourceSet resourceSet = new SynchronizedXtextResourceSet();
		resourceSet.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.FALSE);

		final long millisStart = System.currentTimeMillis();
+58 −0
Original line number Diff line number Diff line
package de.ugoe.cs.swe.T3Q;

import java.util.concurrent.Callable;

import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.xtext.EcoreUtil2;

import de.ugoe.cs.swe.common.CommonHelper;
import de.ugoe.cs.swe.scoping.ImportData;
import de.ugoe.cs.swe.scoping.TTCN3GlobalScopeProvider;
import de.ugoe.cs.swe.tTCN3.ImportDef;
import de.ugoe.cs.swe.tTCN3.TTCN3Module;

public class PreAnalyzer implements Callable<Boolean> {
	private final Resource resource;

	public PreAnalyzer(Resource resource) {
		this.resource = resource;
	}

	private boolean findImports() {
		TTCN3Module currentModule = CommonHelper.getModule(this.resource);

		for (ImportDef i : EcoreUtil2.getAllContentsOfType(currentModule, ImportDef.class)) {
			TTCN3Module importedModule = TTCN3GlobalScopeProvider.NAMED_MODULES.get(i.getName());

			synchronized (TTCN3GlobalScopeProvider.IMPORTS) {
				if (TTCN3GlobalScopeProvider.IMPORTS.containsKey(this.resource)) {
					TTCN3GlobalScopeProvider.IMPORTS.get(this.resource).add(new ImportData(i.getName(), i, importedModule));
				} else {
					TTCN3GlobalScopeProvider.IMPORTS.put(this.resource, new ImportData(i.getName(), i, importedModule));
				}
			}
			
			synchronized (TTCN3GlobalScopeProvider.IMPORTED_RESOURCES) {
				if (TTCN3GlobalScopeProvider.IMPORTED_RESOURCES.containsKey(this.resource)) {
					TTCN3GlobalScopeProvider.IMPORTED_RESOURCES.get(this.resource).add(importedModule.eResource());
				} else {
					TTCN3GlobalScopeProvider.IMPORTED_RESOURCES.put(this.resource, importedModule.eResource());
				}				
			}
			
			synchronized (TTCN3GlobalScopeProvider.IMPORTED_FROM) {
				if (TTCN3GlobalScopeProvider.IMPORTED_FROM.containsKey(importedModule)) {
					TTCN3GlobalScopeProvider.IMPORTED_FROM.get(importedModule).add(currentModule);
				} else {
					TTCN3GlobalScopeProvider.IMPORTED_FROM.put(importedModule, currentModule);
				}
			}
		}
		return true;
	}

	@Override
	public Boolean call() throws Exception {
		return findImports();
	}
}
+54 −120
Original line number Diff line number Diff line
@@ -41,11 +41,13 @@ import com.google.inject.Injector;

import de.ugoe.cs.swe.TTCN3StandaloneSetup;
import de.ugoe.cs.swe.TTCN3Configuration.QualityCheckProfile;
import de.ugoe.cs.swe.common.CommonHelper;
import de.ugoe.cs.swe.common.MiscTools;
import de.ugoe.cs.swe.common.logging.LoggingInterface;
import de.ugoe.cs.swe.common.logging.LoggingInterface.LogLevel;
import de.ugoe.cs.swe.common.logging.LoggingInterface.MessageClass;
import de.ugoe.cs.swe.scoping.TTCN3GlobalScopeProvider;
import de.ugoe.cs.swe.tTCN3.TTCN3Module;
import de.ugoe.cs.swe.validation.TTCN3StatisticsProvider;

public class TTCN3ResourceProvider {
@@ -74,7 +76,6 @@ public class TTCN3ResourceProvider {
		ExecutorService pool = Executors.newFixedThreadPool(4);
		ArrayList<FileParser> parser = new ArrayList<FileParser>();
		
		
		for (String path : paths) {
			File file = new File(path);
			
@@ -105,13 +106,27 @@ public class TTCN3ResourceProvider {
			for (Future<Resource> f : list) {
				Resource r = f.get();
				TTCN3GlobalScopeProvider.RESOURCES.add(r);
				TTCN3Module module = CommonHelper.getModule(r);
				TTCN3GlobalScopeProvider.NAMED_MODULES.put(module.getName(), module);
			}
			pool.shutdown();
		} catch (InterruptedException | ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// TODO: extract this to own step
		ArrayList<PreAnalyzer> preAnalyzer = new ArrayList<PreAnalyzer>();
		for (int i = 0; i < TTCN3GlobalScopeProvider.RESOURCES.size(); i++) {
			preAnalyzer.add(new PreAnalyzer(TTCN3GlobalScopeProvider.RESOURCES.get(i)));
		}
		try {
			pool.invokeAll(preAnalyzer);
			pool.shutdown();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		
		stopwatch.stop();
		
		TTCN3StatisticsProvider.getInstance().setParsingCompleted(true);
@@ -121,131 +136,50 @@ public class TTCN3ResourceProvider {

	public void analyzeResources() {
		Stopwatch watchAnalyzing = Stopwatch.createStarted();
		for (Resource r : TTCN3GlobalScopeProvider.RESOURCES) {
			System.out.println("Analyzing  file: "
					+ r.getURI().devicePath().replaceFirst("///", "") + " ...");

			stopwatch.start();
			EcoreUtil.resolveAll(r);
			validate(r);
			// TODO: make this configurable for debug purposes
			for (Diagnostic d : r.getErrors()) {
				TTCN3StatisticsProvider.getInstance().incrementCountUniversal();
				logger.logInformation(r.getURI(), d.getLine(), d.getLine(),
						MessageClass.UNIVERSAL, d.getMessage());
			}
			for (Diagnostic d : r.getWarnings()) {
				TTCN3StatisticsProvider.getInstance().incrementCountUniversal();
				logger.logInformation(r.getURI(), d.getLine(), d.getLine(),
						MessageClass.UNIVERSAL, d.getMessage());
			}

			stopwatch.stop();

			System.out.println("  ...  Analyzing took: "
					+ stopwatch.elapsed(TimeUnit.MILLISECONDS)
					+ " ms ("
					+ MiscTools.secondsToString(stopwatch
							.elapsed(TimeUnit.SECONDS)) + " minutes).");

			TTCN3StatisticsProvider.getInstance().addAnalyzeTime(
					stopwatch.elapsed(TimeUnit.MILLISECONDS));
			stopwatch.reset();
		}
		ExecutorService pool = Executors.newFixedThreadPool(4);
		
		if (activeProfile.isFeatureListImportedModuleNames()) {
			TTCN3StatisticsProvider.getInstance().printListImportedModuleNames(
					false, logger);
		ArrayList<Analyzer> analyzer = new ArrayList<Analyzer>();
		for (int i = 0; i < TTCN3GlobalScopeProvider.RESOURCES.size(); i++) {
			analyzer.add(new Analyzer(TTCN3GlobalScopeProvider.RESOURCES.get(i)));
		}

		if (activeProfile.isFeatureListImportedModuleFileNames()) {
			TTCN3StatisticsProvider.getInstance().printListImportedModuleNames(
					true, logger);
		try {
			List<Future<String>> output = pool.invokeAll(analyzer);
			pool.shutdown();
			for (Future<String> f : output) {
				String o = f.get();
				System.out.println(o);
			}

		if (activeProfile.isFeatureListImportingModuleNames()) {
			TTCN3StatisticsProvider.getInstance()
					.printListImportingModuleNames(false, logger);
		} catch (InterruptedException | ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}				
		
		if (activeProfile.isFeatureListImportingModuleFileNames()) {
			TTCN3StatisticsProvider.getInstance()
					.printListImportingModuleNames(true, logger);
		}

//		if (activeProfile.isFeatureListImportedModuleNames()) {
//			TTCN3StatisticsProvider.getInstance().printListImportedModuleNames(
//					false, logger);
//		}
//
//		if (activeProfile.isFeatureListImportedModuleFileNames()) {
//			TTCN3StatisticsProvider.getInstance().printListImportedModuleNames(
//					true, logger);
//		}
//
//		if (activeProfile.isFeatureListImportingModuleNames()) {
//			TTCN3StatisticsProvider.getInstance()
//					.printListImportingModuleNames(false, logger);
//		}
//
//		if (activeProfile.isFeatureListImportingModuleFileNames()) {
//			TTCN3StatisticsProvider.getInstance()
//					.printListImportingModuleNames(true, logger);
//		}
		watchAnalyzing.stop();
		System.out.println("Test suite analyzed in "
				+ MiscTools.msToString(watchAnalyzing.elapsed(TimeUnit.MILLISECONDS)) + " minutes." + '\n');
	}

	private void validate(Resource resource) {
		EObject model = resource.getContents().get(0);
		org.eclipse.emf.common.util.Diagnostic diagnostic = Diagnostician.INSTANCE
				.validate(model);
		FeatureBasedDiagnostic featureDiagnostic = null;

		for (org.eclipse.emf.common.util.Diagnostic d : diagnostic
				.getChildren()) {
			switch (d.getSeverity()) {
			case org.eclipse.emf.common.util.Diagnostic.ERROR:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
				logger.logError(resource.getURI(),
						Integer.parseInt(featureDiagnostic.getIssueData()[0]),
						Integer.parseInt(featureDiagnostic.getIssueData()[1]),
						MessageClass.valueOf(featureDiagnostic.getIssueCode()),
						featureDiagnostic.getMessage());
				break;
			case org.eclipse.emf.common.util.Diagnostic.WARNING:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
				logger.logWarning(resource.getURI(),
						Integer.parseInt(featureDiagnostic.getIssueData()[0]),
						Integer.parseInt(featureDiagnostic.getIssueData()[1]),
						MessageClass.valueOf(featureDiagnostic.getIssueCode()),
						featureDiagnostic.getMessage(),
						featureDiagnostic.getIssueData()[2]);
				break;
			case org.eclipse.emf.common.util.Diagnostic.INFO:
				featureDiagnostic = (FeatureBasedDiagnostic) d;
				switch (LogLevel.valueOf(featureDiagnostic.getIssueData()[3])) {
				case INFORMATION:
					logger.logInformation(
							resource.getURI(),
							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
							MessageClass.valueOf(featureDiagnostic
									.getIssueCode()), featureDiagnostic
									.getMessage(), featureDiagnostic
									.getIssueData()[2]);
					break;
				case FIXME:
					logger.logFix(
							resource.getURI(),
							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
							MessageClass.valueOf(featureDiagnostic
									.getIssueCode()), featureDiagnostic
									.getMessage(), featureDiagnostic
									.getIssueData()[2]);
					break;
				case DEBUG:
					logger.logDebug(
							resource.getURI(),
							Integer.parseInt(featureDiagnostic.getIssueData()[0]),
							Integer.parseInt(featureDiagnostic.getIssueData()[1]),
							MessageClass.valueOf(featureDiagnostic
									.getIssueCode()), featureDiagnostic
									.getMessage(), featureDiagnostic
									.getIssueData()[2]);
					break;
				default:
					break;

				}
				break;
			default:
				break;
			}
		}
	}

	public void printStatistics() {
		if (activeProfile.isStatShowLOC())
+0 −1
Original line number Diff line number Diff line
@@ -81,7 +81,6 @@ Workflow {
			composedCheck = "de.ugoe.cs.swe.validation.StructureOfDataValidator"
			composedCheck = "de.ugoe.cs.swe.validation.CodeStyleValidator"
			composedCheck = "de.ugoe.cs.swe.validation.ModularizationValidator"
			composedCheck = "de.ugoe.cs.swe.validation.MiscFeatureValidator"
			composedCheck = "de.ugoe.cs.swe.validation.LogValidator"

			// name clash validator
Loading