All Downloads are FREE. Search and download functionalities are using the official Maven repository.

eu.mihosoft.vmf.vmftext.grammar.impl.ReadOnlyRuleClassImpl Maven / Gradle / Ivy

The newest version!

package eu.mihosoft.vmf.vmftext.grammar.impl;

// vmf imports
//import eu.mihosoft.vmf.runtime.core.*;
//import eu.mihosoft.vmf.runtime.core.internal.*;
import eu.mihosoft.vcollections.*;
import eu.mihosoft.vmf.vmftext.grammar.*;
import java.beans.PropertyChangeListener;

// property types imports
import eu.mihosoft.vcollections.*;

// interface

/**
 * An read-only representation of the model object {@code eu.mihosoft.vmf.vmftext.grammar.RuleClass}.
 */
@SuppressWarnings("deprecation")
class ReadOnlyRuleClassImpl implements ReadOnlyRuleClass, eu.mihosoft.vmf.runtime.core.internal.VObjectInternal, VCloneableInternal {

  private final RuleClass mutableObject;

  // Read-only view for collection properties
  // - properties with collection type (model & non-model collections)
  // - we don't allow/provide setters for collection properties
  private VList childClasses;
     private VList customProperties;
    private VList customRuleAnnotations;
    private VList delegationMethods;
      private VList properties;
      private VList superInterfaces;
   
  public ReadOnlyRuleClassImpl(RuleClass mutableObject) {
    this.mutableObject = mutableObject;
  }


  @Override
  // generic type is a model-type
  public VList getChildClasses() {

    // we return an unmodifiable mapped list that contains read-only versions of the list elements
    // since read-only types and normal types are incompatible by design, we specify the lambda
    // operation that converts an element into a read-only version of that element
    if(this.childClasses == null) {
      this.childClasses = VMappedList.newUnmodifiableInstance(mutableObject.getChildClasses(), (e)->e.asReadOnly());
    }

    return this.childClasses;

 
  }


  @Override
  // property type is a model-type
  public CodeRange getCodeRange() {
    if(this.mutableObject.getCodeRange()!=null) {
      return this.mutableObject.getCodeRange();
    } else {
      return null;
    }
  }


  @Override
  // generic type is a model-type
  public VList getCustomProperties() {

    // we return an unmodifiable mapped list that contains read-only versions of the list elements
    // since read-only types and normal types are incompatible by design, we specify the lambda
    // operation that converts an element into a read-only version of that element
    if(this.customProperties == null) {
      this.customProperties = VMappedList.newUnmodifiableInstance(mutableObject.getCustomProperties(), (e)->e.asReadOnly());
    }

    return this.customProperties;

 
  }


  @Override
  // generic type is a model-type
  public VList getCustomRuleAnnotations() {

    // we return an unmodifiable mapped list that contains read-only versions of the list elements
    // since read-only types and normal types are incompatible by design, we specify the lambda
    // operation that converts an element into a read-only version of that element
    if(this.customRuleAnnotations == null) {
      this.customRuleAnnotations = VMappedList.newUnmodifiableInstance(mutableObject.getCustomRuleAnnotations(), (e)->e.asReadOnly());
    }

    return this.customRuleAnnotations;

 
  }


  @Override
  // generic type is a model-type
  public VList getDelegationMethods() {

    // we return an unmodifiable mapped list that contains read-only versions of the list elements
    // since read-only types and normal types are incompatible by design, we specify the lambda
    // operation that converts an element into a read-only version of that element
    if(this.delegationMethods == null) {
      this.delegationMethods = VMappedList.newUnmodifiableInstance(mutableObject.getDelegationMethods(), (e)->e.asReadOnly());
    }

    return this.delegationMethods;

 
  }


  @Override
  // property type is a model-type
  public ReadOnlyGrammarModel getModel() {
    if(this.mutableObject.getModel()!=null) {
      return this.mutableObject.getModel().asReadOnly();
    } else {
      return null;
    }
  }


  @Override
  public java.lang.String getName() {
    return this.mutableObject.getName();
  }


  @Override
  // generic type is a model-type
  public VList getProperties() {

    // we return an unmodifiable mapped list that contains read-only versions of the list elements
    // since read-only types and normal types are incompatible by design, we specify the lambda
    // operation that converts an element into a read-only version of that element
    if(this.properties == null) {
      this.properties = VMappedList.newUnmodifiableInstance(mutableObject.getProperties(), (e)->e.asReadOnly());
    }

    return this.properties;

 
  }


  @Override
  public boolean isRoot() {
    return this.mutableObject.isRoot();
  }


  @Override
  // property type is a model-type
  public ReadOnlyRuleClass getSuperClass() {
    if(this.mutableObject.getSuperClass()!=null) {
      return this.mutableObject.getSuperClass().asReadOnly();
    } else {
      return null;
    }
  }


  @Override
  public VList getSuperInterfaces() {

    if(this.superInterfaces == null) {
      this.superInterfaces = this.mutableObject.getSuperInterfaces();
    }

    return this.superInterfaces;
 
  }

 // end for each property

  @Override
  public void addPropertyChangeListener(PropertyChangeListener l) {
    ((eu.mihosoft.vmf.runtime.core.internal.VObjectInternal)this.mutableObject).addPropertyChangeListener(l);
  }

  @Override
  public void removePropertyChangeListener(PropertyChangeListener l) {
    ((eu.mihosoft.vmf.runtime.core.internal.VObjectInternal)this.mutableObject).removePropertyChangeListener(l);
  }

  @Override
  public String toString() {
    return this.mutableObject.toString();
  }

  @Override
  public boolean equals(Object o) {
    return this.mutableObject.equals(o);
  }

  @Override
  public int hashCode() {
    return this.mutableObject.hashCode();
  }

  @Override
  public RuleClass _vmf_getMutableObject() {
    return this.mutableObject;
  }

  @Override
  public ReadOnlyRuleClassImpl asReadOnly() {
    return this;
  }

  // --------------------------------------------------------------------
  // --- Cloning
  // --------------------------------------------------------------------

  @Override
  public ReadOnlyRuleClass clone() {
    return this.mutableObject.clone().asReadOnly();
  }

  @Override
  public RuleClass asModifiable() {
    return this.mutableObject.clone();
  }

  @Override
  public RuleClass _vmf_deepCopy(
    java.util.IdentityHashMap identityMap) {
    return (RuleClass)
      ((VCloneableInternal)this.mutableObject)._vmf_deepCopy(
        new java.util.IdentityHashMap<>());
  }

  @Override
  public ReadOnlyRuleClass _vmf_shallowCopy(
    java.util.IdentityHashMap identityMap) {
    return (ReadOnlyRuleClass)
      ((VCloneableInternal)this.mutableObject)._vmf_shallowCopy(
        new java.util.IdentityHashMap<>()).asReadOnly();
  }

  // --------------------------------------------------------------------
  // --- Public VMF API
  // --------------------------------------------------------------------

  @Override
  public eu.mihosoft.vmf.runtime.core.VMF vmf() {
    return new eu.mihosoft.vmf.runtime.core.VMF() {
      public eu.mihosoft.vmf.runtime.core.Content content() {
        return new eu.mihosoft.vmf.runtime.core.Content() {
          public eu.mihosoft.vmf.runtime.core.VIterator iterator() {
            return eu.mihosoft.vmf.runtime.core.VIterator.of(ReadOnlyRuleClassImpl.this);
          }
          public java.util.stream.Stream stream() {
            return eu.mihosoft.vmf.runtime.core.VIterator.of(ReadOnlyRuleClassImpl.this).asStream();
          }

          public eu.mihosoft.vmf.runtime.core.VIterator iterator(eu.mihosoft.vmf.runtime.core.VIterator.IterationStrategy strategy) {
            return eu.mihosoft.vmf.runtime.core.VIterator.of(ReadOnlyRuleClassImpl.this, strategy);
          }
          public java.util.stream.Stream stream(eu.mihosoft.vmf.runtime.core.VIterator.IterationStrategy strategy) {
            return eu.mihosoft.vmf.runtime.core.VIterator.of(ReadOnlyRuleClassImpl.this, strategy).asStream();
          }
          public  java.util.stream.Stream stream(Class type) {
            return stream().filter(e->type.isAssignableFrom(e.getClass())).map(e->(T)e);
          }
          public  java.util.stream.Stream stream(Class type, eu.mihosoft.vmf.runtime.core.VIterator.IterationStrategy strategy) {
            return stream(strategy).filter(e->type.isAssignableFrom(e.getClass())).map(e->(T)e);
          }
          public VList referencedBy() {
            return _vmf_referencedBy().asUnmodifiable();
          }
          public VList references() {
            return _vmf_references().asUnmodifiable();
          }

          @Override
          public ReadOnlyRuleClass deepCopy() {
            return (ReadOnlyRuleClassImpl)
              ((VCloneableInternal)ReadOnlyRuleClassImpl.this.mutableObject)._vmf_deepCopy(
                new java.util.IdentityHashMap<>()).asReadOnly();
          }

          @Override
          public ReadOnlyRuleClass shallowCopy() {
            return ReadOnlyRuleClassImpl.
              this._vmf_shallowCopy(new java.util.IdentityHashMap<>());
          }
        };
      }

      private eu.mihosoft.vmf.runtime.core.internal.ReflectImpl reflect;

      public eu.mihosoft.vmf.runtime.core.Reflect reflect() {
        if (reflect==null) {
          reflect = new eu.mihosoft.vmf.runtime.core.internal.ReflectImpl();
          reflect.setModel(ReadOnlyRuleClassImpl.this);
        }

        return reflect;
      }
    }; // end vmf
  }


  // --------------------------------------------------------------------
  // --- Reflection methods
  // --------------------------------------------------------------------

  // type id for improved reflection performance
  public static final int _VMF_TYPE_ID = 29;

  @Override
  public int _vmf_getTypeId() {
    return _VMF_TYPE_ID;
  }


  static final String[] _VMF_PROPERTY_NAMES = {
    "childClasses",
    "codeRange",
    "customProperties",
    "customRuleAnnotations",
    "delegationMethods",
    "model",
    "name",
    "properties",
    "root",
    "superClass",
    "superInterfaces"
  };

  static final String[] _VMF_PROPERTY_TYPE_NAMES = {
    "eu.mihosoft.vcollections.VList", // type id -2
    "eu.mihosoft.vmf.vmftext.grammar.CodeRange", // type id 8
    "eu.mihosoft.vcollections.VList", // type id -2
    "eu.mihosoft.vcollections.VList", // type id -2
    "eu.mihosoft.vcollections.VList", // type id -2
    "eu.mihosoft.vmf.vmftext.grammar.GrammarModel", // type id 14
    "java.lang.String", // type id -1
    "eu.mihosoft.vcollections.VList", // type id -2
    "boolean", // type id -1
    "eu.mihosoft.vmf.vmftext.grammar.RuleClass", // type id 28
    "eu.mihosoft.vcollections.VList"  // type id -2
  };

  static final int[] _VMF_PROPERTY_TYPES = {
       -2, // type eu.mihosoft.vcollections.VList
        8, // type eu.mihosoft.vmf.vmftext.grammar.CodeRange
       -2, // type eu.mihosoft.vcollections.VList
       -2, // type eu.mihosoft.vcollections.VList
       -2, // type eu.mihosoft.vcollections.VList
       14, // type eu.mihosoft.vmf.vmftext.grammar.GrammarModel
       -1, // type java.lang.String
       -2, // type eu.mihosoft.vcollections.VList
       -1, // type boolean
       28, // type eu.mihosoft.vmf.vmftext.grammar.RuleClass
       -2  // type eu.mihosoft.vcollections.VList
  };


  /**
   * - indices of model objects as properties
   * - parents, i.e., containers are skipped
   * - only indices of reference properties and contained elements, i.e.,
   *   children are listed here
   */
  static final int[] _VMF_PROPERTIES_WITH_MODEL_TYPES_INDICES = {
        1, // type eu.mihosoft.vmf.vmftext.grammar.CodeRange
        5, // type eu.mihosoft.vmf.vmftext.grammar.GrammarModel
  };

  /**
   * - indices of lists that contain model objects as elements
   */
  static final int[] _VMF_PROPERTIES_WITH_MODEL_ELEMENT_TYPES_INDICES = {
        0, // type eu.mihosoft.vcollections.VList
        2, // type eu.mihosoft.vcollections.VList
        3, // type eu.mihosoft.vcollections.VList
        4, // type eu.mihosoft.vcollections.VList
        7, // type eu.mihosoft.vcollections.VList
  };

  /**
   * - indices of model objects as properties and model objects as
   *   elements of lists
   * - parents, i.e., containers are skipped
   * - only indices of reference properties and contained elements, i.e.,
   *   children are listed here
   */
  static final int[] _VMF_PROPERTIES_WITH_MODEL_TYPE_OR_ELEMENT_TYPES_INDICES = {
        0, // type eu.mihosoft.vcollections.VList
        1, // type eu.mihosoft.vmf.vmftext.grammar.CodeRange
        2, // type eu.mihosoft.vcollections.VList
        3, // type eu.mihosoft.vcollections.VList
        4, // type eu.mihosoft.vcollections.VList
        5, // type eu.mihosoft.vmf.vmftext.grammar.GrammarModel
        7, // type eu.mihosoft.vcollections.VList
  };

  /**
   * - indices of model children
   * - parents, i.e., containers and pure references are skipped
   * - only indices of contained elements, i.e.,
   *   children are listed here
   */
  static final int[] _VMF_CHILDREN_INDICES = {
        0, // type eu.mihosoft.vcollections.VList
        2, // type eu.mihosoft.vcollections.VList
        3, // type eu.mihosoft.vcollections.VList
        4, // type eu.mihosoft.vcollections.VList
        5, // type eu.mihosoft.vmf.vmftext.grammar.GrammarModel
        7, // type eu.mihosoft.vcollections.VList
  };

  @Override
  public String[] _vmf_getPropertyNames() {
    return _VMF_PROPERTY_NAMES;
  }

  @Override
  public int[] _vmf_getPropertyTypes() {
    return _VMF_PROPERTY_TYPES;
  }

  @Override
  public String[] _vmf_getPropertyTypeNames() {
    return _VMF_PROPERTY_TYPE_NAMES;
  }

  @Override
  public int[] _vmf_getIndicesOfPropertiesWithModelTypes() {
    return _VMF_PROPERTIES_WITH_MODEL_TYPES_INDICES;
  }

  @Override
  public int[] _vmf_getIndicesOfPropertiesWithModelElementTypes() {
    return _VMF_PROPERTIES_WITH_MODEL_ELEMENT_TYPES_INDICES;
  }

  @Override
  public int[] _vmf_getIndicesOfPropertiesWithModelTypeOrElementTypes() {
    return _VMF_PROPERTIES_WITH_MODEL_TYPE_OR_ELEMENT_TYPES_INDICES;
  }

  @Override
  public int[] _vmf_getChildrenIndices() {
    return _VMF_CHILDREN_INDICES;
  }

  @Override
  public Object _vmf_getPropertyValueById(int propertyId) {

    switch(propertyId) {
      case 0:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getChildClasses();
      case 1:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getCodeRange();
      case 2:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getCustomProperties();
      case 3:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getCustomRuleAnnotations();
      case 4:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getDelegationMethods();
      case 5:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getModel();
      case 6:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getName();
      case 7:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getProperties();
      case 8:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return isRoot();
      case 9:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getSuperClass();
      case 10:
        // TODO check whether we can prevent lazy initialized properties from
        //      being initialized just for iterating the object graph
        return getSuperInterfaces();
    }

    return null;
  }

  @Override
  public int _vmf_getPropertyIdByName(String propertyName) {
    switch(propertyName) {
      case "childClasses":
        return 0;
      case "codeRange":
        return 1;
      case "customProperties":
        return 2;
      case "customRuleAnnotations":
        return 3;
      case "delegationMethods":
        return 4;
      case "model":
        return 5;
      case "name":
        return 6;
      case "properties":
        return 7;
      case "root":
        return 8;
      case "superClass":
        return 9;
      case "superInterfaces":
        return 10;
      default:
        return -1;
    } // end switch
  }


  @Override
  public Object _vmf_getDefaultValueById(int propertyId) {

    switch(propertyId) {
      case 0:
        Object __vmf_default_value_tmpChildClasses = _VMF_DEFAULT_VALUES[0];
        if(__vmf_default_value_tmpChildClasses==null) {
            return null;
        } else {
            return __vmf_default_value_tmpChildClasses;
        }

      case 1:
        Object __vmf_default_value_tmpCodeRange = _VMF_DEFAULT_VALUES[0];
        if(__vmf_default_value_tmpCodeRange==null) {
            return null;
        } else {
            return __vmf_default_value_tmpCodeRange;
        }

      case 2:
        Object __vmf_default_value_tmpCustomProperties = _VMF_DEFAULT_VALUES[1];
        if(__vmf_default_value_tmpCustomProperties==null) {
            return null;
        } else {
            return __vmf_default_value_tmpCustomProperties;
        }

      case 3:
        Object __vmf_default_value_tmpCustomRuleAnnotations = _VMF_DEFAULT_VALUES[2];
        if(__vmf_default_value_tmpCustomRuleAnnotations==null) {
            return null;
        } else {
            return __vmf_default_value_tmpCustomRuleAnnotations;
        }

      case 4:
        Object __vmf_default_value_tmpDelegationMethods = _VMF_DEFAULT_VALUES[3];
        if(__vmf_default_value_tmpDelegationMethods==null) {
            return null;
        } else {
            return __vmf_default_value_tmpDelegationMethods;
        }

      case 5:
        Object __vmf_default_value_tmpModel = _VMF_DEFAULT_VALUES[4];
        if(__vmf_default_value_tmpModel==null) {
            return null;
        } else {
            return __vmf_default_value_tmpModel;
        }

      case 6:
        Object __vmf_default_value_tmpName = _VMF_DEFAULT_VALUES[0];
        if(__vmf_default_value_tmpName==null) {
            return null;
        } else {
            return __vmf_default_value_tmpName;
        }

      case 7:
        Object __vmf_default_value_tmpProperties = _VMF_DEFAULT_VALUES[5];
        if(__vmf_default_value_tmpProperties==null) {
            return null;
        } else {
            return __vmf_default_value_tmpProperties;
        }

      case 8:
        Object __vmf_default_value_tmpRoot = _VMF_DEFAULT_VALUES[6];
        if(__vmf_default_value_tmpRoot==null) {
            return
            false;
        } else {
            return __vmf_default_value_tmpRoot;
        }    

      case 9:
        Object __vmf_default_value_tmpSuperClass = _VMF_DEFAULT_VALUES[7];
        if(__vmf_default_value_tmpSuperClass==null) {
            return null;
        } else {
            return __vmf_default_value_tmpSuperClass;
        }

      case 10:
        Object __vmf_default_value_tmpSuperInterfaces = _VMF_DEFAULT_VALUES[8];
        if(__vmf_default_value_tmpSuperInterfaces==null) {
            return null;
        } else {
            return __vmf_default_value_tmpSuperInterfaces;
        }

    } // end switch

    return null;
  }

  @Override
  public void _vmf_setDefaultValueById(int propertyId, Object defaultValue) {

    // property childClasses
    if(propertyId == 0) { 
      throw new RuntimeException("Cannot set default value for property 'childClasses' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property customProperties
    if(propertyId == 2) { 
      throw new RuntimeException("Cannot set default value for property 'customProperties' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property customRuleAnnotations
    if(propertyId == 3) { 
      throw new RuntimeException("Cannot set default value for property 'customRuleAnnotations' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property delegationMethods
    if(propertyId == 4) { 
      throw new RuntimeException("Cannot set default value for property 'delegationMethods' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property model
    if(propertyId == 5) { 
      throw new RuntimeException("Cannot set default value for property 'model' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property properties
    if(propertyId == 7) { 
      throw new RuntimeException("Cannot set default value for property 'properties' with id="+propertyId +": property is a containment property and not writable.");
    }
    // property superClass
    if(propertyId == 9) { 
      throw new RuntimeException("Cannot set default value for property 'superClass' with id="+propertyId +": property is a containment property and not writable.");
    }

  }

  @Override
  public boolean _vmf_isSetById(int propertyId) {
    return !java.util.Objects.equals(_vmf_getDefaultValueById(propertyId), _vmf_getPropertyValueById(propertyId));
  }


  final Object[] _VMF_DEFAULT_VALUES = {
    null, // type childClasses (containment type, no defaut value possible)  
    null, // type codeRange   
    null, // type customProperties (containment type, no defaut value possible)  
    null, // type customRuleAnnotations (containment type, no defaut value possible)  
    null, // type delegationMethods (containment type, no defaut value possible)  
    null, // type model (containment type, no defaut value possible)  
    null, // type name   
    null, // type properties (containment type, no defaut value possible)  
    null, // type root   
    null, // type superClass (containment type, no defaut value possible)  
    null  // type superInterfaces   
  };

  @Override
  public boolean _vmf_isReadOnly() {
    return true;
  }

  // --------------------------------------------------------------------
  // --- Id related methods
  // --------------------------------------------------------------------

  // id management is currently not part of VMF (TODO how should we support this?)

  // --------------------------------------------------------------------
  // --- Reference methods
  // --------------------------------------------------------------------

  public VList _vmf_referencedBy() { return  ((eu.mihosoft.vmf.runtime.core.internal.VObjectInternalModifiable)this.mutableObject)._vmf_referencedBy();}

  public VList _vmf_references() { return  ((eu.mihosoft.vmf.runtime.core.internal.VObjectInternalModifiable)this.mutableObject)._vmf_references();}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy