use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class SubArrayVisitor method visitAnnotation.
/**
* Visit an annotation element of the visited array.
*
* @param name : null
* @param desc : annotation to visit
* @return the visitor which will visit the annotation
* @see org.objectweb.asm.AnnotationVisitor#visitAnnotation(String, String)
*/
public AnnotationVisitor visitAnnotation(String name, String desc) {
// Sub annotations are map to sub-elements
Element elem = Elements.buildElement(Type.getType(desc));
m_elem.addElement(elem);
return new GenericVisitor(elem);
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class MetadataRenderer method renderElement.
private void renderElement(Element element, StringBuilder builder) {
// If the element is already here, do not re-add the element.
if (!isFiltered(element)) {
// Print the beginning of the element
startElement(element, builder);
// Render all attributes
for (Attribute attribute : element.getAttributes()) {
renderAttribute(attribute, builder);
}
// Render child elements
for (Element child : element.getElements()) {
renderElement(child, builder);
}
// Print the end of the element
endElement(builder);
}
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class InnerClassAdapterTest method testThatManipulationMetadataContainsTheInnerClasses.
@Test
public void testThatManipulationMetadataContainsTheInnerClasses() throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
String className = "test.inner.ComponentWithInnerClasses";
manipulate(className, manipulator);
assertThat(manipulator.getInnerClasses().size()).isEqualTo(3);
Element manipulation = manipulator.getManipulationMetadata();
System.out.println(manipulation);
Element[] inners = manipulation.getElements("inner");
assertThat(inners.length).isEqualTo(3);
Element inner = getInnerClassMetadataByName(inners, "MyInnerWithANativeMethod");
assertThat(inner).isNotNull();
assertThat(getMethodByName(inner.getElements("method"), "foo")).isNotNull();
inner = getInnerClassMetadataByName(inners, "MyInnerClass");
assertThat(inner).isNotNull();
assertThat(getMethodByName(inner.getElements("method"), "foo")).isNotNull();
inner = getInnerClassMetadataByName(inners, "1");
assertThat(inner).isNotNull();
assertThat(getMethodByName(inner.getElements("method"), "compute")).isNotNull();
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class RemanipulationTest method testDoubleManipulationWithAnnotations.
/**
* Tests checking that the consecutive manipulation does still returns valid metadata (from annotations),
* and valid manipulation metadata.
*
* @throws IOException
* @throws ClassNotFoundException
*/
public void testDoubleManipulationWithAnnotations() throws IOException, ClassNotFoundException {
Reporter reporter = mock(Reporter.class);
// Step 1 - First collection and manipulation
// 1.1 Metadata collection
byte[] origin = ManipulatorTest.getBytesFromFile(new File("target/test-classes/test/PlentyOfAnnotations.class"));
MiniStore store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", origin);
AnnotationMetadataProvider provider = new AnnotationMetadataProvider(store, reporter);
List<Element> originalMetadata = provider.getMetadatas();
// 1.2 Manipulation
Manipulator manipulator = new Manipulator(this.getClass().getClassLoader());
manipulator.prepare(origin);
byte[] clazz = manipulator.manipulate(origin);
Element originalManipulationMetadata = manipulator.getManipulationMetadata();
// 1.3 Check that the class is valid
ManipulatedClassLoader classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
Class cl = classloader.findClass("test.PlentyOfAnnotations");
Assert.assertNotNull(cl);
// ---------------
// Step 2 - Second collection and manipulation
// We use the output class as entry.
// 2.1 Metadata collection
store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz);
provider = new AnnotationMetadataProvider(store, reporter);
List<Element> metadataAfterOneManipulation = provider.getMetadatas();
// 2.2 Manipulation
manipulator = new Manipulator(this.getClass().getClassLoader());
manipulator.prepare(clazz);
byte[] clazz2 = manipulator.manipulate(clazz);
Element manipulationMetadataAfterSecondManipulation = manipulator.getManipulationMetadata();
// 2.3 Check that the class is valid
classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
cl = classloader.findClass("test.PlentyOfAnnotations");
Assert.assertNotNull(cl);
// ---------------
// Step 3 - Third collection and manipulation
// We use the output class of 2 as entry.
// 3.1 Metadata collection
store = new MiniStore().addClassToStore("test.PlentyOfAnnotations", clazz2);
provider = new AnnotationMetadataProvider(store, reporter);
List<Element> metadataAfterTwoManipulation = provider.getMetadatas();
// 3.2 Manipulation
manipulator = new Manipulator(this.getClass().getClassLoader());
manipulator.prepare(clazz2);
byte[] clazz3 = manipulator.manipulate(clazz2);
Element manipulationMetadataAfterThirdManipulation = manipulator.getManipulationMetadata();
// 3.3 Check that the class is valid
classloader = new ManipulatedClassLoader("test.PlentyOfAnnotations", clazz);
cl = classloader.findClass("test.PlentyOfAnnotations");
Assert.assertNotNull(cl);
// ---------------
// Verification
// Unchanged metadata
Assert.assertEquals(originalMetadata.toString(), metadataAfterOneManipulation.toString());
Assert.assertEquals(originalMetadata.toString(), metadataAfterTwoManipulation.toString());
// Unchanged manipulation metadata
Assert.assertEquals(originalManipulationMetadata.toString(), manipulationMetadataAfterSecondManipulation.toString());
Assert.assertEquals(originalManipulationMetadata.toString(), manipulationMetadataAfterThirdManipulation.toString());
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class ManipulationEngineTestCase method testManipulationOfSimpleClass.
public void testManipulationOfSimpleClass() throws Exception {
when(store.read(anyString())).thenReturn(from(ClusterDaemon.class));
when(visitor.visitManipulationResult(any(Element.class))).thenReturn(result);
String path = Strings.asResourcePath(ClusterDaemon.class.getName());
Element metadata = new Element("", "");
ManipulationUnit info = new ManipulationUnit(path, metadata);
engine.addManipulationUnit(info);
engine.generate();
verify(visitor).visitManipulationResult(eq(metadata));
verify(result).visitClassStructure(any(Element.class));
verify(result).visitManipulatedResource(eq(path), any(byte[].class));
verify(result).visitEnd();
}
Aggregations