next up previous contents index
Next: Interfaces. Up: Applying the simplify algorithm Previous: Local variable declarations   Contents   Index


Field declarations

Expressions can appear as initializers in field declarations. If these expressions need simplification, and the field is declared in a class, the field initialization can be moved into an instance initializer block (if the field is an instance varible) or a static initializer block (if the field is a class variable) in the class. The case of a field declared in an interface will be considered at the end of this section.

We visit every field declaration in a source class in textual order. Consider a field variable declaration of the form

\begin{displaymath}
\mbox{\it ms} \verb$ $ T \verb$ $ V_0 \verb$ $ I_0 \verb$, $ \ldots \verb$, $
V_{n-1} \verb$ $ I_{n-1} \verb$ ;$
\end{displaymath}

where $\mbox{\it ms}$ is an optional list of modifiers, and other declarations are as in section A.3.3. We assume this is an instance variable (respectively static variable) declaration. Visit each variable declarator in this declaration in exactly the same way as described in the preceding section on local variable declarations. The field declaration is processed in essentially the same way. The only significant change is in the definition of the $D_i$.

If $\mbox{\it INITS}_i$ is empty, then $D_i$ is just:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it ms}$\verb$ $$T$\verb$ $$V_i$\verb$ ;$
\end{tabbing}\end{minipage}\end{displaymath}

Otherwise, we break the declaration into an uninitialized single-variable declaration and an instance initializer block:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it ms...
...rb$ = $$e'_i$\verb$ ;$ \\
\verb$}$
\end{tabbing}\end{minipage}\end{displaymath}

(respectively static initializer block:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\begin{tabbing}
$\mbox{\it ms...
...rb$ = $$e'_i$\verb$ ;$ \\
\verb$}$
\end{tabbing}\end{minipage}\end{displaymath}

).



Subsections
next up previous contents index
Next: Interfaces. Up: Applying the simplify algorithm Previous: Local variable declarations   Contents   Index
Bryan Carpenter 2003-04-15