KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > mondrian > olap > fun > ParenthesesFunDef


1 /*
2 // $Id: //open/mondrian/src/main/mondrian/olap/fun/ParenthesesFunDef.java#11 $
3 // This software is subject to the terms of the Common Public License
4 // Agreement, available at the following URL:
5 // http://www.opensource.org/licenses/cpl.html.
6 // Copyright (C) 2002-2002 Kana Software, Inc.
7 // Copyright (C) 2002-2006 Julian Hyde and others
8 // All Rights Reserved.
9 // You must accept the terms of that agreement to use this software.
10 //
11 // jhyde, 3 March, 2002
12 */

13 package mondrian.olap.fun;
14 import mondrian.olap.*;
15 import mondrian.olap.type.Type;
16 import mondrian.calc.Calc;
17 import mondrian.calc.ExpCompiler;
18 import mondrian.mdx.ResolvedFunCall;
19
20 import java.io.PrintWriter JavaDoc;
21
22 /**
23  * <code>ParenthesesFunDef</code> implements the parentheses operator as if it
24  * were a function.
25  *
26  * @author jhyde
27  * @since 3 March, 2002
28  * @version $Id: //open/mondrian/src/main/mondrian/olap/fun/ParenthesesFunDef.java#11 $
29  */

30 class ParenthesesFunDef extends FunDefBase {
31     private final int argType;
32     ParenthesesFunDef(int argType) {
33         super(
34             "()",
35             "(<Expression>)",
36             "Parenthesis enclose an expression and indicate precedence.",
37             Syntax.Parentheses,
38             argType,
39             new int[] {argType});
40         this.argType = argType;
41     }
42     public void unparse(Exp[] args, PrintWriter JavaDoc pw) {
43         if (args.length != 1) {
44             ExpBase.unparseList(pw, args, "(", ",", ")");
45         } else {
46             // Don't use parentheses unless necessary. We add parentheses around
47
// expressions because we're not sure of operator precedence, so if
48
// we're not careful, the parentheses tend to multiply ad infinitum.
49
args[0].unparse(pw);
50         }
51     }
52
53     public Type getResultType(Validator validator, Exp[] args) {
54         Util.assertTrue(args.length == 1);
55         return args[0].getType();
56     }
57
58     public Calc compileCall(ResolvedFunCall call, ExpCompiler compiler) {
59         return compiler.compile(call.getArg(0));
60     }
61 }
62
63 // End ParenthesesFunDef.java
64
Popular Tags