/** * Throw an exception if the expression passed in is a String Literal */ private void notStringLiteral(Expression exp, String expected) throws ParseException { if (exp instanceof StringLiteral) { throw new ParseException( "Found string literal: " + exp + ". Expecting: " + expected, exp); } }
tokenErrDesc = getCustomTokenErrorDescription(); if (tokenErrDesc == null) { break; tokenErrDesc += add_escapes(tok.image); tok = tok.next;
+ (endNames.size() == 0 ? "" : " You have an unclosed " + concatWithOrs(endNames) + "."); } else if (kind == ELSE) { return "Unexpected directive, \"#else\". "
private void renderMessageAndDescription() { String desc = getOrRenderDescription(); String prefix; if (!isInJBossToolsMode()) { prefix = "Syntax error " + _MessageUtil.formatLocationForSimpleParsingError(templateName, lineNumber, columnNumber) + ":\n"; } else { prefix = "[col. " + columnNumber + "] "; } String msg = prefix + desc; desc = msg.substring(prefix.length()); // so we reuse the backing char[] synchronized (this) { message = msg; description = desc; messageAndDescriptionRendered = true; } }
e.setTemplateName(parentTemplate.getSourceName()); throw e;
private static void renderPomXml(MavenizationService.MavenizationContext mavCtx, Pom pom, Path pomXmlPath) { Map vars = new HashMap(); vars.put("pom", pom); vars.put("config", mavCtx.getGraphContext().getUnique(WindupConfigurationModel.class)); Path template = chooseTemplate(pom); try { LOG.info("Rendering template: " + template + " into " + pomXmlPath + System.lineSeparator()+" - " + pom); Files.createDirectories(pomXmlPath.getParent()); renderFreemarkerTemplate(template, vars, pomXmlPath); } catch (ParseException ex) { throw new WindupException("Could not parse pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } catch (IOException | TemplateException ex) { throw new WindupException("Error rendering pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } }
throw new ParseException("Token manager error: " + exc, 0, 0); e.setTemplateName(name); throw e;
return super.getMessage() + " in " + templateName; String retval = customGetMessage(); if (retval != null) { return retval; break; retval += add_escapes(tok.image); tok = tok.next;
/** * Returns the description of the error without error location or source quotations, or {@code null} if there's no * description available. This is useful in editors (IDE-s) where the error markers and the editor window itself * already carry this information, so it's redundant the repeat in the error dialog. */ public String getEditorMessage() { return getDescription(); }
private ParseException(String description, String templateName, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, Throwable cause) { super(description); // but we override getMessage, so it will be different try { this.initCause(cause); } catch (Exception e) { // Suppressed; we can't do more } this.description = description; this.templateName = templateName; this.lineNumber = lineNumber; this.columnNumber = columnNumber; this.endLineNumber = endLineNumber; this.endColumnNumber = endColumnNumber; }
e.setTemplateName(getSourceName()); throw e; } finally {
private void renderMessageAndDescription() { String desc = getOrRenderDescription(); String prefix; if (!isInJBossToolsMode()) { prefix = "Syntax error " + _MessageUtil.formatLocationForSimpleParsingError(templateName, lineNumber, columnNumber) + ":\n"; } else { prefix = "[col. " + columnNumber + "] "; } String msg = prefix + desc; desc = msg.substring(prefix.length()); // so we reuse the backing char[] synchronized (this) { message = msg; description = desc; messageAndDescriptionRendered = true; } }
private static void renderPomXml(MavenizationService.MavenizationContext mavCtx, Pom pom, Path pomXmlPath) { Map vars = new HashMap(); vars.put("pom", pom); vars.put("config", mavCtx.getGraphContext().getUnique(WindupConfigurationModel.class)); Path template = chooseTemplate(pom); try { LOG.info("Rendering template: " + template + " into " + pomXmlPath + System.lineSeparator()+" - " + pom); Files.createDirectories(pomXmlPath.getParent()); renderFreemarkerTemplate(template, vars, pomXmlPath); } catch (ParseException ex) { throw new WindupException("Could not parse pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } catch (IOException | TemplateException ex) { throw new WindupException("Error rendering pom.xml template: " + template + System.lineSeparator()+" Reason: " + ex.getMessage(), ex); } }
/** * Returns the description of the error without error location or source quotations, or {@code null} if there's no * description available. This is useful in editors (IDE-s) where the error markers and the editor window itself * already carry this information, so it's redundant the repeat in the error dialog. */ public String getEditorMessage() { return getDescription(); }
private ParseException(String description, String templateName, int lineNumber, int columnNumber, int endLineNumber, int endColumnNumber, Throwable cause) { super(description); // but we override getMessage, so it will be different try { this.initCause(cause); } catch (Exception e) { // Suppressed; we can't do more } this.description = description; this.templateName = templateName; this.lineNumber = lineNumber; this.columnNumber = columnNumber; this.endLineNumber = endLineNumber; this.endColumnNumber = endColumnNumber; }
void checkCurrentOutputFormatCanEscape(Token start) throws ParseException { if (!(outputFormat instanceof MarkupOutputFormat)) { throw new ParseException("The current output format can't do escaping: " + outputFormat, template, start); } }
tokenErrDesc = getCustomTokenErrorDescription(); if (tokenErrDesc == null) { break; tokenErrDesc += add_escapes(tok.image); tok = tok.next;
void checkInterpolation() throws ParseException { if (value.length() > 3 && (value.indexOf("${") >= 0 || value.indexOf("#{") >= 0)) { SimpleCharStream scs = new SimpleCharStream(new StringReader(value), beginLine, beginColumn+1, value.length()); FMParserTokenManager token_source = new FMParserTokenManager(scs); token_source.onlyTextOutput = true; FMParser parser = new FMParser(token_source); parser.template = getTemplate(); try { interpolatedOutput = parser.FreeMarkerText(); } catch(ParseException e) { e.setTemplateName(getTemplate().getName()); throw e; } this.constantValue = null; } }
private void renderMessageAndDescription() { String desc = getOrRenderDescription(); String prefix; if (!isInJBossToolsMode()) { prefix = "Syntax error " + _MessageUtil.formatLocationForSimpleParsingError(templateName, lineNumber, columnNumber) + ":\n"; } else { prefix = "[col. " + columnNumber + "] "; } String msg = prefix + desc; desc = msg.substring(prefix.length()); // so we reuse the backing char[] synchronized (this) { message = msg; description = desc; messageAndDescriptionRendered = true; } }
/** * Validates if the given freemarker context is syntactically correct. * * @param freemarkerContent * @throws AMWException * if the template can not be successfully validate. The error message distincts between * parsing exceptions and other (unexpected) potential issues. */ public void validateFreemarkerSyntax(String freemarkerContent) throws AMWException { Objects.requireNonNull(freemarkerContent, "freemarker content must not be null"); Configuration c = new Configuration(); c.setStrictSyntaxMode(true); c.setTagSyntax(Configuration.AUTO_DETECT_TAG_SYNTAX); String templateName = "validation"; StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate(templateName, freemarkerContent); c.setTemplateLoader(stringLoader); try { c.getTemplate(templateName); } catch (ParseException e) { // Validation failed! - was not able to parse the template! throw new AMWException("The template is syntactically incorrect: " + e.getMessage(), e); } catch (IOException e) { // Something else went wrong throw new AMWException("The template can not be validated: " + e.getMessage(), e); } }