btf: Move plugins to the Trace Compass namespace
[deliverable/tracecompass.git] / org.eclipse.linuxtools.ctf.core / src / org / eclipse / linuxtools / ctf / core / event / types / StructDeclaration.java
index a4d60b145fee2a9fead1cb1585eeb8069b83a2e3..a356e8650ad8f395c9e7afcae9f5502d71a77d4c 100644 (file)
@@ -167,31 +167,24 @@ public class StructDeclaration extends Declaration {
         alignRead(input);
         final Definition[] myFields = new Definition[fFieldMap.size()];
         StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldName, fFieldMap.keySet(), myFields);
-
-        Iterator<Map.Entry<String, IDeclaration>> iter = fFieldMap.entrySet().iterator();
-        for (int i = 0; i < fFieldMap.size(); i++) {
-            Map.Entry<String, IDeclaration> entry = iter.next();
-            String name = entry.getKey();
-            if (name == null) {
-                throw new IllegalStateException();
-            }
-            myFields[i] = entry.getValue().createDefinition(structDefinition, name, input);
-        }
+        fillStruct(input, myFields, structDefinition);
         return structDefinition;
     }
 
     /**
-     * Accelerated create definition
+     * Create a definition from this declaration. This is a faster constructor
+     * as it has a lexical scope and this does not need to look it up.
      *
      * @param definitionScope
-     *            the definition scope
+     *            the definition scope, the parent where the definition will be
+     *            placed
      * @param fieldScope
-     *            the lexical scope of this element
+     *            the scope of the definition
      * @param input
-     *            the {@Link BitBuffer} to read
-     * @return the Struct definition
+     *            a bitbuffer to read from
+     * @return a reference to the definition
      * @throws CTFReaderException
-     *             read error and such
+     *             error in reading
      * @since 3.1
      */
     public StructDefinition createDefinition(IDefinitionScope definitionScope,
@@ -203,15 +196,7 @@ public class StructDeclaration extends Declaration {
          */
         @SuppressWarnings("null")
         StructDefinition structDefinition = new StructDefinition(this, definitionScope, fieldScope, fieldScope.getName(), fFieldMap.keySet(), myFields);
-        Iterator<Map.Entry<String, IDeclaration>> iter = fFieldMap.entrySet().iterator();
-        for (int i = 0; i < fFieldMap.size(); i++) {
-            Map.Entry<String, IDeclaration> entry = iter.next();
-            String fieldName = entry.getKey();
-            if (fieldName == null) {
-                throw new IllegalStateException();
-            }
-            myFields[i] = entry.getValue().createDefinition(structDefinition, fieldName, input);
-        }
+        fillStruct(input, myFields, structDefinition);
         return structDefinition;
     }
 
@@ -228,6 +213,15 @@ public class StructDeclaration extends Declaration {
         fMaxAlign = Math.max(fMaxAlign, declaration.getAlignment());
     }
 
+    @SuppressWarnings("null")
+    private void fillStruct(@NonNull BitBuffer input, final Definition[] myFields, StructDefinition structDefinition) throws CTFReaderException {
+        Iterator<Map.Entry<String, IDeclaration>> iter = fFieldMap.entrySet().iterator();
+        for (int i = 0; i < fFieldMap.size(); i++) {
+            Map.Entry<String, IDeclaration> entry = iter.next();
+            myFields[i] = entry.getValue().createDefinition(structDefinition, entry.getKey(), input);
+        }
+    }
+
     @Override
     public String toString() {
         /* Only used for debugging */
This page took 0.025869 seconds and 5 git commands to generate.