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.SystemService; 024import org.androidtransfuse.model.InjectionNode; 025import org.androidtransfuse.model.InjectionSignature; 026import org.androidtransfuse.util.AndroidLiterals; 027 028import javax.inject.Inject; 029 030/** 031 * @author John Ericksen 032 */ 033public class SystemServiceBindingInjectionNodeBuilder extends InjectionNodeBuilderSingleAnnotationAdapter { 034 035 private final InjectionPointFactory injectionPointFactory; 036 private final VariableInjectionBuilderFactory variableInjectionBuilderFactory; 037 private final Analyzer analyzer; 038 039 @Inject 040 public SystemServiceBindingInjectionNodeBuilder(InjectionPointFactory injectionPointFactory, 041 VariableInjectionBuilderFactory variableInjectionBuilderFactory, 042 Analyzer analyzer) { 043 super(SystemService.class); 044 this.injectionPointFactory = injectionPointFactory; 045 this.variableInjectionBuilderFactory = variableInjectionBuilderFactory; 046 this.analyzer = analyzer; 047 } 048 049 @Override 050 public InjectionNode buildInjectionNode(ASTBase target, InjectionSignature signature, AnalysisContext context, ASTAnnotation annotation) { 051 String systemService = annotation.getProperty("value", String.class); 052 053 InjectionNode injectionNode = analyzer.analyze(signature, context); 054 055 InjectionNode contextInjectionNode = injectionPointFactory.buildInjectionNode(AndroidLiterals.CONTEXT, context); 056 057 injectionNode.addAspect(VariableBuilder.class, 058 variableInjectionBuilderFactory.buildSystemServiceVariableBuilder( 059 systemService, 060 contextInjectionNode)); 061 062 return injectionNode; 063 } 064}