X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=org.eclipse.linuxtools.ctf.core%2Fsrc%2Forg%2Feclipse%2Flinuxtools%2Fctf%2Fcore%2Ftrace%2FMetadata.java;h=27ca681d63be828d4c3e67c81b0d9a99f2ee895a;hb=a94410d92f16c8ce3870bb2e1538b93e038e4f78;hp=db82ea05217dc4b8d5e1852d941b970278786259;hpb=aa572e2229b6097f1d4d2342e2ba58a0c61205b7;p=deliverable%2Ftracecompass.git diff --git a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java index db82ea0521..27ca681d63 100644 --- a/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java +++ b/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/trace/Metadata.java @@ -27,6 +27,7 @@ import java.util.UUID; import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.CommonTokenStream; +import org.antlr.runtime.MismatchedTokenException; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.tree.CommonTree; import org.eclipse.linuxtools.ctf.parser.CTFLexer; @@ -36,9 +37,11 @@ import org.eclipse.linuxtools.internal.ctf.core.event.metadata.IOStructGen; import org.eclipse.linuxtools.internal.ctf.core.event.metadata.exceptions.ParseException; /** - * Metadata - *
- * Represents a metadata file + * The CTF trace metadata file + * + * @version 1.0 + * @author Matthew Khouzam + * @author Simon Marchi */ public class Metadata { @@ -49,12 +52,12 @@ public class Metadata { /** * Name of the metadata file in the trace directory */ - final String METADATA_FILENAME = "metadata"; //$NON-NLS-1$ + final static String METADATA_FILENAME = "metadata"; //$NON-NLS-1$ /** * Size of the metadata packet header, in bytes, computed by hand. */ - final int METADATA_PACKET_HEADER_SIZE = 37; + final static int METADATA_PACKET_HEADER_SIZE = 37; // ------------------------------------------------------------------------ // Attributes @@ -117,6 +120,7 @@ public class Metadata { * Parse the metadata file. * * @throws CTFReaderException + * If there was a problem parsing the metadata */ public void parse() throws CTFReaderException { CTFReaderException tempException = null; @@ -158,19 +162,7 @@ public class Metadata { metadataTextInput = new FileReader(metadataFile); } - /* Create an ANTLR reader */ - ANTLRReaderStream antlrStream; - antlrStream = new ANTLRReaderStream(metadataTextInput); - - /* Parse the metadata text and get the AST */ - CTFLexer ctfLexer = new CTFLexer(antlrStream); - CommonTokenStream tokens = new CommonTokenStream(ctfLexer); - CTFParser ctfParser = new CTFParser(tokens, false); - parse_return ret; - - ret = ctfParser.parse(); - - CommonTree tree = (CommonTree) ret.getTree(); + CommonTree tree = createAST(metadataTextInput); /* Generate IO structures (declarations) */ IOStructGen gen = new IOStructGen(tree, trace); @@ -183,11 +175,9 @@ public class Metadata { tempException = new CTFReaderException(e); } catch (ParseException e) { tempException = new CTFReaderException(e); + } catch (MismatchedTokenException e) { + tempException = new CTFReaderException(e); } catch (RecognitionException e) { - /* - * We don't want to expose this ANTLR-specific exception type to the - * outside.. - */ tempException = new CTFReaderException(e); } @@ -219,6 +209,24 @@ public class Metadata { } } + private static CommonTree createAST(Reader metadataTextInput) throws IOException, + RecognitionException { + /* Create an ANTLR reader */ + ANTLRReaderStream antlrStream; + antlrStream = new ANTLRReaderStream(metadataTextInput); + + /* Parse the metadata text and get the AST */ + CTFLexer ctfLexer = new CTFLexer(antlrStream); + CommonTokenStream tokens = new CommonTokenStream(ctfLexer); + CTFParser ctfParser = new CTFParser(tokens, false); + parse_return ret; + + ret = ctfParser.parse(); + + CommonTree tree = (CommonTree) ret.getTree(); + return tree; + } + /** * Determines whether the metadata file is packet-based by looking at the * TSDL magic number. If it is packet-based, it also gives information about @@ -241,8 +249,7 @@ public class Metadata { try { metadataFileChannel.read(magicByteBuffer, 0); } catch (IOException e) { - throw new CTFReaderException( - "Unable to read metadata file channel."); //$NON-NLS-1$ + throw new CTFReaderException("Unable to read metadata file channel."); //$NON-NLS-1$ } /* Get the first int from the file */ @@ -344,8 +351,7 @@ public class Metadata { try { metadataFileChannel.read(payloadByteBuffer); } catch (IOException e) { - throw new CTFReaderException( - "Error reading metadata packet payload."); //$NON-NLS-1$ + throw new CTFReaderException("Error reading metadata packet payload."); //$NON-NLS-1$ } payloadByteBuffer.rewind();