/*
 * Copyright (c) 2015-2019 Dzikoysk
 *
 * Licensed 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.panda_lang.panda.framework.language.resource.parsers.container.branching;

import org.jetbrains.annotations.Nullable;
import org.panda_lang.panda.framework.design.architecture.statement.Container;
import org.panda_lang.panda.framework.design.interpreter.parser.ParserData;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.BootstrapComponents;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.BootstrapParserBuilder;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.UnifiedParserBootstrap;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.Autowired;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.AutowiredParameters;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.Component;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.Src;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.Type;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.handlers.TokenHandler;
import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.interceptor.LinearPatternInterceptor;
import org.panda_lang.panda.framework.design.interpreter.token.snippet.Snippet;
import org.panda_lang.panda.framework.design.resource.parsers.ParserRegistration;
import org.panda_lang.panda.framework.design.runtime.expression.Expression;
import org.panda_lang.panda.framework.language.architecture.dynamic.branching.Return;
import org.panda_lang.panda.framework.language.interpreter.parser.PandaPipelines;
import org.panda_lang.panda.framework.language.resource.syntax.keyword.Keywords;

@ParserRegistration(target = PandaPipelines.CONTAINER_LABEL)
public class ReturnParser extends UnifiedParserBootstrap {

    @Override
    protected BootstrapParserBuilder initialize(ParserData data, BootstrapParserBuilder defaultBuilder) {
        return defaultBuilder
                .handler(new TokenHandler(Keywords.RETURN))
                .interceptor(new LinearPatternInterceptor())
                .pattern("return &value:*=expression");
    }

    @Autowired
    @AutowiredParameters(value = {
            @Type(with = Component.class),
            @Type(with = Component.class, value = BootstrapComponents.CURRENT_SOURCE_LABEL),
            @Type(with = Src.class, value = "value")
    })
    public void parse(Container container, Snippet source, @Nullable Expression value) {
        Return returnStatement = new Return(value);
        returnStatement.setLocation(source.getCurrentLocation());
        container.addStatement(returnStatement);
    }

}

@@ -1272,115 +1272,8 @@
 ed;%0A
-import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.AutowiredParameters;%0A
 impo
@@ -1460,100 +1460,8 @@
 rc;%0A
-import org.panda_lang.panda.framework.design.interpreter.parser.bootstrap.annotations.Type;%0A
 impo
@@ -2631,488 +2631,260 @@
     
-@AutowiredParameters(value = %7B%0A            @Type(with = Component.class),%0A            @Type(with = Component.class, value = BootstrapComponents.CURRENT_SOURCE_LABEL),%0A            @Type(with = Src.class, value = %22value%22)%0A    %7D)%0A    public void parse(Container container, Snippet source, @Nullable Expression value) %7B%0A        Return returnStatement = new Return(value);%0A        returnStatement.setLocation(source.getCurrentLocation());%0A        container.addStatement(returnStatement
+public void parse(@Component Container container, @Component(BootstrapComponents.CURRENT_SOURCE_LABEL) Snippet source, @Src(%22value%22) @Nullable Expression value) %7B%0A        BranchingUtils.parseBranchingStatement(source, container, () -%3E new Return(value)
 );%0A 

Simplify the Return parser