1 /*
2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package com.sun.tools.internal.xjc.outline;
27 
28 import com.sun.codemodel.internal.JBlock;
29 import com.sun.codemodel.internal.JExpression;
30 import com.sun.codemodel.internal.JVar;
31 import com.sun.tools.internal.xjc.model.CPropertyInfo;
32 
33 /**
34  * Encapsulates the access on a field.
35  *
36  * @author
37  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
38  */
39 public interface FieldAccessor {
40 
41     /**
42      * Dumps everything in this field into the given variable.
43      *
44      * <p>
45      * This generates code that accesses the field from outside.
46      *
47      * @param block
48      *      The code will be generated into this block.
49      * @param $var
50      *      Variable whose type is {@link FieldOutline#getRawType()}
51      */
toRawValue( JBlock block, JVar $var )52     void toRawValue( JBlock block, JVar $var );
53 
54     /**
55      * Sets the value of the field from the specified expression.
56      *
57      * <p>
58      * This generates code that accesses the field from outside.
59      *
60      * @param block
61      *      The code will be generated into this block.
62      * @param uniqueName
63      *      Identifier that the caller guarantees to be unique in
64      *      the given block. When the callee needs to produce additional
65      *      variables, it can do so by adding suffixes to this unique
66      *      name. For example, if the uniqueName is "abc", then the
67      *      caller guarantees that any identifier "abc.*" is unused
68      *      in this block.
69      * @param $var
70      *      The expression that evaluates to a value of the type
71      *      {@link FieldOutline#getRawType()}.
72      */
fromRawValue( JBlock block, String uniqueName, JExpression $var )73     void fromRawValue( JBlock block, String uniqueName, JExpression $var );
74 
75     /**
76      * Generates a code fragment to remove any "set" value
77      * and move this field to the "unset" state.
78      *
79      * @param body
80      *      The code will be appended at the end of this block.
81      */
unsetValues( JBlock body )82     void unsetValues( JBlock body );
83 
84     /**
85      * Return an expression that evaluates to true only when
86      * this field has a set value(s).
87      *
88      * @return null
89      *      if the isSetXXX/unsetXXX method does not make sense
90      *      for the given field.
91      */
hasSetValue()92     JExpression hasSetValue();
93 
94     /**
95      * Gets the {@link FieldOutline} from which
96      * this object is created.
97      */
owner()98     FieldOutline owner();
99 
100     /**
101      * Short for <tt>owner().getPropertyInfo()</tt>
102      */
getPropertyInfo()103     CPropertyInfo getPropertyInfo();
104 }
105