Commit fdce308e authored by Daniel Honsel's avatar Daniel Honsel
Browse files

Replaced UsageCrossReferencer with a better performing alternative.

This reduces validation time at least by a third.
parent 31036470
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class TTCN3ResourceProvider {
	@Inject
	private XtextResourceSet resourceSet;

	private Stopwatch stopwatch = Stopwatch.createUnstarted();
	private final Stopwatch stopwatch = Stopwatch.createUnstarted();

	public TTCN3ResourceProvider(final ArrayList<String> paths, LoggingInterface logger, QualityCheckProfile activeProfile) {
		super();
+19 −0
Original line number Diff line number Diff line
package de.ugoe.cs.swe.common;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.xtext.EcoreUtil2.ElementReferenceAcceptor;

public class TTCN3ElementReferenceAcceptor implements ElementReferenceAcceptor {
	private boolean foundReference = false;
	
	@Override
	public void accept(EObject referrer, EObject referenced, EReference reference, int index) {
		foundReference = true;
	}
	
	public boolean foundReference() {
		return foundReference;
	}
	
}
+23 −9
Original line number Diff line number Diff line
package de.ugoe.cs.swe.validation

import com.google.common.base.Stopwatch
import com.google.common.base.Strings
import de.ugoe.cs.swe.TTCN3Configuration.QualityCheckProfile
import de.ugoe.cs.swe.common.ConfigTools
import de.ugoe.cs.swe.common.MiscTools
import de.ugoe.cs.swe.common.TTCN3ElementReferenceAcceptor
import de.ugoe.cs.swe.common.logging.LoggingInterface.LogLevel
import de.ugoe.cs.swe.common.logging.LoggingInterface.MessageClass
import de.ugoe.cs.swe.tTCN3.AltConstruct
@@ -13,6 +15,7 @@ import de.ugoe.cs.swe.tTCN3.BaseTemplate
import de.ugoe.cs.swe.tTCN3.ComponentDef
import de.ugoe.cs.swe.tTCN3.ConstDef
import de.ugoe.cs.swe.tTCN3.ConstList
import de.ugoe.cs.swe.tTCN3.EnumDefNamed
import de.ugoe.cs.swe.tTCN3.FormalPortPar
import de.ugoe.cs.swe.tTCN3.FormalTemplatePar
import de.ugoe.cs.swe.tTCN3.FormalTimerPar
@@ -62,7 +65,6 @@ import java.util.regex.Matcher
import java.util.regex.Pattern
import org.eclipse.emf.ecore.EClass
import org.eclipse.emf.ecore.EObject
import org.eclipse.emf.ecore.util.EcoreUtil.UsageCrossReferencer
import org.eclipse.xtext.nodemodel.INode
import org.eclipse.xtext.nodemodel.util.NodeModelUtils
import org.eclipse.xtext.validation.AbstractDeclarativeValidator
@@ -71,7 +73,6 @@ import org.eclipse.xtext.validation.EValidatorRegistrar

import static extension de.ugoe.cs.swe.common.TTCN3ScopeHelper.*
import static extension org.eclipse.xtext.EcoreUtil2.*
import de.ugoe.cs.swe.tTCN3.EnumDefNamed

class CheckDefinitionComeFirstParameter {
	public boolean hasOtherDefinitions
@@ -82,6 +83,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	val static Map<String, ArrayList<String>> moduleLevelIdentifiersMap = new ConcurrentHashMap<String, ArrayList<String>>();
	val ConfigTools configTools = ConfigTools.getInstance;
	var QualityCheckProfile activeProfile = configTools.selectedProfile as QualityCheckProfile
	final Stopwatch stopwatch = Stopwatch.createUnstarted();

	@Check
	def checkNoGotoStatements(GotoStatement goto) {
@@ -604,8 +606,19 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {

	// TODO: figure out another way to find referenced objects
	private def boolean isUnreferenced(EObject type, EObject parent) {
		val result = UsageCrossReferencer.find(type, parent.eResource)
		result.size == 0
		//stopwatch.start

		val target = newHashSet(type);
		val TTCN3ElementReferenceAcceptor acceptor = new TTCN3ElementReferenceAcceptor()

		parent.findCrossReferences(target, acceptor)

		//stopwatch.stop

		//System.err.println("Finding cross references takes: " + stopwatch.toString)
		//stopwatch.reset

		return !acceptor.foundReference
	}

	@Check
@@ -777,33 +790,34 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
	}

	private def boolean isReferencedComponentSpec(ComponentDef component, EObject parent) {
		val module = parent.findDesiredParent(TTCN3Module)
		for (d : component.defs) {
			val element = d.element
			if (element.port != null) {
				for (p : element.port.instances) {
					if (!p.isUnreferenced(parent))
					if (!p.isUnreferenced(module))
						return true
				}
			} else if (element.const != null) {
				for (c : element.const.defs.list) {
					if (!c.isUnreferenced(parent))
					if (!c.isUnreferenced(module))
						return true
				}
			} else if (element.timer != null) {
				for (t : element.timer.list.variables) {
					if (!t.isUnreferenced(parent))
					if (!t.isUnreferenced(module))
						return true
				}
			} else if (element.variable != null) {
				if (element.variable.list != null) {
					for (v : element.variable.list.variables) {
						if (!v.isUnreferenced(parent))
						if (!v.isUnreferenced(module))
							return true
					}
				}
				if (element.variable.tempList != null) {
					for (tv : element.variable.tempList.variables) {
						if (!tv.isUnreferenced(parent))
						if (!tv.isUnreferenced(module))
							return true
					}
				}