diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java index 153098a01e..d68256874c 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java @@ -13,8 +13,8 @@ package org.eclipse.tracecompass.ctf.core.event.scope; +import java.util.HashMap; import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; @@ -28,7 +28,7 @@ public class LexicalScope implements ILexicalScope { private int hash = 0; private final @NonNull String fName; private final @NonNull String fPath; - private final Map fChildren = new ConcurrentHashMap<>(); + private final Map fChildren = new HashMap<>(); /** * Hidden constructor for the root node only @@ -40,6 +40,22 @@ protected LexicalScope() { fName = ""; //$NON-NLS-1$ } + /** + * Create a scope + * @param parent + * The parent node, can be null, but shouldn't + * @param name + * the name of the field + * @return the scope + */ + public static @NonNull ILexicalScope create(ILexicalScope parent, @NonNull String name) { + ILexicalScope child = parent.getChild(name); + if( child == null) { + child = new LexicalScope(parent, name); + } + return child; + } + /** * The scope constructor * diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java index 76b5b275b5..96ede37145 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/Declaration.java @@ -43,18 +43,10 @@ public ILexicalScope getPath(IDefinitionScope definitionScope, @NonNull String f if (definitionScope != null) { final ILexicalScope parentPath = definitionScope.getScopePath(); if (parentPath != null) { - ILexicalScope myScope = parentPath.getChild(fieldName); - if (myScope == null) { - myScope = new LexicalScope(parentPath, fieldName); - } - return myScope; + return LexicalScope.create(parentPath, fieldName); } } - ILexicalScope child = ILexicalScope.ROOT.getChild(fieldName); - if (child != null) { - return child; - } - return new LexicalScope(ILexicalScope.ROOT, fieldName); + return LexicalScope.create(ILexicalScope.ROOT, fieldName); } /**