|
| 1 | +/** |
| 2 | + * Copyright (C) 2010-2014 eBusiness Information, Excilys Group |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | + * use this file except in compliance with the License. You may obtain a copy of |
| 6 | + * the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed To in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | + * License for the specific language governing permissions and limitations under |
| 14 | + * the License. |
| 15 | + */ |
| 16 | +package org.androidannotations.handler; |
| 17 | + |
| 18 | +import javax.annotation.processing.ProcessingEnvironment; |
| 19 | +import javax.lang.model.element.Element; |
| 20 | + |
| 21 | +import org.androidannotations.annotations.PreferenceHeaders; |
| 22 | +import org.androidannotations.helper.AnnotationHelper; |
| 23 | +import org.androidannotations.helper.IdValidatorHelper; |
| 24 | +import org.androidannotations.holder.EActivityHolder; |
| 25 | +import org.androidannotations.model.AnnotationElements; |
| 26 | +import org.androidannotations.process.IsValid; |
| 27 | +import org.androidannotations.rclass.IRClass; |
| 28 | + |
| 29 | +import com.sun.codemodel.JBlock; |
| 30 | +import com.sun.codemodel.JExpr; |
| 31 | +import com.sun.codemodel.JFieldRef; |
| 32 | +import com.sun.codemodel.JVar; |
| 33 | + |
| 34 | +public class PreferenceHeadersHandler extends BaseAnnotationHandler<EActivityHolder> { |
| 35 | + |
| 36 | + private final AnnotationHelper annotationHelper; |
| 37 | + |
| 38 | + public PreferenceHeadersHandler(ProcessingEnvironment processingEnvironment) { |
| 39 | + super(PreferenceHeaders.class, processingEnvironment); |
| 40 | + annotationHelper = new AnnotationHelper(processingEnvironment); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + protected void validate(Element element, AnnotationElements validatedElements, IsValid valid) { |
| 45 | + validatorHelper.isPreferenceFragmentClassPresent(element, valid); |
| 46 | + validatorHelper.extendsPreferenceActivity(element, valid); |
| 47 | + validatorHelper.hasEActivity(element, validatedElements, valid); |
| 48 | + validatorHelper.resIdsExist(element, IRClass.Res.XML, IdValidatorHelper.FallbackStrategy.NEED_RES_ID, valid); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void process(Element element, EActivityHolder holder) throws Exception { |
| 53 | + JFieldRef headerId = annotationHelper.extractAnnotationFieldRefs(processHolder, element, getTarget(), rClass.get(IRClass.Res.XML), false).get(0); |
| 54 | + |
| 55 | + JBlock block = holder.getPreferenceSupportHolder().getOnBuildHeadersBlock(); |
| 56 | + JVar targetParam = holder.getPreferenceSupportHolder().getOnBuildHeadersTargetParam(); |
| 57 | + block.invoke("loadHeadersFromResource").arg(headerId).arg(targetParam); |
| 58 | + block.invoke(JExpr._super(), "onBuildHeaders").arg(targetParam); |
| 59 | + } |
| 60 | +} |
0 commit comments