Commit 1848e39e authored by Daniel Honsel's avatar Daniel Honsel
Browse files

added alternative version

parent d9b3e96e
Loading
Loading
Loading
Loading
+47 −1
Original line number Diff line number Diff line
@@ -76,4 +76,50 @@ public class TTCN3ReferenceHelper {
		return false;
	}
	
	@SuppressWarnings("unchecked")
	public static boolean isReferenced2(EObject rootElement, Set<? extends EObject> targets) {
		boolean found = false;
		
		for(EReference ref: rootElement.eClass().getEAllReferences()) {
			
			if (found)
				return true;
			
			if(rootElement.eIsSet(ref)) {
				if(ref.isContainment()) {
					Object content = rootElement.eGet(ref, false);
					if(ref.isMany()) {
						InternalEList<EObject> contentList = (InternalEList<EObject>) content;
						for(int i=0; i<contentList.size(); ++i) {
							EObject childElement = contentList.basicGet(i);
							if(!childElement.eIsProxy())
								found |= isReferenced2(childElement, targets);
						}
					} else {
						EObject childElement = (EObject) content;
						if(!childElement.eIsProxy())
							found |= isReferenced2(childElement, targets);
					}
				} else if (!ref.isContainer()) {
					Object value = rootElement.eGet(ref, false);
					if(ref.isMany()) {
						InternalEList<EObject> values = (InternalEList<EObject>) value;
						for(int i=0; i< values.size(); ++i) {
							EObject refElement = values.get(i);
							if(targets.contains(refElement)) {
								return true;
							}
						}
					} else {
						EObject refElement = (EObject) value;
						if(targets.contains(refElement)) {
							return true;
						}
					}
				}
			}
		}
		return found;
	}	
	
}
+2 −3
Original line number Diff line number Diff line
@@ -610,8 +610,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {
		stopwatch.start

		val target = newHashSet(type);

		var boolean found = parent.isReferenced(target)
		var boolean found = parent.isReferenced2(target)

		stopwatch.stop

@@ -622,7 +621,7 @@ class CodeStyleValidator extends AbstractDeclarativeValidator {

				// only consider modules that are importing the current module
				if (statistics.isBaseModuleImported(parent, currentBase.name)) {
					if (currentBase.isReferenced(target)) {
					if (currentBase.isReferenced2(target)) {
						return false
					}
				}