use of antlr.ANTLRException in project checkstyle by checkstyle.
the class MainFrameModel method openFile.
/**
* Open file and load the file.
* @param file the file to open.
* @throws CheckstyleException if the file can not be parsed.
*/
public void openFile(File file) throws CheckstyleException {
if (file != null) {
try {
currentFile = file;
title = "Checkstyle GUI : " + file.getName();
reloadActionEnabled = true;
final DetailAST parseTree;
switch(parseMode) {
case PLAIN_JAVA:
parseTree = parseFile(file);
break;
case JAVA_WITH_COMMENTS:
case JAVA_WITH_JAVADOC_AND_COMMENTS:
parseTree = parseFileWithComments(file);
break;
default:
throw new IllegalArgumentException("Unknown mode: " + parseMode);
}
parseTreeTableModel.setParseTree(parseTree);
parseTreeTableModel.setParseMode(parseMode);
final String[] sourceLines = getFileText(file).toLinesArray();
// clear for each new file
linesToPosition.clear();
// starts line counting at 1
linesToPosition.add(0);
final StringBuilder sb = new StringBuilder();
// insert the contents of the file to the text area
for (final String element : sourceLines) {
linesToPosition.add(sb.length());
sb.append(element).append(System.lineSeparator());
}
text = sb.toString();
} catch (IOException | ANTLRException ex) {
final String exceptionMsg = String.format(Locale.ROOT, "%s occurred while opening file %s.", ex.getClass().getSimpleName(), file.getPath());
throw new CheckstyleException(exceptionMsg, ex);
}
}
}
use of antlr.ANTLRException in project hibernate-orm by hibernate.
the class QueryTranslatorImpl method doCompile.
/**
* Performs both filter and non-filter compiling.
*
* @param replacements Defined query substitutions.
* @param shallow Does this represent a shallow (scalar or entity-id) select?
* @param collectionRole the role name of the collection used as the basis for the filter, NULL if this
* is not a filter.
*/
private synchronized void doCompile(Map replacements, boolean shallow, String collectionRole) {
// If the query is already compiled, skip the compilation.
if (compiled) {
LOG.debug("compile() : The query is already compiled, skipping...");
return;
}
// Remember the parameters for the compilation.
this.tokenReplacements = replacements;
if (tokenReplacements == null) {
tokenReplacements = new HashMap();
}
this.shallowQuery = shallow;
try {
// PHASE 1 : Parse the HQL into an AST.
final HqlParser parser = parse(true);
// PHASE 2 : Analyze the HQL AST, and produce an SQL AST.
final HqlSqlWalker w = analyze(parser, collectionRole);
sqlAst = (Statement) w.getAST();
if (sqlAst.needsExecutor()) {
statementExecutor = buildAppropriateStatementExecutor(w);
} else {
// PHASE 3 : Generate the SQL.
generate((QueryNode) sqlAst);
queryLoader = new QueryLoader(this, factory, w.getSelectClause());
}
compiled = true;
} catch (QueryException qe) {
if (qe.getQueryString() == null) {
throw qe.wrapWithQueryString(hql);
} else {
throw qe;
}
} catch (RecognitionException e) {
// we do not actually propagate ANTLRExceptions as a cause, so
// log it here for diagnostic purposes
LOG.trace("Converted antlr.RecognitionException", e);
throw QuerySyntaxException.convert(e, hql);
} catch (ANTLRException e) {
// we do not actually propagate ANTLRExceptions as a cause, so
// log it here for diagnostic purposes
LOG.trace("Converted antlr.ANTLRException", e);
throw new QueryException(e.getMessage(), hql);
} catch (IllegalArgumentException e) {
// translate this into QueryException
LOG.trace("Converted IllegalArgumentException", e);
throw new QueryException(e.getMessage(), hql);
}
//only needed during compilation phase...
this.enabledFilters = null;
}
use of antlr.ANTLRException in project hudson-2.x by hudson.
the class CronTabList method create.
public static CronTabList create(String format) throws ANTLRException {
Vector<CronTab> r = new Vector<CronTab>();
int lineNumber = 0;
for (String line : format.split("\\r?\\n")) {
lineNumber++;
line = line.trim();
if (line.length() == 0 || line.startsWith("#"))
// ignorable line
continue;
try {
r.add(new CronTab(line, lineNumber));
} catch (ANTLRException e) {
throw new ANTLRException(Messages.CronTabList_InvalidInput(line, e.toString()), e);
}
}
return new CronTabList(r);
}
use of antlr.ANTLRException in project hudson-2.x by hudson.
the class SimpleScheduledRetentionStrategy method readResolve.
protected synchronized Object readResolve() throws ObjectStreamException {
try {
tabs = CronTabList.create(startTimeSpec);
lastChecked = new GregorianCalendar();
this.lastChecked.add(Calendar.MINUTE, -1);
nextStop = Long.MIN_VALUE;
nextStart = Long.MIN_VALUE;
lastStop = Long.MAX_VALUE;
lastStart = Long.MAX_VALUE;
} catch (ANTLRException e) {
InvalidObjectException x = new InvalidObjectException(e.getMessage());
x.initCause(e);
throw x;
}
return this;
}
Aggregations