Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<String, ILexicalScope> fChildren = new ConcurrentHashMap<>();
private final Map<String, ILexicalScope> fChildren = new HashMap<>();

/**
* Hidden constructor for the root node only
Expand All @@ -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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
Loading