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.analysis.module; 017 018import org.androidtransfuse.adapter.ASTAnnotation; 019import org.androidtransfuse.adapter.ASTType; 020import org.androidtransfuse.analysis.repository.InjectionNodeBuilderRepository; 021import org.androidtransfuse.model.manifest.UsesFeature; 022import org.androidtransfuse.processor.ManifestManager; 023 024import javax.inject.Inject; 025 026import static org.androidtransfuse.util.AnnotationUtil.checkBlank; 027import static org.androidtransfuse.util.AnnotationUtil.checkDefault; 028 029/** 030 * @author Gustavo Matias 031 */ 032public class UsesFeatureProcessor implements TypeProcessor { 033 034 private final ManifestManager manifestManager; 035 036 @Inject 037 public UsesFeatureProcessor(ManifestManager manifestManager) { 038 this.manifestManager = manifestManager; 039 } 040 041 @Override 042 public ModuleConfiguration process(ASTType moduleType, ASTAnnotation permissionAnnotation) { 043 UsesFeature usesFeature = new UsesFeature(); 044 usesFeature.setName(checkBlank(permissionAnnotation.getProperty("value", String.class))); 045 usesFeature.setRequired(checkDefault(permissionAnnotation.getProperty("required", Boolean.class), true)); 046 usesFeature.setGlEsVersion(checkDefault(permissionAnnotation.getProperty("glEsVersion", Integer.class), -1)); 047 048 return new UsesFeatureModuleConfiguration(usesFeature); 049 } 050 051 private final class UsesFeatureModuleConfiguration implements ModuleConfiguration{ 052 053 private final UsesFeature usesFeature; 054 055 private UsesFeatureModuleConfiguration(UsesFeature usesFeature) { 056 this.usesFeature = usesFeature; 057 } 058 059 060 @Override 061 public void setConfiguration(InjectionNodeBuilderRepository configurationRepository) { 062 manifestManager.addUsesFeature(usesFeature); 063 } 064 } 065}