From c2a843a8b3e610414f03ee644cc224649d468a75 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam Date: Mon, 13 Jul 2015 10:30:37 -0400 Subject: [PATCH] ctf: make HashMap child a Map and extract lookupStructScope The map is self explanatory. The method extraction improves readibility in my opinion Change-Id: I9fb23c3223641d80e2f70a18142c3d4b968f0dab Signed-off-by: Matthew Khouzam Reviewed-on: https://git.eclipse.org/r/51854 Reviewed-by: Hudson CI Reviewed-by: Francis Giraldeau --- .../core/event/metadata/DeclarationScope.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/metadata/DeclarationScope.java b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/metadata/DeclarationScope.java index 1a96f6af08..fb0deeb916 100644 --- a/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/metadata/DeclarationScope.java +++ b/ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/metadata/DeclarationScope.java @@ -46,7 +46,7 @@ public class DeclarationScope { // ------------------------------------------------------------------------ private DeclarationScope fParentScope; - private @NonNull HashMap fChildren = new HashMap<>(); + private @NonNull Map fChildren = new HashMap<>(); private final Map fStructs = new HashMap<>(); private final Map fEnums = new HashMap<>(); @@ -471,12 +471,7 @@ public class DeclarationScope { private IDeclaration lookupIdentifierElement(DeclarationScope scope, String scopeName, String[] scopes) { if (scope.fStructs.containsKey(scopeName)) { - final IDeclaration structDeclaration = scope.fStructs.get(scopeName); - if (scopes.length <= 1) { - return structDeclaration; - } - return lookupIdentifierStructElement((StructDeclaration) structDeclaration, scopes[1], Arrays.copyOfRange(scopes, 2, scopes.length)); - + return lookupStructScope(scope, scopeName, scopes); } else if (scope.fTypes.containsKey(scopeName)) { return scope.fTypes.get(scopeName); } else if (scope.fEnums.containsKey(scopeName)) { @@ -487,6 +482,14 @@ public class DeclarationScope { return null; } + private IDeclaration lookupStructScope(DeclarationScope scope, String scopeName, String[] scopes) { + final IDeclaration structDeclaration = scope.fStructs.get(scopeName); + if (scopes.length <= 1) { + return structDeclaration; + } + return lookupIdentifierStructElement((StructDeclaration) structDeclaration, scopes[1], Arrays.copyOfRange(scopes, 2, scopes.length)); + } + private IDeclaration lookupIdentifierStructElement(StructDeclaration structDeclaration, String string, String[] children) { IDeclaration field = structDeclaration.getField(string); if (children == null || children.length <= 0) { -- 2.34.1