当前位置: 首页>>代码示例>>Java>>正文


Java ConstantPool.getConstantPool方法代码示例

本文整理汇总了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);
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:24,代码来源:ImportListBuilder.java

示例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;
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:21,代码来源:ClassFanInCounter.java

示例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);
            }
          
              
        }
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:26,代码来源:StaticCalendarDetector.java

示例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();
    }
}
 
开发者ID:spacewalkproject,项目名称:spacewalk,代码行数:24,代码来源:FindStrings.java

示例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] = "&lt;unknown&gt;";
    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();
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:27,代码来源:ConstantHTML.java

示例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);
    }
  }
}
 
开发者ID:mizdebsk,项目名称:java-deptools,代码行数:31,代码来源:JavaClass.java

示例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;
                }
            }
        }
    }

}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:30,代码来源:TapestryEndpointDetector.java

示例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);
	}
}
 
开发者ID:cniweb,项目名称:ant-contrib,代码行数:13,代码来源:VerifyDesignDelegate.java

示例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;
}
 
开发者ID:MCCarbon,项目名称:DecompileTools,代码行数:22,代码来源:ClassFinderHelpers.java

示例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);
	}
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:30,代码来源:JUnitTestListBuilder.java

示例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);
	}
}
 
开发者ID:vimaier,项目名称:conqat,代码行数:33,代码来源:ConQATInstallationDependencyGraphBuilder.java

示例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++;
    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:12,代码来源:PreorderVisitor.java

示例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);
            }
        }

    }
}
 
开发者ID:ytus,项目名称:findbugs-all-the-bugs,代码行数:46,代码来源:ResolveAllReferences.java

示例14: ConstantPoolGen

import org.apache.bcel.classfile.ConstantPool; //导入方法依赖的package包/类
/**
 * Initialize with given constant pool.
 */
public ConstantPoolGen(ConstantPool cp) {
    this(cp.getConstantPool());
}
 
开发者ID:Hu6,项目名称:VestaClient,代码行数:7,代码来源:ConstantPoolGen.java


注:本文中的org.apache.bcel.classfile.ConstantPool.getConstantPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。