Skip to content

Commit 03e60bd

Browse files
committed
Disable debug of cyclic dependencies by default
1 parent 9dcc12d commit 03e60bd

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

com.avaloq.tools.ddk.xtext/src/com/avaloq/tools/ddk/xtext/scoping/AbstractRecursiveScope.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
package com.avaloq.tools.ddk.xtext.scoping;
1212

1313
import java.util.ConcurrentModificationException;
14+
import java.util.HashSet;
1415
import java.util.Iterator;
1516
import java.util.Map;
1617
import java.util.Set;
@@ -27,7 +28,6 @@
2728
import com.avaloq.tools.ddk.caching.CacheManager;
2829
import com.avaloq.tools.ddk.xtext.resource.Messages;
2930
import com.google.common.collect.Iterables;
30-
import com.google.common.collect.Sets;
3131

3232

3333
/**
@@ -37,16 +37,14 @@
3737
public abstract class AbstractRecursiveScope extends AbstractScope {
3838

3939
// CHECKSTYLE:OFF
40-
private static boolean DEBUG = true;
40+
private static boolean DEBUG = Boolean.getBoolean("com.avaloq.tools.ddk.xtext.scoping.AbstractRecursiveScope.debugCyclicDependency"); //$NON-NLS-1$
4141
// CHECKSTYLE:ON
4242

43-
private static final String CYCLIC_DEPENDENCY_MESSAGE = "Cyclic dependency detected for \"{0}\"."; //$NON-NLS-1$
44-
4543
/**
4644
* Set is used to trace invocations of {@link #getSingleElement(QualifiedName)} and {@link #getAllContentsByEObject(EObject)}.
4745
* A duplicate insertion indicates an infinite recursion, i.e. it would lead to a stack overflow.
4846
*/
49-
private final Set<Object> invocationTrace = Sets.newHashSetWithExpectedSize(4);
47+
private Set<Object> invocationTrace;
5048

5149
/**
5250
* Marker for the null value for the lookups to be able to distinguish unsuccessful lookups
@@ -107,20 +105,29 @@ public AbstractRecursiveScope(final String id, final IScope parent, final boolea
107105
@Override
108106
public synchronized Iterable<IEObjectDescription> getAllElements() {
109107
if (contents == null) {
110-
// contents = super.getAllElements(); TODO super eliminates duplicates using a very inefficient algorithm
108+
// contents = super.getAllElements() eliminates duplicates using a very inefficient algorithm
111109
contents = Iterables.concat(getAllLocalElements(), getParent().getAllElements());
112110
}
113111
return contents;
114112
}
115113

114+
private void addInvocationTrace(final Object object) {
115+
if (invocationTrace == null) {
116+
invocationTrace = new HashSet<>();
117+
}
118+
if (!invocationTrace.add(object)) {
119+
throw new IllegalStateException(Messages.bind("Cyclic dependency detected for \"{0}\".", String.valueOf(object))); //$NON-NLS-1$
120+
}
121+
}
122+
116123
@Override
117124
public synchronized IEObjectDescription getSingleElement(final QualifiedName name) { // NOPMD NPathComplexity
118125
if (name == null) {
119126
throw new IllegalArgumentException("Null name in getContentByName"); //$NON-NLS-1$
120127
}
121128
try {
122-
if (DEBUG && !invocationTrace.add(name)) {
123-
throw new IllegalStateException(Messages.bind(CYCLIC_DEPENDENCY_MESSAGE, String.valueOf(name)));
129+
if (DEBUG) {
130+
addInvocationTrace(name);
124131
}
125132
final QualifiedName lookupName = isIgnoreCase() ? name.toLowerCase() : name; // NOPMD UseLocaleWithCaseConversions
126133
IEObjectDescription result = nameCache.get(lookupName);
@@ -153,8 +160,6 @@ public synchronized IEObjectDescription getSingleElement(final QualifiedName nam
153160
}
154161
if (result == null) {
155162
nameCache.put(lookupName, NULL_DESCRIPTION);
156-
// } else {
157-
// ScopeTrace.addTrace(result, getId());
158163
}
159164
return result;
160165
} catch (ConcurrentModificationException e) {
@@ -185,9 +190,10 @@ private void reset() {
185190
@Override
186191
public synchronized IEObjectDescription getSingleElement(final EObject object) {
187192
try {
188-
if (DEBUG && !invocationTrace.add(object)) {
189-
throw new IllegalStateException(Messages.bind(CYCLIC_DEPENDENCY_MESSAGE, String.valueOf(object)));
193+
if (DEBUG) {
194+
addInvocationTrace(object);
190195
}
196+
191197
final URI key = EcoreUtil.getURI(object);
192198
IEObjectDescription result = objectCache.get(key);
193199
if (result == NULL_DESCRIPTION) { // NOPMD CompareObjectsWithEquals

0 commit comments

Comments
 (0)