KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > aspectj > compiler > crosscuts > Correspondences


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;
26
27 import org.aspectj.compiler.base.*;
28 import org.aspectj.compiler.base.ast.*;
29 import org.aspectj.compiler.crosscuts.ast.*;
30 import org.aspectj.util.CollectionUtil;
31
32 import org.aspectj.tools.ide.Declaration;
33 import org.aspectj.tools.ide.SymbolManager;
34
35 import org.aspectj.compiler.base.JavaCompiler;
36 import org.aspectj.compiler.base.CompilerObject;
37
38
39
40 import java.io.*;
41 //import java.io.Writer;
42
//import java.io.File;
43
//import java.io.FileWriter;
44
//import java.io.BufferedWriter;
45
//import java.io.IOException;
46

47
48 import java.util.*;
49
50 // Make sure that references to Vector use the standard version
51
// This lets us generate serialized files which interoperate with other code better
52
import java.util.Vector JavaDoc;
53
54
55 // ultimate goal is probably to do dependency tracking here to make enviro
56
// much nicer to use...
57

58 public class Correspondences extends CompilerObject {
59     private Map corrs = new HashMap();
60
61     public Correspondences(JavaCompiler compiler) {
62         super(compiler);
63     }
64
65     public CompilationUnitCorrespondences getCompilationUnitCorrespondences(ASTObject node) {
66         CompilationUnit cu = node.getCompilationUnit();
67
68         CompilationUnitCorrespondences cuCorrs = (CompilationUnitCorrespondences)corrs.get(cu);
69         if (cuCorrs == null) {
70             cuCorrs = new CompilationUnitCorrespondences(cu);
71             corrs.put(cu, cuCorrs);
72         }
73         return cuCorrs;
74     }
75
76
77     public File makeSymFile(File javaFile) {
78         return SymbolManager.mapFilenameToSymbolFile(javaFile.getPath());
79     }
80
81     // dump these over the files that were read in
82
public void dump(CompilationUnit cu, CompilationUnitCorrespondences cucorr) {
83         //for(Iterator iter=corrs.entrySet().iterator(); iter.hasNext(); ) {
84
// Map.Entry entry = (Map.Entry)iter.next();
85
// CompilationUnit cu = (CompilationUnit)entry.getKey();
86
// if (cu == CompilationUnit.missingCompilationUnit) continue;
87
// CompilationUnitCorrespondences cucorr = (CompilationUnitCorrespondences)entry.getValue();
88
dump(cu.getSourceFile(), cu, cucorr);
89         //}
90
}
91
92     public void dump(File file, CompilationUnit cu, CompilationUnitCorrespondences cucorr) {
93         if (file == null) return;
94 // if (!getOptions().nosymbols) {
95
// try {
96
// OutputStream out = new FileOutputStream(makeSymFile(file));
97
// try {
98
// cucorr.dumpSymbolFile(out);
99
// } finally {
100
// out.close();
101
// }
102
// } catch (IOException ioe) {
103
// // handle ioexception intelligently here,,,
104
// }
105
// }
106
}
107
108     // a better name for me to keep track of what's really going on
109
public void addPointsTo(ASTObject node1, ASTObject node2) {
110         //System.err.println(node1.getCompilationUnit().getSource()+" points to "+node2.getCompilationUnit().getSource());
111

112         if (node1 == null || node2 == null) return;
113
114         //XXX hack to make the IDE's life easier for now
115
getCompilationUnitCorrespondences(node1).addPointsTo(node1, node2);
116         getCompilationUnitCorrespondences(node2).addPointedToBy(node2, node1);
117
118
119     }
120
121     /**
122     public void addCorrespondence(ASTObject node1, ASTObject node2) {
123         addPointsTo(node1, node2);
124     }
125     **/

126
127     /**
128      * Used by <CODE>StructureViewBuilder</CODE>
129      */

130      public Set getAffects(ASTObject astObject) {
131         return getCompilationUnitCorrespondences(astObject).getPointsToSet(astObject);
132      }
133
134     /**
135      * Used by <CODE>StructureViewBuilder</CODE>
136      */

137      public Set getAffectedBy(ASTObject astObject) {
138         return getCompilationUnitCorrespondences(astObject).getPointedToBySet(astObject);
139      }
140 }
141
Popular Tags