http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java index d31c885..119a1b8 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsBasic.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core; -import static org.apache.freemarker.core._CallableUtils.*; +import static org.apache.freemarker.core.util.CallableUtils.*; import java.util.ArrayList; import java.util.StringTokenizer; @@ -34,6 +34,7 @@ import org.apache.freemarker.core.model.TemplateModelException; import org.apache.freemarker.core.model.TemplateScalarModel; import org.apache.freemarker.core.model.impl.SimpleNumber; import org.apache.freemarker.core.model.impl.SimpleScalar; +import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util._StringUtils; class BuiltInsForStringsBasic { @@ -71,7 +72,7 @@ class BuiltInsForStringsBasic { static class containsBI extends ASTExpBuiltIn { - private class BIMethod implements TemplateFunctionModel { + private class BIMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private final String s; @@ -82,7 +83,7 @@ class BuiltInsForStringsBasic { @Override public TemplateModel execute(TemplateModel[] args, CallPlace callPlace, Environment env) throws TemplateException { - return s.contains(_CallableUtils.getStringArgument(args, 0, this)) + return s.contains(CallableUtils.getStringArgument(args, 0, this)) ? TemplateBooleanModel.TRUE : TemplateBooleanModel.FALSE; } @@ -257,6 +258,7 @@ class BuiltInsForStringsBasic { } static class keep_afterBI extends BuiltInForString { + class KeepAfterMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private String s; @@ -367,6 +369,7 @@ class BuiltInsForStringsBasic { } static class keep_beforeBI extends BuiltInForString { + class KeepUntilMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private String s; @@ -414,8 +417,8 @@ class BuiltInsForStringsBasic { } - // TODO static class keep_before_lastBI extends BuiltInForString { + class KeepUntilMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private String s; @@ -597,6 +600,7 @@ class BuiltInsForStringsBasic { } static class split_BI extends BuiltInForString { + class SplitMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private String s; @@ -639,7 +643,7 @@ class BuiltInsForStringsBasic { static class starts_withBI extends BuiltInForString { - private class BIMethod implements TemplateFunctionModel { + private class BIMethod extends BuiltInCallableImpl implements TemplateFunctionModel { private String s; private BIMethod(String s) {
http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java index 7a3fe12..8c6a6df 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsEncoding.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core; -import static org.apache.freemarker.core._CallableUtils.getStringArgument; +import static org.apache.freemarker.core.util.CallableUtils.getStringArgument; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java index ab1dbb3..d2e5f48 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsMisc.java @@ -159,10 +159,10 @@ class BuiltInsForStringsMisc { } else if (model instanceof TemplateScalarModel) { sourceExpr = target; } else { - throw new UnexpectedTypeException( + throw MessageUtils.newUnexpectedOperandTypeException( target, model, "sequence or string", new Class[] { TemplateSequenceModel.class, TemplateScalarModel.class }, - env); + null, env); } String templateSource = sourceExpr.evalAndCoerceToPlainText(env); Template parentTemplate = env.getCurrentTemplate(); @@ -236,7 +236,10 @@ class BuiltInsForStringsMisc { try { return new SimpleNumber(env.getArithmeticEngine().toNumber(s)); } catch (NumberFormatException nfe) { - throw NonNumericalException.newMalformedNumberException(this, s, env); + throw new TemplateException( + new _ErrorDescriptionBuilder( + "Can't convert this string to number: ", new _DelayedJQuote(s)) + .blame(this)); } } } @@ -253,7 +256,7 @@ class BuiltInsForStringsMisc { return new ConstructorFunction(target.evalAndCoerceToPlainText(env), env, target.getTemplate()); } - class ConstructorFunction implements TemplateFunctionModel { + class ConstructorFunction extends BuiltInCallableImpl implements TemplateFunctionModel { private final Class<?> cl; private final Environment env; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java index 6879477..15ea886 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/BuiltInsForStringsRegexp.java @@ -19,7 +19,7 @@ package org.apache.freemarker.core; -import static org.apache.freemarker.core._CallableUtils.*; +import static org.apache.freemarker.core.util.CallableUtils.*; import java.util.ArrayList; import java.util.regex.Matcher; @@ -54,9 +54,11 @@ class BuiltInsForStringsRegexp { return new NativeStringArraySequence(((RegexMatchModel.MatchWithGroups) targetModel).groups); } else { - throw new UnexpectedTypeException(target, targetModel, + throw MessageUtils.newUnexpectedOperandTypeException( + target, targetModel, "regular expression matcher", new Class[] { RegexMatchModel.class, RegexMatchModel.MatchWithGroups.class }, + null, env); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java b/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java index fcf9471..7e7703d 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/Environment.java @@ -19,6 +19,8 @@ package org.apache.freemarker.core; +import static org.apache.freemarker.core.util.CallableUtils.*; + import java.io.IOException; import java.io.PrintWriter; import java.io.Serializable; @@ -64,6 +66,7 @@ import org.apache.freemarker.core.model.impl.SimpleHash; import org.apache.freemarker.core.templateresolver.MalformedTemplateNameException; import org.apache.freemarker.core.templateresolver.TemplateResolver; import org.apache.freemarker.core.templateresolver.impl.DefaultTemplateNameFormat; +import org.apache.freemarker.core.util.CallableUtils; import org.apache.freemarker.core.util.StringToIndexMap; import org.apache.freemarker.core.util._DateUtils; import org.apache.freemarker.core.util._DateUtils.DateToISO8601CalendarFactory; @@ -582,7 +585,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen try { TemplateDirectiveModel nodeProcessor = getNodeProcessor(node); if (nodeProcessor != null) { - _CallableUtils.executeWith0Arguments( + CallableUtils.executeWith0Arguments( nodeProcessor, NonTemplateCallPlace.INSTANCE, out, this); } else if (nodeProcessor == null) { String nodeType = node.getNodeType(); @@ -641,7 +644,7 @@ public final class Environment extends MutableProcessingConfiguration<Environmen void fallback() throws TemplateException, IOException { TemplateDirectiveModel nodeProcessor = getNodeProcessor(currentNodeName, currentNodeNS, nodeNamespaceIndex); if (nodeProcessor != null) { - _CallableUtils.executeWith0Arguments( + CallableUtils.executeWith0Arguments( nodeProcessor, NonTemplateCallPlace.INSTANCE, out, this); } } @@ -2999,22 +3002,23 @@ public final class Environment extends MutableProcessingConfiguration<Environmen } else { // TODO [FM3] Had to give different messages depending on if the argument was omitted, or if // it was null, but this will be fixed with the null related refactoring. - throw new TemplateException(Environment.this, - new _ErrorDescriptionBuilder( - _CallableUtils.getMessageArgumentProblem( - this, argIdx, - " can't be null or omitted.", - isFunction()) - ) - .tip("If the parameter value expression on the caller side is known to " + throw _newNullOrOmittedArgumentException( + argIdx, this, isFunction(), + new Object[] { + "If the parameter value expression on the caller side is known to " + "be legally null/missing, you may want to specify a default " + "value for it on the caller side with the \"!\" operator, like " - + "paramValue!defaultValue.") - .tip("If the parameter was omitted on the caller side, and the omission was " - + "deliberate, you may consider making the parameter optional in the macro " - + "by specifying a default value for it, like <#macro macroName " - + "paramName=defaultExpr>." - ) + + "paramValue!defaultValue.", + new Object[]{ + "If the parameter was omitted on the caller side, and the omission " + + "was deliberate, you may consider making the parameter optional in " + + "the macro by specifying a default value for it, like ", + (isFunction() + ? "<#function functionName(paramName=defaultExpr)>" + : "<#macro macroName paramName=defaultExpr>"), + "." + } + } ); } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java b/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java index 0edbee6..d1db6e6 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/MessageUtils.java @@ -19,7 +19,17 @@ package org.apache.freemarker.core; +import org.apache.freemarker.core.model.TemplateBooleanModel; +import org.apache.freemarker.core.model.TemplateCollectionModel; +import org.apache.freemarker.core.model.TemplateDateModel; +import org.apache.freemarker.core.model.TemplateMarkupOutputModel; +import org.apache.freemarker.core.model.TemplateModel; import org.apache.freemarker.core.model.TemplateModelException; +import org.apache.freemarker.core.model.TemplateNumberModel; +import org.apache.freemarker.core.model.TemplateScalarModel; +import org.apache.freemarker.core.model.TemplateSequenceModel; +import org.apache.freemarker.core.util.BugException; +import org.apache.freemarker.core.util.TemplateLanguageUtils; import org.apache.freemarker.core.util._StringUtils; import org.apache.freemarker.core.valueformat.TemplateDateFormat; import org.apache.freemarker.core.valueformat.TemplateNumberFormat; @@ -52,6 +62,29 @@ class MessageUtils { static final String EMBEDDED_MESSAGE_END = "\n---end-message---"; static final String ERROR_MESSAGE_HR = "----"; + + static final String STRING_COERCABLE_TYPES_DESC + = "string or something automatically convertible to string (number, date or boolean)"; + static final Class[] EXPECTED_TYPES_STRING_COERCABLE = new Class[] { + TemplateScalarModel.class, TemplateNumberModel.class, TemplateDateModel.class, TemplateBooleanModel.class + }; + + static final String STRING_COERCABLE_TYPES_OR_TOM_DESC + = STRING_COERCABLE_TYPES_DESC + ", or \"template output\""; + static final Class[] EXPECTED_TYPES_STRING_COERCABLE_TYPES_AND_TOM; + static { + EXPECTED_TYPES_STRING_COERCABLE_TYPES_AND_TOM = new Class[EXPECTED_TYPES_STRING_COERCABLE.length + 1]; + int i; + for (i = 0; i < EXPECTED_TYPES_STRING_COERCABLE.length; i++) { + EXPECTED_TYPES_STRING_COERCABLE_TYPES_AND_TOM[i] = EXPECTED_TYPES_STRING_COERCABLE[i]; + } + EXPECTED_TYPES_STRING_COERCABLE_TYPES_AND_TOM[i] = TemplateMarkupOutputModel.class; + } + + static final String SEQUENCE_OR_COLLECTION = "sequence or collection"; + static final Class[] EXPECTED_TYPES_SEQUENCE_OR_COLLECTION = new Class[] { + TemplateSequenceModel.class, TemplateCollectionModel.class + }; // Can't be instantiated private MessageUtils() { } @@ -178,9 +211,9 @@ class MessageUtils { static TemplateModelException newCantFormatUnknownTypeDateException( ASTExpression dateSourceExpr, UnknownDateTypeFormattingUnsupportedException cause) { return new _TemplateModelException(cause, null, new _ErrorDescriptionBuilder( - MessageUtils.UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) + UNKNOWN_DATE_TO_STRING_ERROR_MESSAGE) .blame(dateSourceExpr) - .tips(MessageUtils.UNKNOWN_DATE_TO_STRING_TIPS)); + .tips(UNKNOWN_DATE_TO_STRING_TIPS)); } static TemplateException newCantFormatDateException(TemplateDateFormat format, ASTExpression dataSrcExp, @@ -235,5 +268,83 @@ class MessageUtils { } } } - + + static TemplateException newUnexpectedOperandTypeException( + ASTExpression blamed, TemplateModel model, Class<? extends TemplateModel> expectedType, Environment env) + throws InvalidReferenceException { + return newUnexpectedOperandTypeException(blamed, model, null, new Class[] { expectedType }, null, env); + } + + static TemplateException newUnexpectedOperandTypeException( + ASTExpression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Object[] tips, + Environment env) + throws InvalidReferenceException { + return new TemplateException(null, env, blamed, newUnexpectedOperandTypeDescriptionBuilder( + blamed, + null, + model, expectedTypesDesc, expectedTypes, env) + .tips(tips)); + } + + static TemplateException newUnexpectedAssignmentTargetTypeException( + String blamedAssignmentTargetVarName, TemplateModel model, Class<? extends TemplateModel> expectedType, + Environment env) + throws InvalidReferenceException { + return newUnexpectedAssignmentTargetTypeException( + blamedAssignmentTargetVarName, model, null, new Class[] { expectedType }, null, env); + } + + /** + * Used for assignments that use {@code +=} and such. + */ + static TemplateException newUnexpectedAssignmentTargetTypeException( + String blamedAssignmentTargetVarName, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, + Object[] tips, + Environment env) + throws InvalidReferenceException { + return new TemplateException(null, env, null, newUnexpectedOperandTypeDescriptionBuilder( + null, + blamedAssignmentTargetVarName, + model, expectedTypesDesc, expectedTypes, env).tips(tips)); + } + + private static _ErrorDescriptionBuilder newUnexpectedOperandTypeDescriptionBuilder( + ASTExpression blamed, String blamedAssignmentTargetVarName, + TemplateModel model, String expectedTypesDesc, Class<? extends TemplateModel>[] expectedTypes, Environment env) + throws InvalidReferenceException { + if (model == null) { + throw InvalidReferenceException.getInstance(blamed, env); + } + + if (expectedTypesDesc == null) { + if (expectedTypes.length != 1) { + throw new BugException("Can't generate expectedTypesDesc"); + } + expectedTypesDesc = TemplateLanguageUtils.getTypeName(expectedTypes[0]); + } + _ErrorDescriptionBuilder errorDescBuilder = new _ErrorDescriptionBuilder( + "Expected ", new _DelayedAOrAn(expectedTypesDesc), ", but ", + ( + blamedAssignmentTargetVarName != null + ? new Object[] { + "assignment target variable ", + new _DelayedJQuote(blamedAssignmentTargetVarName) } + : blamed != null + ? "this" + : "the expression" + ), + " has evaluated to ", + new _DelayedAOrAn(new _DelayedTemplateLanguageTypeDescription(model)), + (blamed != null ? ":" : ".") + ) + .blame(blamed).showBlamer(true); + if (model instanceof _UnexpectedTypeErrorExplainerTemplateModel) { + Object[] tip = ((_UnexpectedTypeErrorExplainerTemplateModel) model).explainTypeError(expectedTypes); + if (tip != null) { + errorDescBuilder.tip(tip); + } + } + return errorDescBuilder; + } + } http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonBooleanException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonBooleanException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonBooleanException.java deleted file mode 100644 index 3844fd0..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonBooleanException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateBooleanModel} value was expected, but the value had a different type. - */ -public class NonBooleanException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateBooleanModel.class }; - - public NonBooleanException(Environment env) { - super(env, "Expecting boolean value here"); - } - - public NonBooleanException(String description, Environment env) { - super(env, description); - } - - NonBooleanException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonBooleanException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "boolean", EXPECTED_TYPES, env); - } - - NonBooleanException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "boolean", EXPECTED_TYPES, tip, env); - } - - NonBooleanException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "boolean", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonDateException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonDateException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonDateException.java deleted file mode 100644 index 2e63e48..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonDateException.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateDateModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateDateModel} value was expected, but the value had a different type. - */ -public class NonDateException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateDateModel.class }; - - public NonDateException(Environment env) { - super(env, "Expecting date/time value here"); - } - - public NonDateException(String description, Environment env) { - super(env, description); - } - - NonDateException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "date/time", EXPECTED_TYPES, env); - } - - NonDateException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "date/time", EXPECTED_TYPES, tip, env); - } - - NonDateException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "date/time", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonDirectiveException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonDirectiveException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonDirectiveException.java deleted file mode 100644 index 2053361..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonDirectiveException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateDirectiveModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateDirectiveModel} was expected, but the value had a different type. - */ -class NonDirectiveException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { - TemplateDirectiveModel.class, ASTDirMacroOrFunction.class }; - - public NonDirectiveException(Environment env) { - super(env, "Expecting user-defined directive, transform or macro value here"); - } - - public NonDirectiveException(String description, Environment env) { - super(env, description); - } - - NonDirectiveException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonDirectiveException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "user-defined directive, transform or macro", EXPECTED_TYPES, env); - } - - NonDirectiveException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "user-defined directive, transform or macro", EXPECTED_TYPES, tip, env); - } - - NonDirectiveException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "user-defined directive, transform or macro", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedHashException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedHashException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedHashException.java deleted file mode 100644 index 5614b23..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedHashException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateHashModelEx; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateHashModelEx} value was expected, but the value had a different type. - */ -public class NonExtendedHashException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateHashModelEx.class }; - - public NonExtendedHashException(Environment env) { - super(env, "Expecting extended hash value here"); - } - - public NonExtendedHashException(String description, Environment env) { - super(env, description); - } - - NonExtendedHashException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonExtendedHashException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "extended hash", EXPECTED_TYPES, env); - } - - NonExtendedHashException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "extended hash", EXPECTED_TYPES, tip, env); - } - - NonExtendedHashException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "extended hash", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedNodeException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedNodeException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedNodeException.java deleted file mode 100644 index 4c69b05..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonExtendedNodeException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNodeModelEx; - -/** - * Indicates that a {@link TemplateNodeModelEx} value was expected, but the value had a different type. - */ -public class NonExtendedNodeException extends UnexpectedTypeException { - - private static final Class<?>[] EXPECTED_TYPES = new Class[] { TemplateNodeModelEx.class }; - - public NonExtendedNodeException(Environment env) { - super(env, "Expecting extended node value here"); - } - - public NonExtendedNodeException(String description, Environment env) { - super(env, description); - } - - NonExtendedNodeException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonExtendedNodeException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "extended node", EXPECTED_TYPES, env); - } - - NonExtendedNodeException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "extended node", EXPECTED_TYPES, tip, env); - } - - NonExtendedNodeException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "extended node", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonFunctionException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonFunctionException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonFunctionException.java deleted file mode 100644 index 2ae7fdd..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonFunctionException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateFunctionModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateFunctionModel} value was expected, but the value had a different type. - */ -public class NonFunctionException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateFunctionModel.class }; - - public NonFunctionException(Environment env) { - super(env, "Expecting method value here"); - } - - public NonFunctionException(String description, Environment env) { - super(env, description); - } - - NonFunctionException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonFunctionException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "function", EXPECTED_TYPES, env); - } - - NonFunctionException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "function", EXPECTED_TYPES, tip, env); - } - - NonFunctionException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "function", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonHashException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonHashException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonHashException.java deleted file mode 100644 index eb56312..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonHashException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateHashModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateHashModel} value was expected, but the value had a different type. - */ -public class NonHashException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateHashModel.class }; - - public NonHashException(Environment env) { - super(env, "Expecting hash value here"); - } - - public NonHashException(String description, Environment env) { - super(env, description); - } - - NonHashException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonHashException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "hash", EXPECTED_TYPES, env); - } - - NonHashException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "hash", EXPECTED_TYPES, tip, env); - } - - NonHashException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "hash", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonMarkupOutputException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonMarkupOutputException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonMarkupOutputException.java deleted file mode 100644 index cdc0728..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonMarkupOutputException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateMarkupOutputModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link TemplateMarkupOutputModel} value was expected, but the value had a different type. - */ -public class NonMarkupOutputException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateMarkupOutputModel.class }; - - public NonMarkupOutputException(Environment env) { - super(env, "Expecting markup output value here"); - } - - public NonMarkupOutputException(String description, Environment env) { - super(env, description); - } - - NonMarkupOutputException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonMarkupOutputException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "markup output", EXPECTED_TYPES, env); - } - - NonMarkupOutputException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "markup output", EXPECTED_TYPES, tip, env); - } - - NonMarkupOutputException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "markup output", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonNamespaceException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNamespaceException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonNamespaceException.java deleted file mode 100644 index 1433e02..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNamespaceException.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateModel; - -/** - * Indicates that a {@link Environment.Namespace} value was expected, but the value had a different type. - */ -class NonNamespaceException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { Environment.Namespace.class }; - - public NonNamespaceException(Environment env) { - super(env, "Expecting namespace value here"); - } - - public NonNamespaceException(String description, Environment env) { - super(env, description); - } - - NonNamespaceException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonNamespaceException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "namespace", EXPECTED_TYPES, env); - } - - NonNamespaceException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "namespace", EXPECTED_TYPES, tip, env); - } - - NonNamespaceException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "namespace", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonNodeException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNodeException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonNodeException.java deleted file mode 100644 index f6e693f..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNodeException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNodeModel; - -/** - * Indicates that a {@link TemplateNodeModel} value was expected, but the value had a different type. - */ -public class NonNodeException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateNodeModel.class }; - - public NonNodeException(Environment env) { - super(env, "Expecting node value here"); - } - - public NonNodeException(String description, Environment env) { - super(env, description); - } - - NonNodeException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonNodeException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "node", EXPECTED_TYPES, env); - } - - NonNodeException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "node", EXPECTED_TYPES, tip, env); - } - - NonNodeException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "node", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonNumericalException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNumericalException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonNumericalException.java deleted file mode 100644 index e943bad..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonNumericalException.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateCallableModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNumberModel; - -/** - * Indicates that a {@link TemplateNumberModel} value was expected, but the value had a different type. - */ -public class NonNumericalException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateNumberModel.class }; - - public NonNumericalException(Environment env) { - super(env, "Expecting numerical value here"); - } - - public NonNumericalException(String description, Environment env) { - super(env, description); - } - - NonNumericalException(_ErrorDescriptionBuilder description, Environment env) { - super(env, description); - } - - NonNumericalException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "number", EXPECTED_TYPES, env); - } - - NonNumericalException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "number", EXPECTED_TYPES, tip, env); - } - - NonNumericalException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "number", EXPECTED_TYPES, tips, env); - } - - NonNumericalException( - String assignmentTargetVarName, TemplateModel model, String[] tips, Environment env) - throws InvalidReferenceException { - super(assignmentTargetVarName, model, "number", EXPECTED_TYPES, tips, env); - } - - - NonNumericalException( - TemplateCallableModel callableModel, int argArrayIndex, - TemplateModel model, String[] tips, Environment env) - throws InvalidReferenceException { - super(callableModel, argArrayIndex, model, "number", EXPECTED_TYPES, tips, env); - } - - static NonNumericalException newMalformedNumberException(ASTExpression blamed, String text, Environment env) { - return new NonNumericalException( - new _ErrorDescriptionBuilder("Can't convert this string to number: ", new _DelayedJQuote(text)) - .blame(blamed), - env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceException.java deleted file mode 100644 index 738bb35..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceException.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateSequenceModel; - -/** - * Indicates that a {@link TemplateSequenceModel} value was expected, but the value had a different type. - */ -public class NonSequenceException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { TemplateSequenceModel.class }; - - public NonSequenceException(Environment env) { - super(env, "Expecting sequence value here"); - } - - public NonSequenceException(String description, Environment env) { - super(env, description); - } - - NonSequenceException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonSequenceException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, "sequence", EXPECTED_TYPES, env); - } - - NonSequenceException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, "sequence", EXPECTED_TYPES, tip, env); - } - - NonSequenceException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "sequence", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceOrCollectionException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceOrCollectionException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceOrCollectionException.java deleted file mode 100644 index c229808..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonSequenceOrCollectionException.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateCollectionModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateSequenceModel; -import org.apache.freemarker.core.model.WrapperTemplateModel; -import org.apache.freemarker.core.util._CollectionUtils; - -/** - * Indicates that a {@link TemplateSequenceModel} or {@link TemplateCollectionModel} value was expected, but the value - * had a different type. - */ -public class NonSequenceOrCollectionException extends UnexpectedTypeException { - - private static final Class[] EXPECTED_TYPES = new Class[] { - TemplateSequenceModel.class, TemplateCollectionModel.class - }; - private static final String ITERABLE_SUPPORT_HINT = "The problematic value is a java.lang.Iterable. Using " - + "DefaultObjectWrapper(..., iterableSupport=true) as the objectWrapper setting of the FreeMarker " - + "configuration should solve this."; - - public NonSequenceOrCollectionException(Environment env) { - super(env, "Expecting sequence or collection value here"); - } - - public NonSequenceOrCollectionException(String description, Environment env) { - super(env, description); - } - - NonSequenceOrCollectionException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonSequenceOrCollectionException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - this(blamed, model, _CollectionUtils.EMPTY_OBJECT_ARRAY, env); - } - - NonSequenceOrCollectionException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - this(blamed, model, new Object[] { tip }, env); - } - - NonSequenceOrCollectionException( - ASTExpression blamed, TemplateModel model, Object[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, "sequence or collection", EXPECTED_TYPES, extendTipsIfIterable(model, tips), env); - } - - private static Object[] extendTipsIfIterable(TemplateModel model, Object[] tips) { - if (isWrappedIterable(model)) { - final int tipsLen = tips != null ? tips.length : 0; - Object[] extendedTips = new Object[tipsLen + 1]; - for (int i = 0; i < tipsLen; i++) { - extendedTips[i] = tips[i]; - } - extendedTips[tipsLen] = ITERABLE_SUPPORT_HINT; - return extendedTips; - } else { - return tips; - } - } - - public static boolean isWrappedIterable(TemplateModel model) { - return model instanceof WrapperTemplateModel - && ((WrapperTemplateModel) model).getWrappedObject() instanceof Iterable; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringException.java deleted file mode 100644 index ec02f73..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringException.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateBooleanModel; -import org.apache.freemarker.core.model.TemplateCallableModel; -import org.apache.freemarker.core.model.TemplateDateModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateNumberModel; -import org.apache.freemarker.core.model.TemplateScalarModel; - -/** - * Indicates that a {@link TemplateScalarModel} value was expected (or maybe something that can be automatically coerced - * to that), but the value had a different type. - */ -public class NonStringException extends UnexpectedTypeException { - - static final String STRING_COERCABLE_TYPES_DESC - = "string or something automatically convertible to string (number, date or boolean)"; - - static final Class[] STRING_COERCABLE_TYPES = new Class[] { - TemplateScalarModel.class, TemplateNumberModel.class, TemplateDateModel.class, TemplateBooleanModel.class - }; - - private static final Class<?>[] EXPECTED_TYPES = { TemplateScalarModel.class }; - - private static final String DEFAULT_DESCRIPTION - = "Expecting " + NonStringException.STRING_COERCABLE_TYPES_DESC + " value here"; - - public NonStringException(Environment env) { - super(env, DEFAULT_DESCRIPTION); - } - - public NonStringException(String description, Environment env) { - super(env, description); - } - - NonStringException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonStringException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, NonStringException.STRING_COERCABLE_TYPES_DESC, STRING_COERCABLE_TYPES, env); - } - - NonStringException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, NonStringException.STRING_COERCABLE_TYPES_DESC, STRING_COERCABLE_TYPES, tip, env); - } - - NonStringException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, NonStringException.STRING_COERCABLE_TYPES_DESC, STRING_COERCABLE_TYPES, tips, env); - } - - NonStringException( - TemplateCallableModel callableModel, int argArrayIndex, - TemplateModel model, String[] tips, Environment env) - throws InvalidReferenceException { - super(callableModel, argArrayIndex, model, "string", EXPECTED_TYPES, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringOrTemplateOutputException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringOrTemplateOutputException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringOrTemplateOutputException.java deleted file mode 100644 index ddeb811..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/NonStringOrTemplateOutputException.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateMarkupOutputModel; -import org.apache.freemarker.core.model.TemplateModel; -import org.apache.freemarker.core.model.TemplateScalarModel; - -/** - * Indicates that a {@link TemplateScalarModel} (or maybe something that can be automatically coerced - * to that) or {@link TemplateMarkupOutputModel} value was expected, but the value had a different type. - */ -public class NonStringOrTemplateOutputException extends UnexpectedTypeException { - - static final String STRING_COERCABLE_TYPES_OR_TOM_DESC - = NonStringException.STRING_COERCABLE_TYPES_DESC + ", or \"template output\""; - - static final Class[] STRING_COERCABLE_TYPES_AND_TOM; - static { - STRING_COERCABLE_TYPES_AND_TOM = new Class[NonStringException.STRING_COERCABLE_TYPES.length + 1]; - int i; - for (i = 0; i < NonStringException.STRING_COERCABLE_TYPES.length; i++) { - STRING_COERCABLE_TYPES_AND_TOM[i] = NonStringException.STRING_COERCABLE_TYPES[i]; - } - STRING_COERCABLE_TYPES_AND_TOM[i] = TemplateMarkupOutputModel.class; - } - - private static final String DEFAULT_DESCRIPTION - = "Expecting " + NonStringOrTemplateOutputException.STRING_COERCABLE_TYPES_OR_TOM_DESC + " value here"; - - public NonStringOrTemplateOutputException(Environment env) { - super(env, DEFAULT_DESCRIPTION); - } - - public NonStringOrTemplateOutputException(String description, Environment env) { - super(env, description); - } - - NonStringOrTemplateOutputException(Environment env, _ErrorDescriptionBuilder description) { - super(env, description); - } - - NonStringOrTemplateOutputException( - ASTExpression blamed, TemplateModel model, Environment env) - throws InvalidReferenceException { - super(blamed, model, NonStringOrTemplateOutputException.STRING_COERCABLE_TYPES_OR_TOM_DESC, STRING_COERCABLE_TYPES_AND_TOM, env); - } - - NonStringOrTemplateOutputException( - ASTExpression blamed, TemplateModel model, String tip, - Environment env) - throws InvalidReferenceException { - super(blamed, model, NonStringOrTemplateOutputException.STRING_COERCABLE_TYPES_OR_TOM_DESC, STRING_COERCABLE_TYPES_AND_TOM, tip, env); - } - - NonStringOrTemplateOutputException( - ASTExpression blamed, TemplateModel model, String[] tips, Environment env) throws InvalidReferenceException { - super(blamed, model, NonStringOrTemplateOutputException.STRING_COERCABLE_TYPES_OR_TOM_DESC, STRING_COERCABLE_TYPES_AND_TOM, tips, env); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateException.java index 06cb20f..bcbb645 100644 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateException.java +++ b/freemarker-core/src/main/java/org/apache/freemarker/core/TemplateException.java @@ -39,6 +39,7 @@ public class TemplateException extends Exception { = "FTL stack trace (\"~\" means nesting-related):"; // Set in constructor: + // TODO [FM3] These all must be final, or else tha class is not thread safe private transient _ErrorDescriptionBuilder descriptionBuilder; private final transient Environment env; private final transient ASTExpression blamedExpression; http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f231e64f/freemarker-core/src/main/java/org/apache/freemarker/core/UnexpectedTypeException.java ---------------------------------------------------------------------- diff --git a/freemarker-core/src/main/java/org/apache/freemarker/core/UnexpectedTypeException.java b/freemarker-core/src/main/java/org/apache/freemarker/core/UnexpectedTypeException.java deleted file mode 100644 index 10401fd..0000000 --- a/freemarker-core/src/main/java/org/apache/freemarker/core/UnexpectedTypeException.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.freemarker.core; - -import org.apache.freemarker.core.model.TemplateCallableModel; -import org.apache.freemarker.core.model.TemplateModel; - -/** - * The type of a value differs from what was expected. - */ -public class UnexpectedTypeException extends TemplateException { - - public UnexpectedTypeException(Environment env, String description) { - super(description, env); - } - - UnexpectedTypeException(Environment env, _ErrorDescriptionBuilder description) { - super(null, env, null, description); - } - - UnexpectedTypeException( - ASTExpression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDescriptionBuilder( - blamed, - null, - null, -1, - model, expectedTypesDesc, expectedTypes, - env)); - } - - UnexpectedTypeException( - ASTExpression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, String tip, - Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDescriptionBuilder( - blamed, - null, - null, -1, - model, expectedTypesDesc, expectedTypes, - env) - .tip(tip)); - } - - UnexpectedTypeException( - ASTExpression blamed, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, Object[] tips, - Environment env) - throws InvalidReferenceException { - super(null, env, blamed, newDescriptionBuilder( - blamed, - null, - null, -1, - model, expectedTypesDesc, expectedTypes, env) - .tips(tips)); - } - - /** - * Used for assignments that use {@code +=} and such. - */ - UnexpectedTypeException( - String blamedAssignmentTargetVarName, TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, - Object[] tips, - Environment env) - throws InvalidReferenceException { - super(null, env, null, newDescriptionBuilder( - null, - blamedAssignmentTargetVarName, - null, -1, - model, expectedTypesDesc, expectedTypes, env).tips(tips)); - } - - /** - * Used when the value of a directive/function argument has a different type than that the directive/function - * expects. - */ - UnexpectedTypeException( - TemplateCallableModel callableModel, int argArrayIndex, - TemplateModel model, String expectedTypesDesc, Class[] expectedTypes, - Object[] tips, - Environment env) - throws InvalidReferenceException { - super(null, env, null, newDescriptionBuilder( - null, - null, - callableModel, argArrayIndex, - model, - expectedTypesDesc, expectedTypes, env).tips(tips)); - } - - private static _ErrorDescriptionBuilder newDescriptionBuilder( - ASTExpression blamed, String blamedAssignmentTargetVarName, - TemplateCallableModel callableModel, int argArrayIndex, - TemplateModel model, String expectedTypesDesc, Class<? extends TemplateModel>[] expectedTypes, Environment env) - throws InvalidReferenceException { - if (model == null) { - throw InvalidReferenceException.getInstance(blamed, env); - } - - _ErrorDescriptionBuilder errorDescBuilder = new _ErrorDescriptionBuilder( - callableModel == null - ? unexpectedTypeErrorDescription( - expectedTypesDesc, - blamed, - blamedAssignmentTargetVarName, - model) - : unexpectedTypeErrorDescription( - expectedTypesDesc, - blamed, - callableModel, argArrayIndex, - model)) - .blame(blamed).showBlamer(true); - if (model instanceof _UnexpectedTypeErrorExplainerTemplateModel) { - Object[] tip = ((_UnexpectedTypeErrorExplainerTemplateModel) model).explainTypeError(expectedTypes); - if (tip != null) { - errorDescBuilder.tip(tip); - } - } - return errorDescBuilder; - } - - private static Object[] unexpectedTypeErrorDescription( - String expectedTypesDesc, - ASTExpression blamed, - String blamedAssignmentTargetVarName, - TemplateModel model) { - return new Object[] { - "Expected ", new _DelayedAOrAn(expectedTypesDesc), ", but ", ( - blamedAssignmentTargetVarName != null - ? new Object[] { - "assignment target variable ", - new _DelayedJQuote(blamedAssignmentTargetVarName) } - : blamed != null - ? "this" - : "the expression" - ), - " has evaluated to ", - new _DelayedAOrAn(new _DelayedTemplateLanguageTypeDescription(model)), - (blamed != null ? ":" : ".")}; - } - - private static Object[] unexpectedTypeErrorDescription( - String expectedTypesDesc, - ASTExpression blamed, - TemplateCallableModel callableModel, int argArrayIndex, - TemplateModel actualValue) { - // TODO - return new Object[]{ - blamed, " expects ", new _DelayedAOrAn(expectedTypesDesc), " as its ", argArrayIndex, " arg, but it " - + "was " + new _DelayedAOrAn(new _DelayedTemplateLanguageTypeDescription(actualValue)), - (blamed != null ? ":" : ".") - }; - } - -}
