use of org.ovirt.engine.ui.common.idhandler.WithElementId in project ovirt-engine by oVirt.
the class ElementIdTypeParserTest method stubPassingField.
void stubPassingField(JField field, JClassType fieldType, String fieldName) {
WithElementId idAnnotation = mock(WithElementId.class);
when(field.isPrivate()).thenReturn(false);
when(field.isStatic()).thenReturn(false);
when(field.getType()).thenReturn(fieldType);
when(field.getName()).thenReturn(fieldName);
when(fieldType.isClass()).thenReturn(fieldType);
when(field.getAnnotation(WithElementId.class)).thenReturn(idAnnotation);
// $NON-NLS-1$
when(idAnnotation.value()).thenReturn("");
when(idAnnotation.processType()).thenReturn(true);
}
use of org.ovirt.engine.ui.common.idhandler.WithElementId in project ovirt-engine by oVirt.
the class ElementIdTypeParser method doParse.
void doParse(JClassType parentType, List<JClassType> grandParents, String parentFieldExpression, String idPrefix) throws UnableToCompleteException {
for (JClassType type : parentType.getFlattenedSupertypeHierarchy()) {
for (JField field : type.getFields()) {
if (!processField(field)) {
continue;
}
JClassType fieldType = field.getType().isClass();
String fieldName = field.getName();
if (grandParents.contains(fieldType)) {
die(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"Field %s of type %s is already present on path from the owner type %s: %s", fieldName, fieldType.getQualifiedSourceName(), ownerType.getQualifiedSourceName(), grandParents.toString()));
}
WithElementId idAnnotation = field.getAnnotation(WithElementId.class);
String fieldId = idAnnotation.value();
if ("".equals(fieldId)) {
// $NON-NLS-1$
fieldId = fieldName;
}
String elementId = idPrefix + ID_ELEMENT_SEPARATOR + fieldId;
String fieldExpression = ElementIdHandlerGenerator.ElementIdHandler_generateAndSetIds_owner + parentFieldExpression + fieldName;
ElementIdStatement statement = new ElementIdStatement(fieldExpression, elementId);
if (statements.contains(statement)) {
die(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"Duplicate element ID %s for field %s of type %s", elementId, fieldName, fieldType.getQualifiedSourceName()));
}
statements.add(statement);
if (idAnnotation.processType()) {
List<JClassType> newGrandParents = new ArrayList<>(grandParents);
newGrandParents.add(fieldType);
// $NON-NLS-1$
doParse(fieldType, newGrandParents, parentFieldExpression + fieldName + ".", elementId);
}
}
}
}
use of org.ovirt.engine.ui.common.idhandler.WithElementId in project ovirt-engine by oVirt.
the class ElementIdTypeParserTest method stubFieldIdAnnotation.
void stubFieldIdAnnotation(JField field, String fieldId, boolean processType) {
WithElementId idAnnotation = mock(WithElementId.class);
when(field.getAnnotation(WithElementId.class)).thenReturn(idAnnotation);
when(idAnnotation.value()).thenReturn(fieldId);
when(idAnnotation.processType()).thenReturn(processType);
}
Aggregations