예제 #1
0
    /// <summary>
    /// Sets the stat scaling on this weapon based on the user character's selected attribute. </summary>
    /// <param name='userStats'> User character's stat module. </param>
    public void SetScaling(ICharacter user)
    {
        switch (scalingAttribute) {
                case CharacterAttribute.AttributeName.Vitality:
                        _scalingAtt = user.CharStats.Vitality;
                        break;
                case CharacterAttribute.AttributeName.Endurance:
                        _scalingAtt = user.CharStats.Endurance;
                        break;
                case CharacterAttribute.AttributeName.Spirit:
                        _scalingAtt = user.CharStats.Spirit;
                        break;
                case CharacterAttribute.AttributeName.Strength:
                        _scalingAtt = user.CharStats.Strength;
                        break;
                case CharacterAttribute.AttributeName.Dexterity:
                        _scalingAtt = user.CharStats.Dexterity;
                        break;
                case CharacterAttribute.AttributeName.Mind:
                        _scalingAtt = user.CharStats.Mind;
                        break;
                default:
                        _scalingAtt = null;
                        break;
                }

                if (_scalingAtt == null)
                        Debug.Log ("no scaling attribute set!");
    }
 public void Modify(IAttribute originalAttribute, IAttribute newAttribute)
 {
     ICodeExpressionNode codeExpressionNode = newAttribute.AddCodeExpressionNode();
     codeExpressionNode.SetExpressionBody(new CodeExpression("true"));
     IConditionalExpressionNodeWrapper conditionalExpressionNodeWrapper = newAttribute.AddConditionalExpressionNode();
     conditionalExpressionNodeWrapper.SetExpressionBody(new ConditionalExpression(_syntaxProvider.CreateNullCheckAndEvalExpression(originalAttribute.GetTextValue()), originalAttribute.GetTextValue()));
 }
		public IList<IAttribute> Resolve(IAssembly currentAssembly)
		{
			// TODO: make this a per-assembly cache
//				CacheManager cache = currentAssembly.Compilation.CacheManager;
//				IList<IAttribute> result = (IList<IAttribute>)cache.GetShared(this);
//				if (result != null)
//					return result;
			
			ITypeResolveContext context = new SimpleTypeResolveContext(currentAssembly);
			BlobReader reader = new BlobReader(blob, currentAssembly);
			if (reader.ReadByte() != '.') {
				// should not use UnresolvedSecurityDeclaration for XML secdecls
				throw new InvalidOperationException();
			}
			ResolveResult securityActionRR = securityAction.Resolve(context);
			uint attributeCount = reader.ReadCompressedUInt32();
			IAttribute[] attributes = new IAttribute[attributeCount];
			try {
				ReadSecurityBlob(reader, attributes, context, securityActionRR);
			} catch (NotSupportedException) {
				// ignore invalid blobs
				//Debug.WriteLine(ex.ToString());
			}
			for (int i = 0; i < attributes.Length; i++) {
				if (attributes[i] == null)
					attributes[i] = new CecilResolvedAttribute(context, SpecialType.UnknownType);
			}
			return attributes;
//				return (IList<IAttribute>)cache.GetOrAddShared(this, attributes);
		}
 private static IAssociations GetTargetModifierList(IAttribute target, string modifierType)
 {
     switch (modifierType)
     {
         case "ModAdd":
             return target.AdditionAssociations;
         case "ModSub":
             return target.SubstractionAssociations;
         case "PostAssignment":
             return target.PostAssignmentAssociations;
         case "PostDiv":
             return target.PostDivisionAssociations;
         case "PostMul":
             return target.PostMultiplicationAssociations;
         case "PostPercent":
             return target.PostPercentAssociations;
         case "PreAssignment":
             return target.PreAssignmentAssociations;
         case "PreDiv":
             return target.PreDivisionAssociations;
         case "PreMul":
             return target.PreMultiplicationAssociations;
         case "9":
             //skilllevel modifier
             return new DummyAssociations();
         default://TODO richtiger exceptiontyp
             throw new Exception("unknown modifier type: " + modifierType);
     }
 }
 private ConditionalExpression GetConditionalResourceExpression(IAttribute fromAttribute)
 {
     string targetResource = fromAttribute.GetTextValue();
     string nullCheck = _syntaxProvider.CreateNullCheckExpression(targetResource);
     string uriExpression = _syntaxProvider.CreateUriExpression(targetResource);
     return new ConditionalExpression(nullCheck, uriExpression);
 }
 /// <summary>
 /// Creates a new <see cref="pMixinAttributeResolvedResult"/>
 /// </summary>
 /// <param name="attribute">
 /// Reference to the <see cref="CopaceticSoftware.pMixin"/>'s source code.
 /// </param>
 public pMixinAttributeResolvedResult(IAttribute attribute)
     : base(attribute)
 {
     Masks = new List<IType>(0);
     Interceptors = new List<IType>(0);
     EnableSharedRequirementsInterface = new pMixinAttribute().EnableSharedRequirementsInterface;
 }
예제 #7
0
 protected virtual void WriteAttribute(IXhtmlWriter writer, IAttribute attribute)
 {
     if (!attribute.IsDefault || attribute.RendersOnDefaultValue)
     {
         writer.WriteAttributeString(attribute.Name.ToLowerInvariant(), attribute.SerializedValue);
     }
 }
예제 #8
0
 internal EventInfo(Type declaringType, string name, MethodInfo addMethod, MethodInfo removeMethod, IAttribute[] attributes)
 {
     _declaringType = declaringType;
     _name = name;
     _addMethod = addMethod;
     _removeMethod = removeMethod;
     _attributes = attributes;
 }
 public void Modify(IAttribute originalAttribute, IAttribute newAttribute)
 {
     ICodeExpressionNode node = newAttribute.AddCodeExpressionNode();
     string expression = _syntaxProvider.CreateGetPropertyPathExpression(originalAttribute.GetTextValue());
     node.SetExpressionBody(
         new CodeExpression(expression)
         );
 }
		/// <summary>
		/// Tworzymy ciało, dodajemy do managera i zamieniamy atrybut Position na taki, który trzyma pozycje zgodną z silnikiem fizycznym.
		/// </summary>
		public override void OnInit()
		{
			this._Body = this.Owner.Attributes.GetOrCreate<Body>("Body");
			this.Body = FarseerPhysics.Factories.BodyFactory.CreateBody(PhysicsManager.Instance.World);
			this.Body.BodyType = (this.IsDynamic ? BodyType.Dynamic : BodyType.Static);

			this.Owner.Attributes.Replace("Position", new Internals.PhysicalPositionAttribute("Position", this.Body));
			this.Owner.Attributes.Replace("Rotation", new Internals.PhysicalRotationAttribute("Rotation", this.Body));
		}
예제 #11
0
		public override void AddAssemblyAttribute(IProject targetProject, IAttribute attribute)
		{
			// FIXME : will fail if there are no assembly attributes
			ICompilation compilation = SD.ParserService.GetCompilation(targetProject);
			IAttribute target = compilation.MainAssembly.AssemblyAttributes.LastOrDefault();
			if (target == null)
				throw new InvalidOperationException("no assembly attributes found, cannot continue!");
			AddAttribute(target.Region, attribute, "assembly");
		}
예제 #12
0
 public bool TryAttribute(string name, out IAttribute attr) {
     if (Attributes.Any()) {
         if (Attributes.Exists(a => a.Name == name)) {
             attr = Attributes.First(a => a.Name == name);
             return true;
         }
     }
     attr = null;
     return false;
 }
예제 #13
0
        public IAttributeValue CreateValue(IAttribute attribute, String value)
        {
            //            checkArgument(value != null, "Value cannot be null.");
            throw new NotImplementedException();
            //AttributeValue rv = new AttributeValue(attribute);
            //rv.setValue(value);
            //_List.Add(rv);

            //return rv;
        }
예제 #14
0
 public static bool IsRefined(this IClass @class, IAttribute attribute)
 {
     var refine = @class.AttributeConstraints.Any(c => c.Constrains == attribute) || @class.Attributes.Any(r => r.Refines == attribute);
     if (refine) return true;
     foreach (var baseType in @class.BaseTypes)
     {
         if (baseType == attribute.DeclaringType) return false;
         if (IsRefined(baseType, attribute)) return true;
     }
     return false;
 }
예제 #15
0
        public static void Assign(this IAttribute attribute, IAttribute other)
        {
            Debug.Assert(attribute != null);
            if (other == null)
                return;

            Debug.Assert(attribute.GetType() == other.GetType());
            foreach (var eachProperty in attribute.GetType().GetProperties())
            {
                eachProperty.SetValue(attribute, eachProperty.GetValue(other));
            }
        }
예제 #16
0
 public static string ToString(IAttribute attribute)
 {
     var builder = new StringBuilder();
     var attributeType = attribute.GetType();
     builder.Append("  - ").Append(attributeType.Name).AppendLine();
     foreach (var eachProperty in attributeType.GetProperties())
     {
         var propertyValue = eachProperty.GetValue(attribute);
         builder.Append("    - ").Append(eachProperty.Name).Append('=').Append(propertyValue).AppendLine();
     }
     return builder.ToString();
 }
예제 #17
0
		public void CreateAttribute(string fullName, string shortName)
		{
			var returnTypeHelper = new ReturnTypeHelper();
			returnTypeHelper.CreateReturnType(fullName);
			returnTypeHelper.AddShortName(shortName);
			AttributeType = returnTypeHelper.ReturnType;
			
			Attribute = MockRepository.GenerateStub<IAttribute>();
			Attribute.Stub(a => a.AttributeType).Return(AttributeType);
			Attribute.Stub(a => a.PositionalArguments).Return(PositionalArguments);
			Attribute.Stub(a => a.NamedArguments).Return(NamedArguments);
		}
예제 #18
0
        private static object ApplyMinConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo)
        {
            switch (constraints.ValueType)
            {
                case ConstraintsValueType.IntValue:
                    return Math.Max(newValue.As<int>(), constraints.IntValue);

                case ConstraintsValueType.FloatValue:
                    return Math.Max(newValue.As<float>(), constraints.FloatValue);

                case ConstraintsValueType.Reference:
                    return Math.Max(newValue.As<float>(), propertyInfo.GetValue(attribute).As<float>());
            }
            throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType);
        }
예제 #19
0
        public static IAttribute GetCustomAttribute(IAttribute attribute, INode parent, IQualifiedName name, string value)
        {
            var attributeName = attribute.Name.ToString();

            if (!customAttributeFactories.ContainsKey(attributeName))
                return null;

            foreach (var factory in customAttributeFactories[attributeName])
            {
                if (factory.IsValidFor(attribute))
                    return factory.Create(parent, name, value);
            }

            return null;
        }
			public override void OnInit()
			{
				this.VelocityMultiplier = this.Owner.Attributes.GetOrCreate<float>("VelocityMultiplier");

				(this.Owner as IUnit).CollisionWithResource += new CollisionWithResourceEventHandler(CollisionWithResource);
				(this.Owner as IUnit).CollisionWithPlayer += new CollisionWithPlayerEventHandler(CollisionWithPlayer);

				var body = this.Owner.Attributes.Get<Body>("Body");
				if (body == null || body.Value == null || body.Value.FixtureList.Count == 0)
				{
					throw new ClashEngine.NET.Exceptions.NotFoundException("Body");
				}
				//Dodajemy kolizję, by kolidował z zasobami
				body.Value.AddCollidesWith(Category.Cat10);
				body.Value.AddCollisionCategories((Category)((int)Category.Cat11 << (int)(this.Owner as IUnit).Owner.Type));
			}
        public virtual int CompareTo(IAttribute value)
        {
            int cmp;

            cmp = Name.CompareTo(value.Name);
            if (cmp != 0) {
                return cmp;
            }

            cmp = DiffUtility.Compare(PositionalArguments, value.PositionalArguments);
            if (cmp != 0) {
                return cmp;
            }

            return DiffUtility.Compare(NamedArguments, value.NamedArguments);
        }
예제 #22
0
 public static ICollection<string> GetAttributeConstraintValue(this IClass referenceClass, IAttribute attribute)
 {
     var attRefinement = referenceClass.AttributeConstraints.FirstOrDefault(c => c.Constrains == attribute);
     if (attRefinement != null)
     {
         return attRefinement.Values;
     }
     foreach (var baseClass in referenceClass.BaseTypes)
     {
         var value = baseClass.GetAttributeConstraintValue(attribute);
         if (value != null)
         {
             return value;
         }
     }
     return null;
 }
 public bool IsAvailable(IUserDataHolder cache)
 {
     _propertyAssignment = null;
     _dllImportAttribute = null;
     Func<IAttribute, bool> isDllImportAttribute = a =>
     {
         var typeReference = a.TypeReference;
         if (typeReference != null)
         {
             var typeElement = typeReference.Resolve().DeclaredElement as ITypeElement;
             if (typeElement != null && Equals(typeElement.GetClrName(), DllImportMissingAnalyzer.DllImportAttribute))
             {
                 return true;
             }
         }
         return false;
     };
     var method = _provider.GetSelectedElement<IMethodDeclaration>(true, true);
     if (method == null)
     {
         return false;
     }
     var attribute = method.Attributes.FirstOrDefault(isDllImportAttribute);
     if (attribute == null || !attribute.IsValid())
     {
         return false;
     }
     _dllImportAttribute = attribute;
     var entryPoint = attribute.PropertyAssignments.FirstOrDefault(pa => pa.PropertyNameIdentifier.Name == "EntryPoint");
     if (entryPoint == null)
     {
         return true;
     }
     _propertyAssignment = entryPoint;
     var literal = entryPoint.Source as ICSharpLiteralExpression;
     if (literal != null)
     {
         if (!literal.IsConstantValue())
         {
             return true;
         }
         var value = literal.ConstantValue.Value as string;
         return value != method.NameIdentifier.Name;
     }
     return false;
 }
예제 #24
0
 public bool TryAttribute(string name, out IAttribute attr)
 {
     if (_attributes == null)
     {
         _attributes = new Dictionary<string, IAttribute>();
         for (int i = 0; i < Attributes.Count; i++)
         {
             _attributes[Attributes[i].Name] = Attributes[i];
         }
     }
     if (_attributes.ContainsKey(name))
     {
         attr = _attributes[name];
         return true;
     }
     attr = null;
     return false;
 }
예제 #25
0
        private static object ApplyMaxConstraints(ConstraintsAttribute constraints, object newValue, IAttribute attribute, PropertyInfo propertyInfo)
        {
            switch (constraints.ValueType)
            {
                case ConstraintsValueType.IntValue:
                    return Math.Min(newValue.As<int>(), constraints.IntValue);

                case ConstraintsValueType.FloatValue:
                    return Math.Min(newValue.As<float>(), constraints.FloatValue);

                case ConstraintsValueType.Reference:
                    {
                        var attributeType = attribute.GetType();
                        var referenceProperty = attributeType.GetProperty(constraints.FieldName.ToCamelCase());
                        return Math.Min(newValue.As<float>(), referenceProperty.GetValue(attribute).As<float>());
                    }
            }
            throw new InvalidOperationException("invalid value-type for max constraints: " + constraints.ValueType);
        }
예제 #26
0
        public sealed override bool IsAvailable(JetBrains.Util.IUserDataHolder cache)
        {
            attributesOwnerDeclaration = provider.GetSelectedElement<IAttributesOwnerDeclaration>(true, false);

            if (attributesOwnerDeclaration != null && attributesOwnerDeclaration.GetNameRange().Contains(provider.SelectedTreeRange) &&
                !attributesOwnerDeclaration.OverridesInheritedMember() && !attributesOwnerDeclaration.AttributesEnumerable.Any(IsAttribute))
            {
                createAttributeFactory = CreateAttributeFactoryIfAvailable(attributesOwnerDeclaration, provider.PsiModule, out attributeToRemove);

                if (createAttributeFactory != null)
                {
                    return true;
                }
            }

            attributeToRemove = null;
            createAttributeFactory = null;
            attributesOwnerDeclaration = null;

            return false;
        }
예제 #27
0
        public static object ApplyConstraints(IAttribute attribute, string propertyName, object newValue)
        {
            Debug.Assert(attribute != null);
            var attributeType = attribute.GetType();
            var propertyInfo = attributeType.GetProperty(propertyName);
            Debug.Assert(propertyInfo != null);

            foreach (var constraints in propertyInfo.GetCustomAttributes(typeof(ConstraintsAttribute), false).OfType<ConstraintsAttribute>())
            {
                switch (constraints.Type)
                {
                    case ConstraintsType.Min:
                        newValue = ApplyMinConstraints(constraints, newValue, attribute, propertyInfo);
                        break;

                    case ConstraintsType.Max:
                        newValue = ApplyMaxConstraints(constraints, newValue, attribute, propertyInfo);
                        break;
                }
            }
            return Convert.ChangeType(newValue, propertyInfo.PropertyType);
        }
예제 #28
0
 public static ICollection<IAttribute> Decompose(this IClass scope, IAttribute attribute)
 {
     var layering = Layering<IClass>.CreateLayers(scope, cl => cl.BaseTypes);
     var attributes = new HashSet<IAttribute>();
     attributes.Add(attribute);
     foreach (var layer in layering)
     {
         if (layer.Count > 1)
         {
             throw new InvalidOperationException("There is a cycle in the inheritance hierarchy.");
         }
         foreach (var cl in layer)
         {
             foreach (var att in cl.Attributes)
             {
                 if (att.Refines != null && attributes.Contains(att.Refines))
                 {
                     attributes.Add(att);
                 }
             }
         }
     }
     return attributes;
 }
        protected sealed override Func<CSharpElementFactory, IAttribute> CreateAttributeFactoryIfAvailable(
            IAttributesOwnerDeclaration attributesOwnerDeclaration,
            IPsiModule module,
            out IAttribute attributeToRemove)
        {
            var attributeType =
                attributesOwnerDeclaration.GetPsiServices()
                    .GetComponent<CodeAnnotationsConfiguration>()
                    .GetAttributeTypeForElement(attributesOwnerDeclaration, AnnotationAttributeTypeName);
            if (attributeType != null && CanBeAnnotated(attributesOwnerDeclaration.DeclaredElement, attributesOwnerDeclaration, module))
            {
                attributeToRemove = TryGetAttributeToReplace(attributesOwnerDeclaration);

                return factory =>
                {
                    Debug.Assert(factory != null);

                    return factory.CreateAttribute(attributeType);
                };
            }

            attributeToRemove = null;
            return null;
        }
예제 #30
0
        protected virtual List <string> WriteObjectInitializer(IList <KeyValuePair <IMember, ResolveResult> > expressions, bool preserveMemberCase, TypeDefinition type, IAttribute attr)
        {
            bool          needComma  = false;
            List <string> names      = new List <string>();
            List <string> inlineInit = new List <string>();

            if (expressions != null)
            {
                foreach (KeyValuePair <IMember, ResolveResult> item in expressions)
                {
                    var member       = item.Key;
                    var preserveCase = !this.Emitter.IsNativeMember(member.FullName) && preserveMemberCase;
                    var name         = this.Emitter.GetEntityName(member, preserveCase);

                    var inlineCode = AttributeCreateBlock.GetInlineInit(item, this);

                    if (inlineCode != null)
                    {
                        inlineInit.Add(inlineCode);
                    }
                    else
                    {
                        if (member is IProperty)
                        {
                            name = Helpers.GetPropertyRef(member, this.Emitter, true);
                        }
                        else if (member is IEvent)
                        {
                            name = Helpers.GetEventRef(member, this.Emitter, false);
                        }

                        if (needComma)
                        {
                            this.WriteComma();
                        }

                        needComma = true;

                        this.Write(name, ": ");

                        AttributeCreateBlock.WriteResolveResult(item.Value, this);

                        names.Add(name);
                    }
                }
            }

            if (this.Emitter.Validator.IsObjectLiteral(type))
            {
                var key   = BridgeTypes.GetTypeDefinitionKey(type);
                var tinfo = this.Emitter.Types.FirstOrDefault(t => t.Key == key);

                if (tinfo == null)
                {
                    return(inlineInit);
                }
                var itype = tinfo.Type as ITypeDefinition;

                var mode = 0;
                if (attr.Constructor != null)
                {
                    if (itype != null)
                    {
                        var oattr = this.Emitter.Validator.GetAttribute(itype.Attributes, Translator.Bridge_ASSEMBLY + ".ObjectLiteralAttribute");
                        if (oattr.PositionalArguments.Count > 0)
                        {
                            var value = oattr.PositionalArguments.First().ConstantValue;

                            if (value is int)
                            {
                                mode = (int)value;
                            }
                        }
                    }
                }

                if (mode != 0)
                {
                    var members = tinfo.InstanceConfig.Fields.Concat(tinfo.InstanceConfig.Properties);

                    if (members.Any())
                    {
                        foreach (var member in members)
                        {
                            if (mode == 1 && (member.VarInitializer == null || member.VarInitializer.Initializer.IsNull))
                            {
                                continue;
                            }

                            var name = member.GetName(this.Emitter);

                            if (!preserveMemberCase)
                            {
                                name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
                            }

                            if (names.Contains(name))
                            {
                                continue;
                            }

                            if (needComma)
                            {
                                this.WriteComma();
                            }

                            needComma = true;

                            this.Write(name, ": ");

                            var primitiveExpr = member.Initializer as PrimitiveExpression;

                            if (primitiveExpr != null && primitiveExpr.Value is AstType)
                            {
                                this.Write(Inspector.GetStructDefaultValue((AstType)primitiveExpr.Value, this.Emitter));
                            }
                            else
                            {
                                member.Initializer.AcceptVisitor(this.Emitter);
                            }
                        }
                    }
                }
            }

            return(inlineInit);
        }
예제 #31
0
 public override void CopyTo(IAttribute target)
 {
 }
 public int CompareTo(IAttribute attribute) => string.Compare(this.Name, attribute.Name, StringComparison.OrdinalIgnoreCase);
예제 #33
0
        private static JObject ConstructConstructorInfo(IMethod constructor, IEmitter emitter, bool includeDeclaringType, bool isGenericSpecialization, SyntaxTree tree)
        {
            var properties = MetadataUtils.GetCommonMemberInfoProperties(constructor, emitter, includeDeclaringType, isGenericSpecialization, tree);

            if (Helpers.IsNonScriptable(constructor))
            {
                return(null);
            }

            properties.Add("t", (int)MemberTypes.Constructor);
            if (constructor.Parameters.Count > 0)
            {
                properties.Add("p", new JArray(constructor.Parameters.Select(p => new JRaw(MetadataUtils.GetTypeName(p.Type, emitter, isGenericSpecialization)))));
            }

            var parametersInfo = constructor.Parameters.Select(p => MetadataUtils.ConstructParameterInfo(p, emitter, false, false, tree)).ToList();

            if (parametersInfo.Count > 0)
            {
                properties.Add("pi", new JArray(parametersInfo));
            }

            var        inline     = emitter.GetInline(constructor);
            var        typeDef    = constructor.DeclaringTypeDefinition;
            IAttribute customCtor = null;

            if (typeDef != null)
            {
                customCtor = emitter.Validator.GetAttribute(typeDef.Attributes, Translator.Bridge_ASSEMBLY + ".ConstructorAttribute");
            }

            if (string.IsNullOrEmpty(inline) && customCtor == null)
            {
                string sname;
                if (constructor.IsStatic || constructor.DeclaringType.Kind == TypeKind.Anonymous)
                {
                    sname = JS.Funcs.CONSTRUCTOR;
                }
                else
                {
                    sname = OverloadsCollection.Create(emitter, constructor).GetOverloadName();
                }

                properties.Add("sn", sname);
            }

            if (constructor.IsStatic)
            {
                properties.Add("sm", true);
            }

            if (string.IsNullOrEmpty(inline) && constructor.Attributes.Any(a => a.AttributeType.FullName == "Bridge.ExpandParamsAttribute"))
            {
                properties.Add("exp", true);
            }

            if (!string.IsNullOrEmpty(inline))
            {
                var block     = new InlineArgumentsBlock(emitter, new ArgumentsInfo(emitter, constructor), inline, constructor);
                var oldWriter = block.SaveWriter();
                block.NewWriter();
                block.EmitFunctionReference(true);
                var str = emitter.Output.ToString();
                block.RestoreWriter(oldWriter);

                properties.Add("def", new JRaw(str));
            }
            else if (customCtor != null)
            {
                inline = customCtor.PositionalArguments[0].ConstantValue.ToString();
                if (Regex.Match(inline, @"\s*\{\s*\}\s*").Success)
                {
                    var names = constructor.Parameters.Select(p => p.Name);

                    StringBuilder sb = new StringBuilder("function(" + string.Join(", ", names.ToArray()) + ") { return {");

                    bool needComma = false;
                    foreach (var name in names)
                    {
                        if (needComma)
                        {
                            sb.Append(", ");
                        }

                        needComma = true;

                        sb.Append(name + ": " + name);
                    }
                    sb.Append("};}");
                    properties.Add("def", new JRaw(sb.ToString()));
                }
                else
                {
                    var block     = new InlineArgumentsBlock(emitter, new ArgumentsInfo(emitter, constructor), inline, constructor);
                    var oldWriter = block.SaveWriter();
                    block.NewWriter();
                    block.EmitFunctionReference(true);
                    var str = emitter.Output.ToString();
                    block.RestoreWriter(oldWriter);

                    properties.Add("def", new JRaw(str));
                }
            }

            return(properties);
        }
예제 #34
0
        public override void CopyTo(IAttribute target)
        {
            ReadingAttribute t = (ReadingAttribute)target;

            t.SetToken(token);
        }
예제 #35
0
        protected virtual void WritePositionalList(IList <ResolveResult> expressions, IAttribute attr)
        {
            bool needComma   = false;
            int  count       = this.Emitter.Writers.Count;
            bool expanded    = false;
            int  paramsIndex = -1;

            if (attr.Constructor.Parameters.Any(p => p.IsParams))
            {
                paramsIndex = attr.Constructor.Parameters.IndexOf(attr.Constructor.Parameters.FirstOrDefault(p => p.IsParams));
                var or = new OverloadResolution(this.Emitter.Resolver.Compilation, expressions.ToArray());
                or.AddCandidate(attr.Constructor);
                expanded = or.BestCandidateIsExpandedForm;
            }

            for (int i = 0; i < expressions.Count; i++)
            {
                var expr = expressions[i];

                if (needComma)
                {
                    this.WriteComma();
                }

                needComma = true;

                if (expanded && paramsIndex == i)
                {
                    this.WriteOpenBracket();
                }

                AttributeCreateBlock.WriteResolveResult(expr, this);

                if (this.Emitter.Writers.Count != count)
                {
                    this.PopWriter();
                    count = this.Emitter.Writers.Count;
                }
            }

            if (expanded)
            {
                this.WriteCloseBracket();
            }
        }
예제 #36
0
 public bool Contains(IAttribute item)
 {
     return(_attributes.ContainsKey(item.Name));
 }
예제 #37
0
        public override void CopyTo(IAttribute target)
        {
            OffsetAttribute t = (OffsetAttribute)target;

            t.SetOffset(startOffset, endOffset);
        }
예제 #38
0
 public bool OnValueChanged(IAttribute sender, AttributeValueChangedEventArgs args, IAttributeModifier modifier)
 {
     return(false);
 }
예제 #39
0
 static bool IsComAttribute(IAttribute attribute, string name)
 {
     return(attribute.AttributeType.Name == name && attribute.AttributeType.Namespace == "System.Runtime.InteropServices");
 }
예제 #40
0
 public void Add(IAttribute attr)
 {
     attributes.Add(attr);
 }
 internal MissingSuppressionJustificationHighlighting(
     [NotNull] IAttributesOwnerDeclaration attributesOwnerDeclaration,
     [NotNull] IAttribute attribute,
     [NotNull] string message) : base(attributesOwnerDeclaration, attribute, false, message)
 {
 }
예제 #42
0
        protected override void DoEmit()
        {
            IAttribute attribute = this.Attribute;

            var type = this.Emitter.GetTypeDefinition(attribute.AttributeType);

            var argsInfo = new ArgumentsInfo(this.Emitter, attribute);

            string inlineCode = this.Emitter.GetInline(attribute.Constructor);

            var customCtor     = this.Emitter.Validator.GetCustomConstructor(type) ?? "";
            var hasInitializer = attribute.NamedArguments.Count > 0;

            if (inlineCode == null && Regex.Match(customCtor, @"\s*\{\s*\}\s*").Success)
            {
                this.WriteOpenBrace();
                this.WriteSpace();

                if (hasInitializer)
                {
                    this.WriteObjectInitializer(attribute.NamedArguments, this.Emitter.AssemblyInfo.PreserveMemberCase, type, attribute);
                    this.WriteSpace();
                }
                else if (this.Emitter.Validator.IsObjectLiteral(type))
                {
                    this.WriteObjectInitializer(null, this.Emitter.AssemblyInfo.PreserveMemberCase, type, attribute);
                    this.WriteSpace();
                }

                this.WriteCloseBrace();
            }
            else
            {
                if (hasInitializer)
                {
                    this.Write(JS.Funcs.BRIDGE_MERGE);
                    this.WriteOpenParentheses();
                }

                if (inlineCode != null)
                {
                    new InlineArgumentsBlock(this.Emitter, argsInfo, inlineCode, attribute.Constructor).Emit();
                }
                else
                {
                    if (String.IsNullOrEmpty(customCtor))
                    {
                        this.WriteNew();
                        this.Write(BridgeTypes.ToJsName(attribute.AttributeType, this.Emitter));
                    }
                    else
                    {
                        this.Write(customCtor);
                    }

                    if (!this.Emitter.Validator.IsExternalType(type) && type.Methods.Count(m => m.IsConstructor && !m.IsStatic) > (type.IsValueType ? 0 : 1))
                    {
                        this.WriteDot();
                        var name = OverloadsCollection.Create(this.Emitter, attribute.Constructor).GetOverloadName();
                        this.Write(name);
                    }

                    this.WriteOpenParentheses();

                    this.WritePositionalList(attribute.PositionalArguments, attribute);
                    this.WriteCloseParentheses();
                }

                if (hasInitializer)
                {
                    this.WriteComma();

                    this.BeginBlock();

                    var inlineInit = this.WriteObjectInitializer(attribute.NamedArguments, this.Emitter.AssemblyInfo.PreserveMemberCase, type, attribute);

                    this.WriteNewLine();

                    this.EndBlock();

                    if (inlineInit.Count > 0)
                    {
                        this.Write(", function () ");
                        this.BeginBlock();

                        foreach (var init in inlineInit)
                        {
                            this.Write(init);
                            this.WriteNewLine();
                        }

                        this.EndBlock();
                    }

                    this.WriteSpace();
                    this.WriteCloseParentheses();
                }
            }
        }
예제 #43
0
        public override void CopyTo(IAttribute target)
        {
            CharTermAttribute t = (CharTermAttribute)target;

            t.CopyBuffer(termBuffer, 0, termLength);
        }
예제 #44
0
 public bool Remove(IAttribute item)
 {
     return(_attributes.Remove(item.Name));
 }
예제 #45
0
 public AttributeCreateBlock(IEmitter emitter, IAttribute attribute)
     : base(emitter, null)
 {
     this.Emitter   = emitter;
     this.Attribute = attribute;
 }
예제 #46
0
        public override void Start(ICoreAPI api)
        {
            this.api = api;

            worldConfig = api.World.Config;
            if (worldConfig == null)
            {
                worldConfig = new TreeAttribute();
            }

            List <IAsset> entries = api.Assets.GetMany("patches/");

            int appliedCount        = 0;
            int notfoundCount       = 0;
            int errorCount          = 0;
            int totalCount          = 0;
            int unmetConditionCount = 0;

            foreach (IAsset asset in entries)
            {
                JsonPatch[] patches = null;
                try
                {
                    patches = asset.ToObject <JsonPatch[]>();
                } catch (Exception e)
                {
                    api.World.Logger.Error("Failed loading patches file {0}: {1}", asset.Location, e);
                }

                for (int j = 0; patches != null && j < patches.Length; j++)
                {
                    JsonPatch patch = patches[j];
                    if (patch.Condition != null)
                    {
                        IAttribute attr = worldConfig[patch.Condition.When];
                        if (attr == null)
                        {
                            continue;
                        }

                        if (patch.Condition.useValue)
                        {
                            patch.Value = new JsonObject(JToken.Parse(attr.ToJsonToken()));
                        }
                        else
                        {
                            if (!patch.Condition.IsValue.Equals(attr.GetValue() + "", StringComparison.InvariantCultureIgnoreCase))
                            {
                                unmetConditionCount++;
                                continue;
                            }
                        }
                    }

                    totalCount++;
                    ApplyPatch(j, asset.Location, patch, ref appliedCount, ref notfoundCount, ref errorCount);
                }
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("JsonPatch Loader: ");

            if (totalCount == 0)
            {
                sb.Append(Lang.Get("Nothing to patch", totalCount));
            }
            else
            {
                sb.Append(Lang.Get("{0} patches total", totalCount));

                if (appliedCount > 0)
                {
                    sb.Append(Lang.Get(", successfully applied {0} patches", appliedCount));
                }

                if (notfoundCount > 0)
                {
                    sb.Append(Lang.Get(", missing files on {0} patches", notfoundCount));
                }

                if (unmetConditionCount > 0)
                {
                    sb.Append(Lang.Get(", unmet conditions on {0} patches", unmetConditionCount));
                }

                if (errorCount > 0)
                {
                    sb.Append(Lang.Get(", had errors on {0} patches", errorCount));
                }
                else
                {
                    sb.Append(Lang.Get(", no errors", errorCount));
                }
            }


            api.World.Logger.Notification(sb.ToString());
            base.Start(api);
        }
 public bool OnValueChanged(IAttribute sender, AttributeValueChangedEventArgs args, IAttributeModifier modifier)
 {
     throw new NotImplementedException();
 }
예제 #48
0
 public CodeAttribute(IAttribute attribute)
 {
     this.attribute = attribute;
 }
예제 #49
0
        public override void CopyTo(IAttribute target)
        {
            PositionLengthAttribute t = (PositionLengthAttribute)target;

            t.PositionLength = positionLength;
        }
예제 #50
0
 public IAttribute AddAttributeAfter(IAttribute param, IAttribute anchor)
 {
     return(_classDeclaration.AddAttributeAfter(param, anchor));
 }
예제 #51
0
 public static IEntity GetParent(this IAttribute att)
 {
     return(null); //TODO:
 }
예제 #52
0
        public void SerializableAttribute()
        {
            IAttribute attr = ctx.GetClass(typeof(NonCustomAttributes)).Attributes.Single();

            Assert.AreEqual("System.SerializableAttribute", attr.AttributeType.Resolve(ctx).FullName);
        }
예제 #53
0
 public void RemoveAttribute(IAttribute param)
 {
     _classDeclaration.RemoveAttribute(param);
 }
예제 #54
0
 private static bool CheckName(IAttribute attribute, params string[] names)
 {
     return(attribute != null && names != null && names.Any(name => attribute.AttributeType.FullName == name));
 }
예제 #55
0
        static bool AreChildrenAsProperties(IType type, out string defaultProperty)
        {
            bool childrenAsProperties = false;

            defaultProperty = "";

            IAttribute att     = GetAttributes(type, "System.Web.UI.ParseChildrenAttribute").FirstOrDefault();
            var        posArgs = att.PositionalArguments;

            if (att == null || posArgs.Count == 0)
            {
                return(childrenAsProperties);
            }

            if (posArgs.Count > 0)
            {
                var expr = posArgs [0];
                if (expr == null)
                {
                    LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", expr);
                    return(false);
                }

                if (expr.ConstantValue is bool)
                {
                    childrenAsProperties = (bool)expr.ConstantValue;
                }
                else
                {
                    //TODO: implement this
                    LoggingService.LogWarning("ASP.NET completion does not yet handle ParseChildrenAttribute (Type)");
                    return(false);
                }
            }

            if (posArgs.Count > 1)
            {
                var expr = posArgs [1];
                if (expr == null || !(expr.ConstantValue is string))
                {
                    LoggingService.LogWarning("Unknown expression '{0}' in IAttribute parameter", expr);
                    return(false);
                }
                defaultProperty = (string)expr.ConstantValue;
            }

            var namedArgs = att.NamedArguments;

            if (namedArgs.Count > 0)
            {
                if (namedArgs.Any(p => p.Key.Name == "ChildrenAsProperties"))
                {
                    var expr = namedArgs.First(p => p.Key.Name == "ChildrenAsProperties").Value;
                    if (expr == null)
                    {
                        LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", expr);
                        return(false);
                    }
                    childrenAsProperties = (bool)expr.ConstantValue;
                }
                if (namedArgs.Any(p => p.Key.Name == "DefaultProperty"))
                {
                    var expr = namedArgs.First(p => p.Key.Name == "DefaultProperty").Value;
                    if (expr == null)
                    {
                        LoggingService.LogWarning("Unknown expression type {0} in IAttribute parameter", expr);
                        return(false);
                    }
                    defaultProperty = (string)expr.ConstantValue;
                }
                if (namedArgs.Any(p => p.Key.Name == "ChildControlType"))
                {
                    //TODO: implement this
                    LoggingService.LogWarning("ASP.NET completion does not yet handle ParseChildrenAttribute (Type)");
                    return(false);
                }
            }

            return(childrenAsProperties);
        }
예제 #56
0
 public override void CopyTo(IAttribute target)
 {
     ((BoostAttribute)target).Boost = boost;
 }
예제 #57
0
 /// <summary> Copies the values from this <see cref="Attribute"/> into the passed-in
 /// <paramref name="target"/> attribute. The <paramref name="target"/> implementation must support all the
 /// <see cref="IAttribute"/>s this implementation supports.
 /// </summary>
 public abstract void CopyTo(IAttribute target);
            public override void CopyTo(IAttribute target)
            {
                IMockRetainAttribute t = (IMockRetainAttribute)target;

                t.Retain = retain;
            }
			static string BuildArguments (IAttribute attr)
			{
				var sb = new StringBuilder ();
				foreach (var arg in attr.PositionalArguments) {
					if (sb.Length > 0)
						sb.Append (", ");
					var cr = arg as ConversionResolveResult;
					if (cr != null) {
						AppendConstant (sb, cr.Input.ConstantValue);
						continue;
					}
					AppendConstant (sb, arg.ConstantValue);
				}
				return sb.ToString ();
			}
        public new static void RegisterType(ModelBuilder modelBuilder)
        {
            IModelElementTypeBuilder typeBuilder = modelBuilder.DefineType <IMultiInstanceLoopCharacteristics>(/*typeof(IMultiInstanceLoopCharacteristics),*/ BpmnModelConstants.BpmnElementMultiInstanceLoopCharacteristics)
                                                   .NamespaceUri(BpmnModelConstants.Bpmn20Ns)
                                                   .ExtendsType(typeof(ILoopCharacteristics))
                                                   .InstanceProvider(new ModelTypeInstanceProviderAnonymousInnerClass());

            IsSequentialAttribute = typeBuilder
                                    .BooleanAttribute(BpmnModelConstants.BpmnElementIsSequential)
                                    .DefaultValue(false)
                                    .Build();

            BehaviorAttribute = typeBuilder
                                .EnumAttribute <MultiInstanceFlowCondition>(BpmnModelConstants.BpmnElementBehavior /*, typeof(MultiInstanceFlowCondition)*/)
                                .DefaultValue(MultiInstanceFlowCondition.All)
                                .Build();

            OneBehaviorEventRefAttribute = typeBuilder
                                           .StringAttribute(BpmnModelConstants.BpmnElementOneBehaviorEventRef)
                                           .QNameAttributeReference <IEventDefinition>(/*typeof(IEventDefinition)*/)
                                           .Build();

            NoneBehaviorEventRefAttribute = typeBuilder
                                            .StringAttribute(BpmnModelConstants.BpmnElementNoneBehaviorEventRef)
                                            .QNameAttributeReference <IEventDefinition>(/*typeof(IEventDefinition)*/)
                                            .Build();

            ISequenceBuilder sequenceBuilder = typeBuilder.Sequence();

            LoopCardinalityChild = sequenceBuilder
                                   .Element <ILoopCardinality>(/*typeof(ILoopCardinality)*/)
                                   .Build/*<ILoopCardinality>*/ ();

            LoopDataInputRefChild = sequenceBuilder
                                    .Element <LoopDataInputRef>(/*typeof(LoopDataInputRef)*/)
                                    .QNameElementReference <IDataInput>(/*typeof(IDataInput)*/)
                                    .Build();

            LoopDataOutputRefChild = sequenceBuilder
                                     .Element <LoopDataOutputRef>(/*typeof(LoopDataOutputRef)*/)
                                     .QNameElementReference <IDataOutput>(/*typeof(IDataOutput)*/)
                                     .Build();

            OutputDataItemChild = sequenceBuilder
                                  .Element <IOutputDataItem>(/*typeof(IOutputDataItem)*/)
                                  .Build/*<IOutputDataItem>*/ ();

            InputDataItemChild = sequenceBuilder
                                 .Element <INputDataItem>(/*typeof(INputDataItem)*/)
                                 .Build/*<INputDataItem>*/ ();

            ComplexBehaviorDefinitionCollection = sequenceBuilder
                                                  .ElementCollection <IComplexBehaviorDefinition>(/*typeof(IComplexBehaviorDefinition)*/)
                                                  .Build/*<IComplexBehaviorDefinition>*/ ();

            CompletionConditionChild = sequenceBuilder
                                       .Element <ICompletionCondition>(/*typeof(ICompletionCondition)*/)
                                       .Build/*<ICompletionCondition>*/ ();

            camundaAsyncAfter = typeBuilder
                                .BooleanAttribute(BpmnModelConstants.CamundaAttributeAsyncAfter)
                                .Namespace(BpmnModelConstants.CamundaNs).DefaultValue(false)
                                .Build();

            camundaAsyncBefore = typeBuilder
                                 .BooleanAttribute(BpmnModelConstants.CamundaAttributeAsyncBefore)
                                 .Namespace(BpmnModelConstants.CamundaNs)
                                 .DefaultValue(false)
                                 .Build();

            camundaExclusive = typeBuilder
                               .BooleanAttribute(BpmnModelConstants.CamundaAttributeExclusive)
                               .Namespace(BpmnModelConstants.CamundaNs)
                               .DefaultValue(true)
                               .Build();

            camundaCollection = typeBuilder
                                .StringAttribute(BpmnModelConstants.CamundaAttributeCollection)
                                .Namespace(BpmnModelConstants.CamundaNs)
                                .Build();

            camundaElementVariable = typeBuilder
                                     .StringAttribute(BpmnModelConstants.CamundaAttributeElementVariable)
                                     .Namespace(BpmnModelConstants.CamundaNs)
                                     .Build();

            typeBuilder.Build();
        }