root/trunk/ProjectFortress/src/com/sun/fortress/compiler/index/DeclaredMethod.java @ 3366

Revision 3366, 3.1 KB (checked in by sukyoungryu, 10 months ago)

[copyright] Fixed copyright notices.

Line 
1/*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16 ******************************************************************************/
17
18package com.sun.fortress.compiler.index;
19
20import java.util.Collections;
21import java.util.List;
22
23import com.sun.fortress.compiler.typechecker.StaticTypeReplacer;
24import com.sun.fortress.nodes.BaseType;
25import com.sun.fortress.nodes.Expr;
26import com.sun.fortress.nodes.FnDecl;
27import com.sun.fortress.nodes.Id;
28import com.sun.fortress.nodes.Node;
29import com.sun.fortress.nodes.NodeDepthFirstVisitor;
30import com.sun.fortress.nodes.NodeUpdateVisitor;
31import com.sun.fortress.nodes.Param;
32import com.sun.fortress.nodes.StaticArg;
33import com.sun.fortress.nodes.StaticParam;
34import com.sun.fortress.nodes.Type;
35import com.sun.fortress.nodes_util.NodeUtil;
36import com.sun.fortress.nodes_util.Span;
37
38import edu.rice.cs.plt.tuple.Option;
39
40public class DeclaredMethod extends Method {
41
42    private final FnDecl _ast;
43    private final Id _declaringTrait;
44
45    public DeclaredMethod(FnDecl ast, Id declaringTrait) {
46        _ast = ast;
47        _declaringTrait = declaringTrait;
48    }
49
50    public FnDecl ast() { return _ast; }
51
52    @Override
53    public Span getSpan() { return NodeUtil.getSpan(_ast); }
54
55        @Override
56        public Option<Expr> body() {
57                return _ast.accept(new NodeDepthFirstVisitor<Option<Expr>>(){
58                        @Override
59                        public Option<Expr> defaultCase(Node that) {
60                                return Option.none();
61                        }
62                        @Override
63                        public Option<Expr> forFnDecl(FnDecl that) {
64                            return that.getBody();
65                        }
66                });
67        }
68
69        @Override
70        public List<Param> parameters() {
71                return NodeUtil.getParams(_ast);
72        }
73
74        @Override
75        public List<StaticParam> staticParameters() {
76                return NodeUtil.getStaticParams(_ast);
77        }
78
79        @Override
80        public List<BaseType> thrownTypes() {
81                if( NodeUtil.getThrowsClause(_ast).isSome() )
82                        return Collections.emptyList();
83                else
84                        return Collections.unmodifiableList(NodeUtil.getThrowsClause(_ast).unwrap());
85        }
86
87        @Override
88        public Functional instantiate(List<StaticParam> params, List<StaticArg> args) {
89                FnDecl replaced_decl =
90                        (FnDecl)_ast.accept(new StaticTypeReplacer(params,args));
91                return new DeclaredMethod(replaced_decl,_declaringTrait);
92        }
93
94        @Override
95        public Type getReturnType() {
96                return NodeUtil.getReturnType(_ast).unwrap();
97        }
98
99        @Override
100        public Id getDeclaringTrait() {
101                return this._declaringTrait;
102        }
103
104        @Override
105        public Functional acceptNodeUpdateVisitor(NodeUpdateVisitor visitor) {
106                return new DeclaredMethod((FnDecl)_ast.accept(visitor), this._declaringTrait);
107        }
108}
Note: See TracBrowser for help on using the browser.