001/**
002 * Copyright 2013 John Ericksen
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.androidtransfuse.gen.variableBuilder;
017
018import com.sun.codemodel.JExpression;
019import org.androidtransfuse.adapter.ASTType;
020import org.androidtransfuse.gen.InjectionBuilderContext;
021import org.androidtransfuse.gen.InjectionExpressionBuilder;
022import org.androidtransfuse.gen.variableDecorator.TypedExpressionFactory;
023import org.androidtransfuse.model.InjectionNode;
024import org.androidtransfuse.model.TypedExpression;
025
026import javax.inject.Inject;
027
028/**
029 * @author John Ericksen
030 */
031public class DependentVariableBuilderWrapper extends ConsistentTypeVariableBuilder {
032
033    private final InjectionExpressionBuilder injectionExpressionBuilder;
034    private final InjectionNode dependency;
035    private final DependentVariableBuilder dependentVariableBuilder;
036
037    @Inject
038    public DependentVariableBuilderWrapper(/*@Assisted*/ InjectionNode dependency,
039                                           /*@Assisted*/ DependentVariableBuilder dependentVariableBuilder,
040                                           /*@Assisted*/ ASTType type,
041                                           TypedExpressionFactory typedExpressionFactory,
042                                           InjectionExpressionBuilder injectionExpressionBuilder) {
043        super(type, typedExpressionFactory);
044        this.dependency = dependency;
045        this.dependentVariableBuilder = dependentVariableBuilder;
046        this.injectionExpressionBuilder = injectionExpressionBuilder;
047    }
048
049    @Override
050    public JExpression buildExpression(InjectionBuilderContext context, InjectionNode injectionNode) {
051        TypedExpression dependentExpression = injectionExpressionBuilder.buildVariable(context, dependency);
052
053        return dependentVariableBuilder.buildVariable(dependentExpression.getExpression());
054    }
055}