org.apache.bcel.util.SyntheticRepository Java Examples

The following examples show how to use org.apache.bcel.util.SyntheticRepository. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FieldAnnotationsTestCase.java    From commons-bcel with Apache License 2.0 6 votes vote down vote up
/**
 * Check field AnnotationEntrys (de)serialize ok.
 */
public void testFieldAnnotationEntrysReadWrite() throws ClassNotFoundException,
        IOException
{
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.AnnotatedFields");
    checkAnnotatedField(clazz, "i", "L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;", "id", "1");
    checkAnnotatedField(clazz, "s", "L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;", "id", "2");
    // Write it out
    final File tfile = createTestdataFile("AnnotatedFields.class");
    clazz.dump(tfile);
    final SyntheticRepository repos2 = createRepos(".");
    repos2.loadClass("AnnotatedFields");
    checkAnnotatedField(clazz, "i", "L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;", "id", "1");
    checkAnnotatedField(clazz, "s", "L"+PACKAGE_BASE_SIG+"/data/SimpleAnnotation;", "id", "2");
    assertTrue(tfile.delete());
}
 
Example #2
Source File: GeneratingAnnotatedClassesTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
private JavaClass getClassFrom(final String where, final String clazzname)
        throws ClassNotFoundException
{
    // System.out.println(where);
    final SyntheticRepository repos = createRepos(where);
    return repos.loadClass(clazzname);
}
 
Example #3
Source File: EnclosingMethodAttributeTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
/**
 * Check that we can save and load the attribute correctly.
 */
public void testAttributeSerializtion() throws ClassNotFoundException,
        IOException
{
    final JavaClass clazz = getTestClass(PACKAGE_BASE_NAME+".data.AttributeTestClassEM02$1");
    final ConstantPool pool = clazz.getConstantPool();
    final Attribute[] encMethodAttrs = findAttribute("EnclosingMethod", clazz);
    assertTrue("Expected 1 EnclosingMethod attribute but found "
            + encMethodAttrs.length, encMethodAttrs.length == 1);
    // Write it out
    final File tfile = createTestdataFile("AttributeTestClassEM02$1.class");
    clazz.dump(tfile);
    // Read in the new version and check it is OK
    final SyntheticRepository repos2 = createRepos(".");
    final JavaClass clazz2 = repos2.loadClass("AttributeTestClassEM02$1");
    Assert.assertNotNull(clazz2); // Use the variable to avoid a warning
    final EnclosingMethod em = (EnclosingMethod) encMethodAttrs[0];
    final String enclosingClassName = em.getEnclosingClass().getBytes(pool);
    assertTrue(
            "The class is not within a method, so method_index should be null, but it is "
                    + em.getEnclosingMethodIndex(), em
                    .getEnclosingMethodIndex() == 0);
    assertTrue(
            "Expected class name to be '"+PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02' but was "
                    + enclosingClassName, enclosingClassName
                    .equals(PACKAGE_BASE_SIG+"/data/AttributeTestClassEM02"));
    tfile.deleteOnExit();
}
 
Example #4
Source File: AbstractTestCase.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
protected JavaClass getTestClass(final String name) throws ClassNotFoundException
{
    return SyntheticRepository.getInstance().loadClass(name);
}
 
Example #5
Source File: AbstractTestCase.java    From commons-bcel with Apache License 2.0 4 votes vote down vote up
public SyntheticRepository createRepos(final String cpentry)
{
    final ClassPath cp = new ClassPath("target" + File.separator + "testdata"
            + File.separator + cpentry + File.separator);
    return SyntheticRepository.getInstance(cp);
}