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 org.androidtransfuse.adapter.ASTAnnotation;
019import org.androidtransfuse.adapter.ASTBase;
020import org.androidtransfuse.analysis.AnalysisContext;
021import org.androidtransfuse.analysis.Analyzer;
022import org.androidtransfuse.analysis.InjectionPointFactory;
023import org.androidtransfuse.annotations.View;
024import org.androidtransfuse.gen.ClassGenerationUtil;
025import org.androidtransfuse.model.InjectionNode;
026import org.androidtransfuse.model.InjectionSignature;
027import org.androidtransfuse.util.AndroidLiterals;
028
029import javax.inject.Inject;
030
031/**
032 * @author John Ericksen
033 */
034public class FragmentViewInjectionNodeBuilder extends InjectionNodeBuilderSingleAnnotationAdapter {
035
036    private final ClassGenerationUtil generationUtil;
037    private final InjectionPointFactory injectionPointFactory;
038    private final VariableInjectionBuilderFactory variableInjectionBuilderFactory;
039    private final Analyzer analyzer;
040
041    @Inject
042    public FragmentViewInjectionNodeBuilder(ClassGenerationUtil generationUtil,
043                                            InjectionPointFactory injectionPointFactory,
044                                            VariableInjectionBuilderFactory variableInjectionBuilderFactory,
045                                            Analyzer analyzer) {
046        super(View.class);
047        this.generationUtil = generationUtil;
048        this.injectionPointFactory = injectionPointFactory;
049        this.variableInjectionBuilderFactory = variableInjectionBuilderFactory;
050        this.analyzer = analyzer;
051    }
052
053    @Override
054    public InjectionNode buildInjectionNode(ASTBase target, InjectionSignature signature, AnalysisContext context, ASTAnnotation annotation) {
055        Integer viewId = annotation.getProperty("value", Integer.class);
056        String viewTag = annotation.getProperty("tag", String.class);
057
058        InjectionNode injectionNode = analyzer.analyze(signature, context);
059
060        InjectionNode viewInjectionNode = injectionPointFactory.buildInjectionNode(AndroidLiterals.VIEW, context);
061
062        injectionNode.addAspect(VariableBuilder.class, variableInjectionBuilderFactory.buildFragmentViewVariableBuilder(viewId, viewTag, viewInjectionNode, generationUtil.type(signature.getType())));
063
064        return injectionNode;
065    }
066}