Android Open Source - injectextra Inject Extra






From Project

Back to project page injectextra.

License

The source code is released under:

Apache License

If you think the Android project injectextra listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * Copyright 2009 Michael Burton/*  w  w w.ja  v a2 s.com*/
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 */
package com.github.stephanenicolas.injectextra;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
 * Indicates that a variable member of a class (whether static or not) should be
 * injected with an Android extra. The value is compulsory, and corresponds to
 * the key of the extra.<br />
 * <br />
 * The extra must exist when the activity is injected, unless you specify
 * {@code optional=true} in the {@link InjectExtra} annotation. If optional is
 * set to true and no extra is found, no value will be injected in the field.<br />
 * <br />
 * The default behavior of the {@link InjectExtra} annotation is to forbid null
 * values. However, if you wish to allow injection of null values, you should
 * use the @Nullable annotation. You can use any annotation class (findbugs, etc.)
 * with the name 'Nullable' <br />
 * <br />
 * You can define a default value via Java when the extra is optional : <br /> {@code
 * @InjectExtra(value="someValue", optional=true) Integer someValue = 2;} ) <br />
 * However, it is nonsense to inject a default value in Java if the extra is
 * not optional : {@code @InjectExtra("someValue") Integer someValue = 2; // DO
 * NOT DO THIS}
 *
 * <br />
 * Usage example:<br /> {@code @InjectExtra("someValue") protected Integer someValue;}<br />
 * <br />{@code @InjectExtra("someValue") @Nullable protected Integer someValue;}
 *
 * @author Mike Burton
 */
@Retention(RUNTIME)
@Target( { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
public @interface InjectExtra {
  String value();
  boolean optional() default false;
}




Java Source Code List

com.example.injectextra.MainActivity.java
com.example.injectextra.SecondActivity.java
com.github.stephanenicolas.injectextra.InjectExtraException.java
com.github.stephanenicolas.injectextra.InjectExtraProcessor.java
com.github.stephanenicolas.injectextra.InjectExtra.java