本文整理汇总了Java中org.apache.bcel.classfile.ConstantPool.getConstantPool方法的典型用法代码示例。如果您正苦于以下问题:Java ConstantPool.getConstantPool方法的具体用法?Java ConstantPool.getConstantPool怎么用?Java ConstantPool.getConstantPool使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.bcel.classfile.ConstantPool
的用法示例。
在下文中一共展示了ConstantPool.getConstantPool方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createDependencyList
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
* Create a list containing all referenced classes.
*
* @return the list of all classes the given class depends on.
*/
private List<String> createDependencyList(JavaClass clazz) {
Set<String> result = new HashSet<String>();
ConstantPool cp = clazz.getConstantPool();
String className = clazz.getClassName();
for (Constant c : cp.getConstantPool()) {
if (c instanceof ConstantClass) {
String usedClassName = cp.constantToString(c);
usedClassName = JavaLibrary
.ignoreArtificialPrefix(usedClassName);
if (!usedClassName.equals("") && !isBlacklisted(usedClassName)
&& !className.equals(usedClassName)) {
result.add(usedClassName);
}
}
}
return new ArrayList<String>(result);
}
示例2: createDependencyList
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** Create a list of dependencies for a given class. */
private ArrayList<String> createDependencyList(JavaClass clazz) {
ArrayList<String> depList = new ArrayList<String>();
ConstantPool cp = clazz.getConstantPool();
String className = clazz.getClassName();
for (Constant constant : cp.getConstantPool()) {
if (constant instanceof ConstantClass) {
String usedClassName = cp.constantToString(constant);
// don't include self-reference
if (!className.equals(usedClassName)) {
depList.add(usedClassName);
}
}
}
return depList;
}
示例3: visit
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
@Override
public void visit(ConstantPool pool) {
for (Constant constant : pool.getConstantPool()) {
if (constant instanceof ConstantClass) {
ConstantClass cc = (ConstantClass) constant;
@SlashedClassName String className = cc.getBytes(pool);
if (className.equals("java/util/Calendar") || className.equals("java/text/DateFormat")) {
sawDateClass = true;
break;
}
try {
ClassDescriptor cDesc = DescriptorFactory.createClassDescriptor(className);
if (subtypes2.isSubtype(cDesc, calendarType) || subtypes2.isSubtype(cDesc, dateFormatType)) {
sawDateClass = true;
break;
}
} catch (ClassNotFoundException e) {
reporter.reportMissingClass(e);
}
}
}
}
示例4: main
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
* Main class, to find strings in class files.
* @param args Arguments to program.
*/
public static void main(String[] args) {
try {
JavaClass clazz = Repository.lookupClass(args[0]);
ConstantPool cp = clazz.getConstantPool();
Constant[] consts = cp.getConstantPool();
for (int i = 0; i < consts.length; i++) {
if (consts[i] instanceof ConstantString) {
System.out.println("Found String: " +
((ConstantString)consts[i]).getBytes(cp));
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
示例5: ConstantHTML
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
ConstantHTML(String dir, String class_name, String class_package, Method[] methods,
ConstantPool constant_pool) throws IOException {
this.class_name = class_name;
this.class_package = class_package;
this.constant_pool = constant_pool;
this.methods = methods;
constants = constant_pool.getConstantPool();
file = new PrintWriter(new FileOutputStream(dir + class_name + "_cp.html"));
constant_ref = new String[constants.length];
constant_ref[0] = "<unknown>";
file.println("<HTML><BODY BGCOLOR=\"#C0C0C0\"><TABLE BORDER=0>");
// Loop through constants, constants[0] is reserved
for (int i = 1; i < constants.length; i++) {
if (i % 2 == 0) {
file.print("<TR BGCOLOR=\"#C0C0C0\"><TD>");
} else {
file.print("<TR BGCOLOR=\"#A0A0A0\"><TD>");
}
if (constants[i] != null) {
writeConstant(i);
}
file.print("</TD></TR>\n");
}
file.println("</TABLE></BODY></HTML>");
file.close();
}
示例6: JavaClass
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
* Read class definition from an input stream.
*
* @param filename
* the name of the class file (used to determine the class name)
* @param is
* the input stream to read the class file from
* @throws IOException
* if I/O exception occurs while reading from the input stream
*/
public JavaClass(String filename, InputStream is) throws IOException {
ClassParser parser = new ClassParser(is, filename);
org.apache.bcel.classfile.JavaClass clazz = parser.parse();
ConstantPool cp = clazz.getConstantPool();
name = clazz.getClassName();
for (Constant c : cp.getConstantPool()) {
if (c instanceof ConstantClass) {
ConstantClass cc = (ConstantClass) c;
ConstantUtf8 cs = (ConstantUtf8) cp.getConstant(cc.getNameIndex());
String cn = new String(cs.getBytes());
if (cn.contains("["))
continue;
cn = cn.replaceAll("^\\[L", "");
cn = cn.replaceAll(";", "");
cn = cn.replaceAll("/", ".");
getDependencies().add(cn);
}
}
}
示例7: visitClassContext
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
@Override
public void visitClassContext(ClassContext classContext) {
JavaClass javaClass = classContext.getJavaClass();
if (!javaClass.getPackageName().contains(".pages")) {
return;
}
//The package contains ".pages" and has some references to tapestry
// then it must be an endpoint.
//The constants pool contains all references that are reused in the bytecode
// including full class name and interface name.
if (javaClass.getPackageName().contains(".pages")) {
ConstantPool constants = javaClass.getConstantPool();
for (Constant c : constants.getConstantPool()) {
if (c instanceof ConstantUtf8) {
ConstantUtf8 utf8 = (ConstantUtf8) c;
String constantValue = String.valueOf(utf8.getBytes());
if (constantValue.startsWith("Lorg/apache/tapestry5/annotations")) {
bugReporter.reportBug(new BugInstance(this, TAPESTRY_ENDPOINT_TYPE, Priorities.LOW_PRIORITY) //
.addClass(javaClass));
return;
}
}
}
}
}
示例8: processConstantPool
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
private void processConstantPool(ConstantPool pool) {
Constant[] constants = pool.getConstantPool();
if (constants == null) {
log(" constants=null", Project.MSG_VERBOSE);
return;
}
log(" constants len=" + constants.length, Project.MSG_VERBOSE);
for (int i = 0; i < constants.length; i++) {
processConstant(pool, constants[i], i);
}
}
示例9: getConstantPool
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
public static Set<Object> getConstantPool(InputStream is, String name) throws ClassFormatException, IOException {
HashSet<Object> constants = new HashSet<Object>();
ClassParser parser = new ClassParser(is, name);
ConstantPool pool = parser.parse().getConstantPool();
for (Constant constant : pool.getConstantPool()) {
//Strings used in code are stored using String constant, they are just references to Utf8 constant
//but we can't use Utf8 constants because they are used to store field/method/class names and signatures too
if (constant instanceof ConstantString) {
String string = (String) ((ConstantString) constant).getConstantValue(pool);
//skip empty string
if (string.isEmpty()) {
continue;
}
constants.add(string);
}
if (constant instanceof ConstantInteger || constant instanceof ConstantLong || constant instanceof ConstantFloat || constant instanceof ConstantDouble) {
constants.add(((ConstantObject) constant).getConstantValue(pool));
}
}
return constants;
}
示例10: addToClassToTestsMap
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
* Fill the {@link #classToTests} map for a given JUnit test case class.
*/
private void addToClassToTestsMap(JavaClass clazz) {
Set<String> result = new HashSet<String>();
ConstantPool cp = clazz.getConstantPool();
String className = clazz.getClassName();
for (Constant c : cp.getConstantPool()) {
if (c instanceof ConstantClass) {
String usedClassName = cp.constantToString(c);
usedClassName = JavaLibrary
.ignoreArtificialPrefix(usedClassName);
if (usedClassName.equals("")) {
continue;
}
if (JavaLibrary.isInternalClass(usedClassName)) {
continue;
}
// don't include self-reference
if (!className.equals(usedClassName)) {
result.add(usedClassName);
}
}
}
for (String foundName : result) {
classToTests.add(foundName, className);
}
}
示例11: makeClassNode
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/** Create the vertex and dependencies for the given class. */
private void makeClassNode(ConQATGraphInnerNode node, BundleInfo bundle,
JavaClass clazz) {
String className = clazz.getClassName();
Set<String> dependencies = new HashSet<String>();
ConstantPool cp = clazz.getConstantPool();
for (Constant c : cp.getConstantPool()) {
if (c instanceof ConstantClass) {
String usedClassName = cp.constantToString(c);
usedClassName = JavaLibrary
.ignoreArtificialPrefix(usedClassName);
if (usedClassName.equals("")
|| usedClassName.startsWith("java.")
|| usedClassName.startsWith("javax.")
|| usedClassName.startsWith("org.xml.")
|| usedClassName.startsWith("org.w3c.")
|| className.equals(usedClassName)) {
continue;
}
dependencies.add(usedClassName);
}
}
try {
ConQATVertex v = graph.createVertex(className, className, node);
depInfo.put(v, dependencies);
parentBundle.put(className, bundle);
} catch (ConQATException e) {
getLogger().warn("Duplicate class: " + className);
}
}
示例12: visitConstantPool
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
@Override
public void visitConstantPool(ConstantPool obj) {
super.visitConstantPool(obj);
Constant[] constant_pool = obj.getConstantPool();
for (int i = 1; i < constant_pool.length; i++) {
constant_pool[i].accept(this);
byte tag = constant_pool[i].getTag();
if ((tag == CONSTANT_Double) || (tag == CONSTANT_Long))
i++;
}
}
示例13: visit
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
@Override
public void visit(JavaClass obj) {
compute();
ConstantPool cp = obj.getConstantPool();
Constant[] constants = cp.getConstantPool();
checkConstant: for (int i = 0; i < constants.length; i++) {
Constant co = constants[i];
if (co instanceof ConstantDouble || co instanceof ConstantLong)
i++;
if (co instanceof ConstantClass) {
String ref = getClassName(obj, i);
if ((ref.startsWith("java") || ref.startsWith("org.w3c.dom")) && !defined.contains(ref))
bugReporter.reportBug(new BugInstance(this, "VR_UNRESOLVABLE_REFERENCE", NORMAL_PRIORITY).addClass(obj)
.addString(ref));
} else if (co instanceof ConstantFieldref) {
// do nothing until we handle static fields defined in
// interfaces
} else if (co instanceof ConstantCP) {
ConstantCP co2 = (ConstantCP) co;
String className = getClassName(obj, co2.getClassIndex());
// System.out.println("checking " + ref);
if (className.equals(obj.getClassName()) || !defined.contains(className)) {
// System.out.println("Skipping check of " + ref);
continue checkConstant;
}
ConstantNameAndType nt = (ConstantNameAndType) cp.getConstant(co2.getNameAndTypeIndex());
String name = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getNameIndex(), CONSTANT_Utf8)).getBytes();
String signature = ((ConstantUtf8) obj.getConstantPool().getConstant(nt.getSignatureIndex(), CONSTANT_Utf8))
.getBytes();
try {
JavaClass target = Repository.lookupClass(className);
if (!find(target, name, signature))
bugReporter.reportBug(new BugInstance(this, "VR_UNRESOLVABLE_REFERENCE", NORMAL_PRIORITY).addClass(obj)
.addString(getMemberName(target.getClassName(), name, signature)));
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
}
}
}
}
示例14: ConstantPoolGen
import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
* Initialize with given constant pool.
*/
public ConstantPoolGen(ConstantPool cp) {
this(cp.getConstantPool());
}