KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > joinpoints > FieldSetJp


1 /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the compiler and core tools for the AspectJ(tm)
4  * programming language; see http://aspectj.org
5  *
6  * The contents of this file are subject to the Mozilla Public License
7  * Version 1.1 (the "License"); you may not use this file except in
8  * compliance with the License. You may obtain a copy of the License at
9  * either http://www.mozilla.org/MPL/ or http://aspectj.org/MPL/.
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is AspectJ.
17  *
18  * The Initial Developer of the Original Code is Xerox Corporation. Portions
19  * created by Xerox Corporation are Copyright (C) 1999-2002 Xerox Corporation.
20  * All Rights Reserved.
21  *
22  * Contributor(s):
23  */

24 package org.aspectj.compiler.crosscuts.joinpoints;
25
26 import org.aspectj.compiler.base.ast.*;
27 import org.aspectj.compiler.crosscuts.ast.*;
28
29 import org.aspectj.compiler.base.JavaCompiler;
30 import org.aspectj.util.JavaStrings;
31
32 import java.util.*;
33
34
35 public class FieldSetJp extends FieldGetJp {
36     public static interface FieldSetExprPromise extends FieldGetExprPromise {
37         /** makes this concrete */
38         public AssignExpr getAssignExpr();
39     }
40     public FieldSetJp(FieldSetExprPromise fieldSetExprPromise,
41         JoinPoint enclosingJoinPoint)
42     {
43         super(fieldSetExprPromise, enclosingJoinPoint);
44     }
45
46     public static final Kind KIND = new Kind("field-set", FIELD_SET);
47
48     public Kind getKind() { return KIND; }
49     
50     // newValue handling
51
FormalDec newValueFormal = null;
52     public FormalDec getNewValueFormal() {
53         if (newValueFormal == null) {
54             newValueFormal = getAST().makeFormal(getResultType(), "newValue");
55         }
56         return newValueFormal;
57     }
58     
59     //XXX clarify names vs. one below
60
public Expr makeNewFieldValueExpr() {
61        return getAST().makeVar(getNewValueFormal());
62     }
63     
64     public Expr makeNewValueExpr() {
65         return getResultType().makeObject(getAST().makeVar(getNewValueFormal()));
66     }
67     
68     public List makeArgsTypes() {
69         List ret = new ArrayList();
70         ret.add(getResultType());
71         return ret;
72     }
73
74     public Exprs makeArgsExprs() {
75         return getAST().makeExprs(makeNewFieldValueExpr());
76     }
77
78     protected ASTObject makeInnerCall(Expr targetExpr, Exprs argsExprs) {
79         return getAST().makeSet(targetExpr, getCalledFieldDec(), argsExprs.get(0));
80     }
81     
82     protected AnonymousMethodExpr makeSyntheticCall() {
83         final AST ast = getAST();
84         AssignExpr setExpr =
85             ((FieldSetExprPromise)fieldGetExprPromise).getAssignExpr();
86
87         //XXX this cast expression wouldn't be needed if we handled int literals as
88
//XXX shorts and bytes more uniformly elsewhere
89
Expr newValue = ast.makeCast(getNewValueFormal().getType(), setExpr.getRhs());
90
91         return makeAnonMethodExpr(ast.makeFormals(getNewValueFormal()),
92                                   ((FieldAccessExpr)setExpr.getLhs()).getExpr(),
93                                   ast.makeExprs(newValue));
94     }
95     protected void replaceExprWith(Expr newExpr) {
96         ((FieldSetExprPromise)fieldGetExprPromise).getAssignExpr().replaceWith(newExpr);
97     }
98 }
99
Popular Tags