Search in sources :

Example 1 with WithElementId

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);
}
Also used : WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId)

Example 2 with WithElementId

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);
            }
        }
    }
}
Also used : JClassType(com.google.gwt.core.ext.typeinfo.JClassType) JField(com.google.gwt.core.ext.typeinfo.JField) WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId) ArrayList(java.util.ArrayList)

Example 3 with WithElementId

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);
}
Also used : WithElementId(org.ovirt.engine.ui.common.idhandler.WithElementId)

Aggregations

WithElementId (org.ovirt.engine.ui.common.idhandler.WithElementId)3 JClassType (com.google.gwt.core.ext.typeinfo.JClassType)1 JField (com.google.gwt.core.ext.typeinfo.JField)1 ArrayList (java.util.ArrayList)1