KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > tools > ajdoc > OfClauseDocImpl


1 /* -*- Mode: JDE; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2  *
3  * This file is part of the debugger 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 package org.aspectj.tools.ajdoc;
23
24 import org.aspectj.ajdoc.ClassDoc;
25 import org.aspectj.ajdoc.OfClauseDoc;
26 import org.aspectj.ajdoc.OfEachObjectDoc;
27 import org.aspectj.compiler.crosscuts.ast.Pcd;
28 import org.aspectj.compiler.crosscuts.ast.PerCFlow;
29 import org.aspectj.compiler.crosscuts.ast.PerClause;
30 import org.aspectj.compiler.crosscuts.ast.PerObject;
31 import org.aspectj.compiler.crosscuts.ast.PerSingleton;
32
33 import java.util.Collections JavaDoc;
34 import java.util.List JavaDoc;
35
36 public class OfClauseDocImpl {
37
38     /** TODO */
39     public final static OfClauseDoc getInstance(PerClause clause) {
40         return factory.getInstance(clause);
41     }
42
43     /** The factory used to create the instance. */
44     private final static Factory factory = new Factory();
45
46     /** TODO */
47     private final static class OfEachObjectDocImpl implements OfEachObjectDoc {
48         private final List JavaDoc instances;
49         private OfEachObjectDocImpl(PerObject eo) {
50             instances = createInstances(eo);
51         }
52         public ClassDoc[] instances() {
53             return (ClassDoc[])instances.toArray(new ClassDoc[instances.size()]);
54         }
55         public OfEachObjectDoc.Kind kind() {
56             return OfClauseDoc.Kind.EACH_OBJECT;
57         }
58         private List JavaDoc createInstances(PerObject eo) {
59             Pcd pc = eo.getPcd();
60             if (pc == null) {
61                 return Collections.EMPTY_LIST;
62             }
63             return Collections.EMPTY_LIST;
64         }
65     }
66
67     /** TODO */
68     private static class Factory {
69
70         private final static OfClauseDoc EACH_CFLOW = new OfClauseDoc(){
71                 public OfClauseDoc.Kind kind() {
72                     return OfClauseDoc.Kind.EACH_CFLOW;
73                 }
74             };
75
76         private final static OfClauseDoc EACH_JVM = new OfClauseDoc() {
77                 public OfClauseDoc.Kind kind() {
78                     return OfClauseDoc.Kind.EACH_JVM;
79                 }
80             };
81
82         public final OfClauseDoc getInstance(PerClause clause) {
83             if (clause instanceof PerCFlow) {
84                 return EACH_CFLOW;
85             }
86             if (clause instanceof PerSingleton) {
87                 return EACH_JVM;
88             }
89             if (clause instanceof PerObject) {
90                 return new OfEachObjectDocImpl((PerObject)clause);
91             }
92             return null; //??? error
93
}
94     }
95 }
96
Popular Tags