use of spoon.reflect.declaration.CtInterface in project spoon by INRIA.
the class SpoonMetaModel method initializeConcept.
/**
* is called once for each {@link MetamodelConcept}, to initialize it.
* @param type a class or inteface of the spoon model element
* @param mmConcept to be initialize {@link MetamodelConcept}
*/
private void initializeConcept(CtType<?> type, MetamodelConcept mmConcept) {
// it is not initialized yet. Do it now
if (type instanceof CtInterface<?>) {
CtInterface<?> iface = (CtInterface<?>) type;
mmConcept.setModelClass(getImplementationOfInterface(iface));
mmConcept.setModelInterface(iface);
} else if (type instanceof CtClass<?>) {
CtClass<?> clazz = (CtClass<?>) type;
mmConcept.setModelClass(clazz);
mmConcept.setModelInterface(getInterfaceOfImplementation(clazz));
} else {
throw new SpoonException("Unexpected spoon model type: " + type.getQualifiedName());
}
// add fields of class
if (mmConcept.getModelClass() != null) {
addFieldsOfType(mmConcept, mmConcept.getModelClass());
}
// add fields of interface
if (mmConcept.getModelInterface() != null) {
// add fields of interface too. They are not added by above call of addFieldsOfType, because the MetamodelConcept already exists in nameToConcept
addFieldsOfType(mmConcept, mmConcept.getModelInterface());
}
// initialize all fields
mmConcept.getRoleToProperty().forEach((role, mmField) -> {
// if there are more methods for the same field then choose the one which best matches the field type
mmField.sortByBestMatch();
// finally initialize value type of this field
mmField.setValueType(mmField.detectValueType());
});
}
use of spoon.reflect.declaration.CtInterface in project spoon by INRIA.
the class ProcessingTest method testCallProcessorWithMultipleTypes.
@Test
public void testCallProcessorWithMultipleTypes() {
// contract: when calling a processor capable of treating CtClass and another capable of treating CtType, they are called on the right types
Launcher spoon = new Launcher();
spoon.addInputResource("./src/test/java/spoon/test/imports/testclasses");
CtClassProcessor classProcessor = new CtClassProcessor();
spoon.addProcessor(classProcessor);
CtTypeProcessor typeProcessor = new CtTypeProcessor();
spoon.addProcessor(typeProcessor);
CtInterfaceProcessor interfaceProcessor = new CtInterfaceProcessor();
spoon.addProcessor(interfaceProcessor);
spoon.run();
assertFalse(classProcessor.elements.isEmpty());
for (CtType type : classProcessor.elements) {
assertTrue("Type " + type.getSimpleName() + " is not a class", type instanceof CtClass);
}
assertFalse(classProcessor.elements.isEmpty());
for (CtType type : interfaceProcessor.elements) {
assertTrue("Type " + type.getSimpleName() + " is not an interface", type instanceof CtInterface);
}
assertFalse(typeProcessor.elements.isEmpty());
for (CtType type : typeProcessor.elements) {
if (type instanceof CtClass) {
assertTrue(classProcessor.elements.contains(type));
assertFalse(interfaceProcessor.elements.contains(type));
} else if (type instanceof CtInterface) {
assertFalse(classProcessor.elements.contains(type));
assertTrue(interfaceProcessor.elements.contains(type));
} else {
assertFalse(classProcessor.elements.contains(type));
assertFalse(interfaceProcessor.elements.contains(type));
}
}
}
Aggregations