1 /* 2 * Copyright (C) 2009 The Guava Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 15 package com.google.common.annotations; 16 17 import java.lang.annotation.Documented; 18 import java.lang.annotation.ElementType; 19 import java.lang.annotation.Retention; 20 import java.lang.annotation.RetentionPolicy; 21 import java.lang.annotation.Target; 22 23 /** 24 * The presence of this annotation on a type indicates that the type may be used with the <a 25 * href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> (GWT). When applied to a method, 26 * the return type of the method is GWT compatible. It's useful to indicate that an instance created 27 * by factory methods has a GWT serializable type. In the following example, 28 * 29 * <pre> 30 * {@literal @}GwtCompatible 31 * class Lists { 32 * ... 33 * {@literal @}GwtCompatible(serializable = true) 34 * {@literal static <E> List<E>} newArrayList(E... elements) { 35 * ... 36 * } 37 * } 38 * </pre> 39 * 40 * <p>The return value of {@code Lists.newArrayList(E[])} has GWT serializable type. It is also 41 * useful in specifying contracts of interface methods. In the following example, 42 * 43 * <pre> 44 * {@literal @}GwtCompatible 45 * interface ListFactory { 46 * ... 47 * {@literal @}GwtCompatible(serializable = true) 48 * {@literal <E> List<E>} newArrayList(E... elements); 49 * } 50 * </pre> 51 * 52 * <p>The {@code newArrayList(E[])} method of all implementations of {@code ListFactory} is expected 53 * to return a value with a GWT serializable type. 54 * 55 * <p>Note that a {@code GwtCompatible} type may have some {@link GwtIncompatible} methods. 56 * 57 * @author Charles Fry 58 * @author Hayward Chan 59 */ 60 @Retention(RetentionPolicy.CLASS) 61 @Target({ElementType.TYPE, ElementType.METHOD}) 62 @Documented 63 @GwtCompatible 64 public @interface GwtCompatible { 65 66 /** 67 * When {@code true}, the annotated type or the type of the method return value is GWT 68 * serializable. 69 * 70 * @see <a href= 71 * "http://code.google.com/webtoolkit/doc/latest/DevGuideServerCommunication.html#DevGuideSerializableTypes"> 72 * Documentation about GWT serialization</a> 73 */ serializable()74 boolean serializable() default false; 75 76 /** 77 * When {@code true}, the annotated type is emulated in GWT. The emulated source (also known as 78 * super-source) is different from the implementation used by the JVM. 79 * 80 * @see <a href= 81 * "http://code.google.com/webtoolkit/doc/latest/DevGuideOrganizingProjects.html#DevGuideModules"> 82 * Documentation about GWT emulated source</a> 83 */ emulated()84 boolean emulated() default false; 85 } 86