1/*
2 * Copyright (c) 1997, 2012, 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/*
27 * Use is subject to the license terms.
28 */
29package com.sun.tools.internal.xjc.generator.bean;
30
31import com.sun.codemodel.internal.JCodeModel;
32import com.sun.codemodel.internal.JDocComment;
33import com.sun.codemodel.internal.JMethod;
34import com.sun.codemodel.internal.JType;
35import com.sun.codemodel.internal.JVar;
36import com.sun.tools.internal.xjc.outline.ClassOutline;
37
38/**
39 * The back-end may or may not generate the content interface
40 * separately from the implementation class. If so, a method
41 * needs to be declared on both the interface and the implementation class.
42 * <p>
43 * This class hides those details and allow callers to declare
44 * methods just once.
45 *
46 * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
47 */
48public abstract class MethodWriter {
49    protected final JCodeModel codeModel;
50
51    protected MethodWriter(ClassOutline context) {
52        this.codeModel = context.parent().getCodeModel();
53    }
54
55    /**
56     * Declares a method in both the interface and the implementation.
57     *
58     * @return
59     *      JMethod object that represents a newly declared method
60     *      on the implementation class.
61     */
62    public abstract JMethod declareMethod( JType returnType, String methodName );
63
64    public final JMethod declareMethod( Class returnType, String methodName ) {
65        return declareMethod( codeModel.ref(returnType), methodName );
66    }
67
68    /**
69     * To generate javadoc for the previously declared method, use this method
70     * to obtain a {@link JDocComment} object. This may return a value
71     * different from declareMethod().javadoc().
72     */
73    public abstract JDocComment javadoc();
74
75
76    /**
77     * Adds a parameter to the previously declared method.
78     *
79     * @return
80     *      JVar object that represents a newly added parameter
81     *      on the implementation class.
82     */
83    public abstract JVar addParameter( JType type, String name );
84
85    public final JVar addParameter( Class type, String name ) {
86        return addParameter( codeModel.ref(type), name );
87    }
88}
89