public PluginInvoke invoke()

in src/main/java/org/apache/sling/scripting/sightly/impl/plugin/TestPlugin.java [46:88]


    public PluginInvoke invoke(final Expression expressionNode, final PluginCallInfo callInfo, final CompilerContext compilerContext) {

        return new DefaultPluginInvoke() {

            private boolean globalBinding;

            @Override
            public void beforeElement(PushStream stream, String tagName) {
                String variableName = decodeVariableName(callInfo);
                ExpressionNode root = expressionNode.getRoot();
                boolean constantValueComparison =
                        root instanceof Atom && !(root instanceof Identifier) ||
                        root instanceof NullLiteral ||
                        root instanceof ArrayLiteral ||
                        root instanceof MapLiteral;
                if (!constantValueComparison && root instanceof BinaryOperation) {
                    constantValueComparison = ((BinaryOperation) root).getOperator() == BinaryOperator.CONCATENATE;
                }
                if (constantValueComparison) {
                    stream.warn(new PushStream.StreamMessage("data-sly-test: redundant constant value comparison",
                            expressionNode.getRawText()));
                }
                globalBinding = variableName != null;
                if (variableName == null) {
                    variableName = compilerContext.generateVariable("testVariable");
                }
                if (globalBinding) {
                    stream.write(new VariableBinding.Global(variableName, root));
                } else {
                    stream.write(new VariableBinding.Start(variableName, root));
                }
                stream.write(new Conditional.Start(variableName, true));
            }

            @Override
            public void afterElement(PushStream stream) {
                stream.write(Conditional.END);
                if (!globalBinding) {
                    stream.write(VariableBinding.END);
                }
            }
        };
    }