1 /**
2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3 *
4 * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
5 * Portions Copyright 2013-2015 Philip Helger
6 *
7 * The contents of this file are subject to the terms of either the GNU
8 * General Public License Version 2 only ("GPL") or the Common Development
9 * and Distribution License("CDDL") (collectively, the "License"). You
10 * may not use this file except in compliance with the License. You can
11 * obtain a copy of the License at
12 * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
13 * or packager/legal/LICENSE.txt. See the License for the specific
14 * language governing permissions and limitations under the License.
15 *
16 * When distributing the software, include this License Header Notice in each
17 * file and include the License file at packager/legal/LICENSE.txt.
18 *
19 * GPL Classpath Exception:
20 * Oracle designates this particular file as subject to the "Classpath"
21 * exception as provided by Oracle in the GPL Version 2 section of the License
22 * file that accompanied this code.
23 *
24 * Modifications:
25 * If applicable, add the following below the License Header, with the fields
26 * enclosed by brackets [] replaced by your own identifying information:
27 * "Portions Copyright [year] [name of copyright owner]"
28 *
29 * Contributor(s):
30 * If you wish your version of this file to be governed by only the CDDL or
31 * only the GPL Version 2, indicate your decision by adding "[Contributor]
32 * elects to include this software in this distribution under the [CDDL or GPL
33 * Version 2] license." If you don't indicate a single choice of license, a
34 * recipient has the option to distribute your version of this file under
35 * either the CDDL, the GPL Version 2 or to extend the choice of license to
36 * its licensees as provided above. However, if you add GPL Version 2 code
37 * and therefore, elected the GPL Version 2 license, then the option applies
38 * only if the new code is made subject to such option by the copyright
39 * holder.
40 */
41 package com.helger.jcodemodel;
42
43 import javax.annotation.Nonnull;
44
45 /**
46 * Things that can be values of an annotation element.
47 *
48 * @author Bhakti Mehta (bhakti.mehta@sun.com)
49 */
50 public abstract class AbstractJAnnotationValue implements IJGenerable
51 {
52 @Nonnull
53 public static JAnnotationStringValue wrap (final boolean value)
54 {
55 return new JAnnotationStringValue (JExpr.lit (value), Boolean.valueOf (value));
56 }
57
58 @Nonnull
59 public static JAnnotationStringValue wrap (final byte value)
60 {
61 return new JAnnotationStringValue (JExpr.lit (value), Byte.valueOf (value));
62 }
63
64 @Nonnull
65 public static JAnnotationStringValue wrap (final char value)
66 {
67 return new JAnnotationStringValue (JExpr.lit (value), Character.valueOf (value));
68 }
69
70 @Nonnull
71 public static JAnnotationStringValue wrap (final double value)
72 {
73 return new JAnnotationStringValue (JExpr.lit (value), Double.valueOf (value));
74 }
75
76 @Nonnull
77 public static JAnnotationStringValue wrap (final float value)
78 {
79 return new JAnnotationStringValue (JExpr.lit (value), Float.valueOf (value));
80 }
81
82 @Nonnull
83 public static JAnnotationStringValue wrap (final int value)
84 {
85 return new JAnnotationStringValue (JExpr.lit (value), Integer.valueOf (value));
86 }
87
88 @Nonnull
89 public static JAnnotationStringValue wrap (final long value)
90 {
91 return new JAnnotationStringValue (JExpr.lit (value), Long.valueOf (value));
92 }
93
94 @Nonnull
95 public static JAnnotationStringValue wrap (final short value)
96 {
97 return new JAnnotationStringValue (JExpr.lit (value), Short.valueOf (value));
98 }
99
100 @Nonnull
101 public static JAnnotationStringValue wrap (@Nonnull final String value)
102 {
103 // Escape string values with quotes so that they can
104 // be generated accordingly
105 return new JAnnotationStringValue (JExpr.lit (value), value);
106 }
107
108 @Nonnull
109 public static JAnnotationStringValue wrap (@Nonnull final JEnumConstant aValue)
110 {
111 return new JAnnotationStringValue (aValue);
112 }
113
114 @Nonnull
115 public static JAnnotationStringValue wrap (@Nonnull final AbstractJType aType)
116 {
117 return new JAnnotationStringValue (aType.boxify ().dotclass (), aType);
118 }
119
120 @Nonnull
121 public static JAnnotationStringValue wrap (@Nonnull final IJExpression aExpr)
122 {
123 return new JAnnotationStringValue (aExpr);
124 }
125 }