KickJava   Java API By Example, From Geeks To Geeks.

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


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
25 package org.aspectj.compiler.crosscuts.joinpoints;
26
27 import org.aspectj.compiler.base.ast.*;
28 import org.aspectj.compiler.crosscuts.ast.*;
29 import org.aspectj.compiler.crosscuts.*;
30
31 import org.aspectj.compiler.base.JavaCompiler;
32
33 import java.util.*;
34
35 public class ExceptionHandlerJp extends CodeBodyJp {
36     CatchClause catchClause;
37
38     public ExceptionHandlerJp(CatchClause catchClause, JoinPoint enclosingJoinPoint) {
39         super(enclosingJoinPoint);
40         this.catchClause = catchClause;
41     }
42
43     static final Kind KIND = new Kind("exception-handler", HANDLER);
44
45     public Kind getKind() { return KIND; }
46
47
48     protected Expr makeSignatureExpr() {
49         return makeSignatureExpr(catchClause);
50     }
51  
52     public ASTObject getSourceLocation() { return catchClause; }
53
54     public Expr makeThrowableExpr() {
55         return getAST().makeVar(catchClause.getFormal());
56     }
57     
58     public Type getTargetType() {
59         return null;
60     }
61
62     //!!! better than null
63
public Dec getTargetDec() { return catchClause.getEnclosingCodeDec(); }
64
65     public Type getResultType() {
66         return getTypeManager().voidType;
67     }
68
69     public Type getExceptionType() {
70         return catchClause.getFormal().getType();
71     }
72     
73     public Exprs makeArgsExprs() {
74         return getAST().makeExprs(makeThrowableExpr());
75     }
76
77     public boolean canThrow(Type t) {
78         //XXX this is wrong
79
return t.isUncheckedThrowable();
80     }
81     
82     public Collection getPossibleCheckedExceptions() {
83         //XXX this is wrong
84
return Collections.EMPTY_LIST;
85     }
86
87
88
89     public Stmts getStmts() {
90         Stmt body = catchClause.getBody();
91         if (body instanceof BlockStmt) {
92             return ((BlockStmt)body).getStmts();
93         } else {
94             return getAST().makeStmts(body);
95         }
96     }
97
98     public void setStmts(Stmts stmts) {
99         catchClause.setBody(getAST().makeBlock(stmts));
100     }
101
102     public FormalDec getFormal() { return catchClause.getFormal(); }
103
104
105     public String JavaDoc toString() {
106         return "handler(" + catchClause.getFormal() + ")";
107     }
108
109     //XXX what is this all about
110
private static int counter = 0;
111     protected String JavaDoc getJoinPointNameModifier() { return "Handler" + counter++; }
112 }
113
Popular Tags