use of com.ibm.dtfj.javacore.parser.framework.parser.ILookAheadBuffer in project openj9 by eclipse.
the class ParserController method parse.
/**
* Support for one image builder parsing javacore data for only one runtime.
* Multiple runtime support will require overriding this method in a subclass.
*/
public Image parse(IScannerManager scannerManager) throws ParserException {
ILookAheadBuffer lookAhead = scannerManager.getLookAheadBuffer();
// For error reporting
StringBuffer sb = new StringBuffer();
try {
for (int i = 1; i <= 2 && i <= lookAhead.maxDepth(); ++i) {
IParserToken token = lookAhead.lookAhead(i);
if (token != null) {
sb.append(token.getValue());
}
}
} catch (IOException e) {
} catch (IndexOutOfBoundsException e) {
} catch (ScannerException e) {
throw new ParserException(e);
}
// Don't get too much data
sb.setLength(Math.min(300, sb.length()));
String first = sb.toString();
IImageBuilder imageBuilder = null;
try {
imageBuilder = generateImageBuilder();
} catch (BuilderFailureException e) {
throw new ParserException(e);
}
boolean anyMatched = false;
try {
lookAhead.init();
for (Iterator it = fFramework.iterator(); it.hasNext(); ) {
processUnknownData(lookAhead);
ISectionParser sectionParser = (ISectionParser) it.next();
sectionParser.readIntoDTFJ(lookAhead, imageBuilder);
/*
* Retrieve the error log.
*/
Iterator errors = sectionParser.getErrors();
if ((fListener != null) && errors.hasNext()) {
while (errors.hasNext()) {
fListener.handleEvent(errors.next().toString());
}
}
anyMatched |= sectionParser.anyMatched();
}
} catch (IOException e) {
/*
* If IO exception encountered, parser may have reached a non-recoverable state, so for now no
* point in continuing the parsing process.
*/
e.printStackTrace();
} catch (RuntimeException e) {
/*
* For internal tracing purposes (Eclipse catches runtime exceptions,
* and they get hard to track even with the eclipse error log view).
*/
e.printStackTrace();
throw e;
} catch (ScannerException e) {
throw new ParserException(e);
}
if (!anyMatched) {
throw new ParserException("Not a javacore file. First line: " + first);
}
return imageBuilder.getImage();
}
Aggregations