Debian Codegraph @

src/main/java/net/sf/antcontrib/design/InstructionVisitor.java

raw symbols SCIP
1 /*
2 * Copyright (c) 2001-2004 Ant-Contrib project. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.antcontrib.design;
17
18 import org.apache.bcel.generic.ANEWARRAY;
19 import org.apache.bcel.generic.CHECKCAST;
20 import org.apache.bcel.generic.ConstantPoolGen;
21 import org.apache.bcel.generic.EmptyVisitor;
22 import org.apache.bcel.generic.INSTANCEOF;
23 import org.apache.bcel.generic.INVOKESTATIC;
24 import org.apache.bcel.generic.LoadInstruction;
25 import org.apache.bcel.generic.NEW;
26 import org.apache.bcel.generic.PUTSTATIC;
27 import org.apache.bcel.generic.Type;
28 import org.apache.tools.ant.Project;
29
30
31
32 public class InstructionVisitor extends EmptyVisitor {
33
34
35 private ConstantPoolGen poolGen;
36 private Log log;
37 private Design design;
38
39 /**
40 * @param poolGen
41 * @param v
42 */
43 public InstructionVisitor(ConstantPoolGen poolGen, Log log, Design d) {
44 this.poolGen = poolGen;
45 this.log = log;
46 this.design = d;
47 }
48
49 public void visitCHECKCAST(CHECKCAST c) {
50 Type t = c.getType(poolGen);
51 log.log(" instr(checkcast)="+t, Project.MSG_DEBUG);
52 String type = t.toString();
53
54 design.checkClass(type);
55 }
56
57 public void visitLoadInstruction(LoadInstruction l) {
58 //log.log(" visit load", Project.MSG_DEBUG);
59 Type t = l.getType(poolGen);
60 log.log(" instr(loadinstr)="+t, Project.MSG_DEBUG);
61 String type = t.toString();
62
63 design.checkClass(type);
64 }
65
66 public void visitNEW(NEW n) {
67 Type t= n.getType(poolGen);
68 log.log(" instr(new)="+t, Project.MSG_DEBUG);
69 String type = t.toString();
70
71 design.checkClass(type);
72 }
73
74 public void visitANEWARRAY(ANEWARRAY n) {
75 Type t = n.getType(poolGen);
76 log.log(" instr(anewarray)="+t, Project.MSG_DEBUG);
77 String type = t.toString();
78
79 design.checkClass(type);
80 }
81
82 public void visitINSTANCEOF(INSTANCEOF i) {
83 Type t = i.getType(poolGen);
84 log.log(" instr(instanceof)="+t, Project.MSG_DEBUG);
85 String type = t.toString();
86
87 design.checkClass(type);
88 }
89 public void visitINVOKESTATIC(INVOKESTATIC s) {
90 String t = s.getClassName(poolGen);
91 log.log(" instr(invokestatic)="+t, Project.MSG_DEBUG);
92
93 design.checkClass(t);
94 }
95
96 public void visitPUTSTATIC(PUTSTATIC s) {
97 String one = s.getClassName(poolGen);
98 String two = s.getFieldName(poolGen);
99 String three = s.getName(poolGen);
100 String four = s.getSignature(poolGen);
101 String five = s.getClassType(poolGen)+"";
102 String six = s.getFieldType(poolGen)+"";
103 log.log(" instr(putstatic)a="+one, Project.MSG_DEBUG);
104 log.log(" instr(putstatic)b="+two, Project.MSG_DEBUG);
105 log.log(" instr(putstatic)c="+three, Project.MSG_DEBUG);
106 log.log(" instr(putstatic)d="+four, Project.MSG_DEBUG);
107 log.log(" instr(putstatic)e="+five, Project.MSG_DEBUG);
108 log.log(" instr(putstatic)f="+six, Project.MSG_DEBUG);
109
110 String className = s.getFieldName(poolGen);
111 if("staticField".equals(className))
112 return;
113
114 if(className.startsWith("class$") || className.startsWith("array$"))
115 ;
116 else return;
117
118 log.log(" instr(putstatic)1="+className, Project.MSG_DEBUG);
119 className = className.substring(6, className.length());
120 log.log(" instr(putstatic)2="+className, Project.MSG_DEBUG);
121 className = className.replace('$', '.');
122 log.log(" instr(putstatic)3="+className, Project.MSG_DEBUG);
123
124 design.checkClass(className);
125 }
126 }