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

org.snapscript.tree.define.ConstantPropertyBuilder Maven / Gradle / Ivy

There is a newer version: 1.4.6
Show newest version
package org.snapscript.tree.define;

import static org.snapscript.core.ModifierType.CONSTANT;
import static org.snapscript.core.ModifierType.STATIC;

import java.util.List;

import org.snapscript.core.constraint.Constraint;
import org.snapscript.core.constraint.DeclarationConstraint;
import org.snapscript.core.function.Accessor;
import org.snapscript.core.function.AccessorProperty;
import org.snapscript.core.function.ScopeAccessor;
import org.snapscript.core.function.StaticAccessor;
import org.snapscript.core.property.Property;
import org.snapscript.core.type.Type;
import org.snapscript.core.type.TypeBody;

public class ConstantPropertyBuilder {
   
   public ConstantPropertyBuilder() {
      super();
   }
   
   public Property createStaticProperty(TypeBody body, String name, Type type, Constraint constraint) {
      Constraint constant = new DeclarationConstraint(constraint, STATIC.mask | CONSTANT.mask);
      Accessor accessor = new StaticAccessor(body, type, name, name);
      Property property = new AccessorProperty(name, name, type, constant, accessor, STATIC.mask | CONSTANT.mask);
      
      if(type != null) {
         List properties = type.getProperties();
         properties.add(property);
      }
      return property;
   }

   public Property createInstanceProperty(String name, Type type, Constraint constraint) {
      Constraint constant = new DeclarationConstraint(constraint, STATIC.mask | CONSTANT.mask);
      Accessor accessor = new ScopeAccessor(name, name);
      Property property = new AccessorProperty(name, name, type, constant, accessor, CONSTANT.mask); // is this the correct type!!??
      
      if(type != null) {
         List properties = type.getProperties();
         properties.add(property);
      }
      return property;
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy