Commit 4b740f7f authored by Daniel Honsel's avatar Daniel Honsel
Browse files

adapted t3tools configuration and logging structure to Xtext

Maybe it is a good idea to use log4j for logging purposes as Xtext does?
parent eb2272a7
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -6,5 +6,7 @@
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
	<classpathentry kind="lib" path="libs/asm-all-5.0.3.jar"/>
	<classpathentry kind="lib" path="libs/guava-18.0.jar"/>
	<classpathentry combineaccessrules="false" kind="src" path="/de.ugoe.cs.swe.TTCN3Configuration"/>
	<classpathentry kind="output" path="bin"/>
</classpath>
+2.15 MiB

File added.

No diff preview for this file type.

+59 −13
Original line number Diff line number Diff line
package de.ugoe.cs.swe.validation

import de.ugoe.cs.swe.common.logging.LoggingInterface.MessageClass
import de.ugoe.cs.swe.common.logging.LoggingInterface.LogLevel
import com.google.common.base.Strings
import de.ugoe.cs.swe.TTCN3Configuration.QualityCheckProfile
import de.ugoe.cs.swe.TTCN3Configuration.T3QConfig
import de.ugoe.cs.swe.common.ConfigTools
import de.ugoe.cs.swe.tTCN3.AltstepDef
import de.ugoe.cs.swe.tTCN3.AltstepLocalDef
import de.ugoe.cs.swe.tTCN3.AltstepLocalDefList
@@ -8,7 +14,10 @@ import de.ugoe.cs.swe.tTCN3.ComponentDefList
import de.ugoe.cs.swe.tTCN3.ConstDef
import de.ugoe.cs.swe.tTCN3.ConstList
import de.ugoe.cs.swe.tTCN3.ControlStatementOrDefList
import de.ugoe.cs.swe.tTCN3.EnumDef
import de.ugoe.cs.swe.tTCN3.EnumDefNamed
import de.ugoe.cs.swe.tTCN3.Enumeration
import de.ugoe.cs.swe.tTCN3.EnumerationList
import de.ugoe.cs.swe.tTCN3.ForStatement
import de.ugoe.cs.swe.tTCN3.FunctionDef
import de.ugoe.cs.swe.tTCN3.FunctionDefList
@@ -39,6 +48,7 @@ import de.ugoe.cs.swe.tTCN3.StructFieldDef
import de.ugoe.cs.swe.tTCN3.SubTypeDefNamed
import de.ugoe.cs.swe.tTCN3.TTCN3Module
import de.ugoe.cs.swe.tTCN3.TTCN3Package
import de.ugoe.cs.swe.tTCN3.TTCN3Reference
import de.ugoe.cs.swe.tTCN3.TemplateDef
import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalPar
import de.ugoe.cs.swe.tTCN3.TemplateOrValueFormalParList
@@ -47,16 +57,61 @@ import de.ugoe.cs.swe.tTCN3.TypeDef
import de.ugoe.cs.swe.tTCN3.TypeDefBody
import de.ugoe.cs.swe.tTCN3.UnionDefNamed
import de.ugoe.cs.swe.tTCN3.VarInstance
import java.util.regex.Matcher
import java.util.regex.Pattern
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.EStructuralFeature
import org.eclipse.xtext.validation.Check

import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*
import de.ugoe.cs.swe.tTCN3.EnumerationList
import de.ugoe.cs.swe.tTCN3.EnumDef
import de.ugoe.cs.swe.tTCN3.Enumeration
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.nodemodel.INode

class TTCN3Validator extends AbstractTTCN3Validator {
	val private String configurationClassName = typeof(T3QConfig).name;
	val private String configurationProfileClassName = typeof(QualityCheckProfile).name;
	val private String configurationFilename = "config/test.t3q";
	val ConfigTools configTools;
	var QualityCheckProfile activeProfile = null;

	new() {
		configTools = new ConfigTools(configurationClassName, configurationProfileClassName);
		configTools.loadConfig(configurationFilename);
		activeProfile = configTools.selectProfile("defaultProfile") as QualityCheckProfile;
	}

	@Check
	def checkModuleName(TTCN3Module module) {
		val regExp = activeProfile.namingConventionsConfig.moduleRegExp;
		module.checkIdentifierForNamingConventionCompliance(regExp, "module")
	}

	def private boolean regExpMatch(String regExp, String subject) {
		val pattern = Pattern.compile(regExp);
		val Matcher matcher = pattern.matcher(subject);
		return matcher.matches;
	}

	def private checkIdentifierForNamingConventionCompliance(TTCN3Reference object, String regExp, String type) {
		if (object == null || Strings.isNullOrEmpty(regExp))
			return;

		val INode node = NodeModelUtils.getNode(object)

		if (!object.name.regExpMatch(regExp)) {			
			info(
				"Wrong " + type + " name!",
				TTCN3Package.eINSTANCE.TTCN3Reference_Name,
				MessageClass.NAMING.toString,
				node.startLine.toString,
				node.endLine.toString,
				"\"" + object.name + "\" does not comply to the naming conventions for \"" + type + "\"!",
				"2.1, " + regExp,
				LogLevel.INFORMATION.toString
			);
			return;
		}
	}

	@Check
	def checkUniqueNameNestedVariable(RefValue variable) {
@@ -85,15 +140,6 @@ class TTCN3Validator extends AbstractTTCN3Validator {
		}
	}

	@Check
	def checkModuleStartsWithM(TTCN3Module module) {
		val char pattern = 'M';

		if (module.name.charAt(0) != pattern) {
			warning('Module names should start with M!', TTCN3Package.eINSTANCE.TTCN3Reference_Name);
		}
	}

	// TODO: adapt auto-completion (remove extended types)
	// TODO: treat cyclic dependencies??
	@Check
+1 −0
Original line number Diff line number Diff line
@@ -3,3 +3,4 @@ Bundle-ManifestVersion: 2
Bundle-Name: TTCN3ConfigurationProvider
Bundle-SymbolicName: de.ugoe.cs.swe.TTCN3Configuration
Bundle-Version: 1.0.0.qualifier
Require-Bundle: org.eclipse.xtext;bundle-version="2.7.1"
+10 −8
Original line number Diff line number Diff line
package de.ugoe.cs.swe.common;

import de.ugoe.cs.swe.common.logging.LoggingConfiguration;

public abstract class ConfigurationProfile {

	protected String profileName;
@@ -9,7 +11,7 @@ public abstract class ConfigurationProfile {
	protected String projectExtension = "t3p";
	protected boolean settingRecursiveProcessing = true;
	protected boolean settingAbortOnError = true;
//	protected LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
	protected LoggingConfiguration loggingConfiguration = new LoggingConfiguration();
	protected boolean statShowSummary = true;
	protected boolean statShowLOC = true;

@@ -57,13 +59,13 @@ public abstract class ConfigurationProfile {
		return profileVersion;
	}

//	public void setLoggingConfiguration(LoggingConfiguration loggingConfiguration) {
//		this.loggingConfiguration = loggingConfiguration;
//	}
//
//	public LoggingConfiguration getLoggingConfiguration() {
//		return loggingConfiguration;
//	}
	public void setLoggingConfiguration(LoggingConfiguration loggingConfiguration) {
		this.loggingConfiguration = loggingConfiguration;
	}

	public LoggingConfiguration getLoggingConfiguration() {
		return loggingConfiguration;
	}

	public void setStatShowSummary(boolean statShowSummary) {
		this.statShowSummary = statShowSummary;
Loading