Example usage for java.lang.reflect Modifier Modifier

List of usage examples for java.lang.reflect Modifier Modifier

Introduction

In this page you can find the example usage for java.lang.reflect Modifier Modifier.

Prototype

Modifier

Source Link

Usage

From source file:rubah.tools.UpdateClassGenerator.java

private Map<String, Object> buildTemplateModel(String outJavaPackage) {
    Map<String, Object> templateModel = new HashMap<String, Object>();

    templateModel.put("package", outJavaPackage);
    templateModel.put("namespace", this.defaultNamespace);
    templateModel.put("modifier", new Modifier());
    templateModel.put("helper", this);
    templateModel.put("convertName", METHOD_NAME);
    templateModel.put("convertStaticName", METHOD_NAME_STATIC);
    templateModel.put("copyStaticFieldsMethodName", COPY_METHOD_NAME_STATIC);

    HashSet<ChangesTemplateModel> detectedChanges = new HashSet<ChangesTemplateModel>();
    for (Entry<Clazz, ClassChange> change : this.changes.entrySet()) {

        if (change.getValue().getChangeSet().hasChange(ChangeType.NEW_CLASS)) {
            continue;
        }/*from  ww w . j a v  a2  s .  co m*/

        ChangesTemplateModel ctm = new ChangesTemplateModel(
                this.addPreffixToFQN(change.getValue().getOriginal()), this.addPreffixToFQN(change.getKey()));

        if (this.allClasses) {
            ctm.hasStaticChanges = true;
            ctm.hasNonStaticChanges = true;
        }

        for (Entry<Field, Change<Field>> fieldChange : change.getValue().getFieldChanges().entrySet()) {

            if (this.isHashCode(fieldChange)) {
                continue;
            }

            ChangeSet changeSet = fieldChange.getValue().getChangeSet();

            if (changeSet.hasChange(ChangeType.NEW_FIELD)) {
                if (Modifier.isStatic(fieldChange.getKey().getAccess())) {
                    ctm.hasStaticChanges = true;
                } else {
                    ctm.hasNonStaticChanges = true;
                }
                ctm.newFields.add(new Pair<Field, Change<Field>>(fieldChange.getKey(), fieldChange.getValue()));
            } else if (changeSet.hasChange(ChangeType.NEW_CONSTANT)) {
                ctm.hasStaticChanges = true;
                ctm.newConstants
                        .add(new Pair<Field, Change<Field>>(fieldChange.getKey(), fieldChange.getValue()));
            } else if (changeSet.hasChange(ChangeType.FIELD_TYPE_CHANGE)) {
                if (Modifier.isStatic(fieldChange.getKey().getAccess())) {
                    ctm.hasStaticChanges = true;
                } else {
                    ctm.hasNonStaticChanges = true;
                }
                ctm.typeChangedFields
                        .add(new Pair<Field, Change<Field>>(fieldChange.getKey(), fieldChange.getValue()));
            } else {
                ctm.unmodifiedFields
                        .add(new Pair<Field, Change<Field>>(fieldChange.getKey(), fieldChange.getValue()));
            }
        }

        if (ctm.hasNonStaticChanges || ctm.hasStaticChanges) {
            detectedChanges.add(ctm);
        }
    }

    templateModel.put("classes", detectedChanges);

    return templateModel;
}