Example #1
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static bool IsDeprecated(this MethodBase method)
        {
            if (method == null)
            {
                return(false);
            }

            // Keep this one line for now but should be removed once the DepreacatedAttribute is deleted
            DeprecatedAttribute attribute = method.GetCustomAttribute <DeprecatedAttribute>();

            ToBeRemovedAttribute deletedAttribute  = method.GetCustomAttribute <ToBeRemovedAttribute>();
            ReplacedAttribute    replacedAttribute = method.GetCustomAttribute <ReplacedAttribute>();

            if (attribute != null || deletedAttribute != null || replacedAttribute != null)
            {
                return(true);
            }

            if (method is ConstructorInfo)
            {
                return(method.DeclaringType.IsDeprecated());
            }

            return(false);
        }
Example #2
0
        /***************************************************/

        public static bool IsDeprecated(this Type type)
        {
            DeprecatedAttribute attribute = type.GetCustomAttribute <DeprecatedAttribute>();

            if (attribute != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static bool IsDeprecated(this MethodBase method)
        {
            DeprecatedAttribute attribute = method.GetCustomAttribute <DeprecatedAttribute>();

            if (attribute != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #4
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static bool IsDeprecated(this MethodBase method)
        {
            DeprecatedAttribute attribute = method.GetCustomAttribute <DeprecatedAttribute>();

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

            if (method is ConstructorInfo)
            {
                return(method.DeclaringType.IsDeprecated());
            }

            return(false);
        }
Example #5
0
        public FieldInfo(ref ReadOnlySpan <byte> data, CPInfo[] constants)
        {
            AccessFlags     = data.ReadTwo();
            NameIndex       = data.ReadTwo();
            DescriptorIndex = data.ReadTwo();
            AttributesCount = data.ReadTwo();
            AttributeInfo   = new AttributeInfo[AttributesCount];
            for (int i = 0; i < AttributesCount; i++)
            {
                ushort nameIndexNonSwapped = MemoryMarshal.Cast <byte, ushort>(data)[0];
                ushort nameIndex           = nameIndexNonSwapped.SwapEndian();
                string name = ((CUtf8Info)constants[nameIndex]).String;
                switch (name)
                {
                case "ConstantValue":
                    AttributeInfo[i] = new ConstantValueAttribute(ref data, constants);
                    break;

                case "Synthetic":
                    AttributeInfo[i] = new SyntheticAttribute(ref data, constants);
                    break;

                case "Signature":
                    AttributeInfo[i] = new SignatureAttribute(ref data, constants);
                    break;

                case "Deprecated":
                    AttributeInfo[i] = new DeprecatedAttribute(ref data, constants);
                    Deprecated       = true;
                    break;

                case "RuntimeVisibleAnnotations":
                    AttributeInfo[i] = new RuntimeVisibleAnnotationsAttribute(ref data, constants);
                    break;

                case "RuntimeInvisibleAnnotations":
                    throw new NotImplementedException();

                default:
                    AttributeInfo[i] = new AttributeInfo(ref data, constants);
                    break;
                }
            }
            Name       = ((CUtf8Info)constants[NameIndex]).String;
            Descriptor = ((CUtf8Info)constants[DescriptorIndex]).String;
        }
Example #6
0
        /***************************************************/

        public static bool IsDeprecated(this Type type)
        {
            // Keep this one line for now but should be removed once the DepreacatedAttribute is deleted
            DeprecatedAttribute attribute = type.GetCustomAttribute <DeprecatedAttribute>();

            ToBeRemovedAttribute deletedAttribute  = type.GetCustomAttribute <ToBeRemovedAttribute>();
            ReplacedAttribute    replacedAttribute = type.GetCustomAttribute <ReplacedAttribute>();

            if (attribute != null || deletedAttribute != null || replacedAttribute != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #7
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static bool IsDeprecated(this MethodBase method)
        {
            DeprecatedAttribute attribute = method.GetCustomAttribute <DeprecatedAttribute>();

            if (attribute != null)
            {
                try
                {
                    Version version = new Version(attribute.FromVersion);
                    return(version.CompareTo(method.DeclaringType.Assembly.GetName().Version) <= 0);
                }
                catch
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Example #8
0
        /***************************************************/

        public static bool IsDeprecated(this Type type)
        {
            DeprecatedAttribute attribute = type.GetCustomAttribute <DeprecatedAttribute>();

            if (attribute != null)
            {
                try
                {
                    Version version = new Version(attribute.FromVersion);
                    return(version.CompareTo(type.Assembly.GetName().Version) > 0);
                }
                catch
                {
                    return(true);
                }
            }
            else
            {
                return(false);
            }
        }
Example #9
0
        public MethodInfo(ref ReadOnlySpan <byte> data, ClassFile classFile)
        {
            AccessFlags = data.ReadTwo();

            NameIndex = data.ReadTwo();
            Name      = ((CUtf8Info)classFile.Constants[NameIndex]).String;

            DescriptorIndex = data.ReadTwo();
            Descriptor      = ((CUtf8Info)classFile.Constants[DescriptorIndex]).String;

            AttributesCount = data.ReadTwo();
            Attributes      = new AttributeInfo[AttributesCount];
            for (int i = 0; i < AttributesCount; i++)
            {
                ushort nameIndexNonSwapped = MemoryMarshal.Cast <byte, ushort>(data)[0];
                ushort nameIndex           = nameIndexNonSwapped.SwapEndian();
                string name = ((CUtf8Info)classFile.Constants[nameIndex]).String;
                switch (name)
                {
                case "Code":
                    CodeAttribute code = new CodeAttribute(ref data, classFile.Constants);
                    Attributes[i] = code;
                    MaxStack      = code.MaxStack;
                    MaxLocals     = code.MaxLocals;
                    CodeAttribute = code;
                    break;

                case "Exceptions":
                    ExceptionsAttribute exceptionsAttribute = new ExceptionsAttribute(ref data, classFile.Constants);
                    Attributes[i]       = exceptionsAttribute;
                    ExceptionsAttribute = exceptionsAttribute;
                    break;

                case "Deprecated":
                    Attributes[i] = new DeprecatedAttribute(ref data, classFile.Constants);
                    Deprecated    = true;
                    break;

                case "RuntimeVisibleAnnotations":
                    Attributes[i] = new RuntimeVisibleAnnotationsAttribute(ref data, classFile.Constants);
                    break;

                case "Synthetic":
                    Attributes[i] = new SyntheticAttribute(ref data, classFile.Constants);
                    break;

                case "Signature":
                    Attributes[i] = new SignatureAttribute(ref data, classFile.Constants);
                    break;

                case "RuntimeInvisibleAnnotations":
                case "RuntimeVisibleParameterAnnotations":
                case "RuntimeInvisibleParameterAnnotations":
                case "AnnotationDefault":
                    throw new NotImplementedException();

                default:
                    Attributes[i] = new AttributeInfo(ref data, classFile.Constants);
                    break;
                }
            }

            ClassFile = classFile;
        }
Example #10
0
 public string VisitAttribute(DeprecatedAttribute a)
 {
     throw new NotImplementedException();
 }
Example #11
0
        public void Deprecated_EmptyConstructor_PropertyCheck()
        {
            var attrib = new DeprecatedAttribute();

            Assert.AreEqual(null, attrib.Reason);
        }
Example #12
0
		private void AttributeSpecifier(IBlockNode scope)
		{
			DAttribute attr;
			Modifier m;

			switch (laKind) {
				case DTokens.At:
				attr = AtAttribute(scope);
				break;

				case DTokens.Pragma:
				attr=_Pragma();
				break;

				case DTokens.Deprecated:
				Step();
				var loc = t.Location;
				IExpression lc = null;
				if(laKind == OpenParenthesis)
				{
					Step();
					lc = AssignExpression(scope);
					Expect(CloseParenthesis);
				}
				attr = new DeprecatedAttribute(loc, t.EndLocation, lc);
				break;

				case DTokens.Extern:
				attr = m = new Modifier (laKind, la.Value) { Location = la.Location };
				Step ();
				if (laKind == DTokens.OpenParenthesis) {
					Step(); // Skip (

					var sb = new StringBuilder ();
					// Check if EOF and append IncompleteID
					while (!IsEOF && laKind != CloseParenthesis)
					{
						Step();
						sb.Append(t.ToString());

						if (t.Kind == Identifier && laKind == Identifier)
							sb.Append(' ');
					}
					if (IsEOF)
						m.LiteralContent = DTokens.IncompleteId;
					else
						m.LiteralContent = sb.ToString();

					Expect (CloseParenthesis);
				}

				m.EndLocation = t.EndLocation;
				break;

				case DTokens.Align:
				attr = m = new Modifier (laKind, la.Value) { Location = la.Location };
				Step ();
				if (laKind == DTokens.OpenParenthesis) {
					Step();
					if (Expect(Literal))
						m.LiteralContent = new IdentifierExpression(t.LiteralValue, t.LiteralFormat);

					if (!Expect(CloseParenthesis))
						return;
				}

				m.EndLocation = t.EndLocation;
				break;

				case DTokens.Package:
				attr = m = new Modifier (laKind, la.Value) { Location = la.Location };
				Step ();

				if (laKind == OpenParenthesis) {
					// This isn't documented anywhere. http://dlang.org/attribute.html#ProtectionAttribute
					//TODO: Semantically handle this.
					Step ();
					m.LiteralContent = IdentifierList (scope); // Reassigns a symbol's package/'namespace' or so

					Expect (DTokens.CloseParenthesis);
				}

				m.EndLocation = t.EndLocation;
				break;

				default:
				attr = m = new Modifier (laKind, la.Value) { Location = la.Location };
				Step ();
				m.EndLocation = t.EndLocation;
				break;
			}

			//TODO: What about these semicolons after e.g. a pragma? Enlist these attributes anyway in the meta decl list?
			if (laKind != Semicolon)
			{
				if (scope is DBlockNode)
					AttributeSpecifier(scope as DBlockNode, attr);
				else
					PushAttribute(attr, false);
			}
		}
Example #13
0
        static Dictionary <TypeId, EnumType> CreateEnumsDict(Assembly assembly)
        {
            var allTypeIds = typeof(TypeIds).GetFields().Select(a => (TypeId)a.GetValue(null) !).ToHashSet();
            var enums      = new Dictionary <TypeId, EnumType>();

            foreach (var type in assembly.GetTypes())
            {
                var ca = type.GetCustomAttribute <EnumAttribute>(false);
                if (ca is null)
                {
                    continue;
                }
                if (!allTypeIds.Contains(ca.TypeId))
                {
                    throw new InvalidOperationException();
                }
                allTypeIds.Remove(ca.TypeId);
                var flags = EnumTypeFlags.None;
                if (ca.Public)
                {
                    flags |= EnumTypeFlags.Public;
                }
                if (ca.NoInitialize)
                {
                    flags |= EnumTypeFlags.NoInitialize;
                }
                if (ca.Flags)
                {
                    flags |= EnumTypeFlags.Flags;
                }
                var values   = type.GetFields().Where(a => a.IsLiteral).Select(a => new EnumValue(GetValue(a.GetValue(null)), a.Name, CommentAttribute.GetDocumentation(a), DeprecatedAttribute.GetDeprecatedInfo(a))).ToArray();
                var enumType = new EnumType(ca.Name, ca.TypeId, ca.Documentation, values, flags);
                enums.Add(ca.TypeId, enumType);
            }
            return(enums);
        }
 public ulong VisitAttribute(DeprecatedAttribute a)
 {
     return(1000159);
 }
Example #15
0
 public AbstractType VisitAttribute(DeprecatedAttribute a)
 {
     throw new NotImplementedException();
 }
Example #16
0
        private void AttributeSpecifier(IBlockNode scope)
        {
            DAttribute attr;
            if(laKind == At)
                attr = AtAttribute(scope);
            else if (laKind == Pragma)
                 attr=_Pragma();
            else if(laKind == Deprecated)
            {
                Step();
                var loc = t.Location;
                IExpression lc = null;
                if(laKind == OpenParenthesis)
                {
                    Step();
                    lc = AssignExpression(scope);
                    Expect(CloseParenthesis);
                }
                attr = new DeprecatedAttribute(loc, t.EndLocation, lc);
            }
            else
            {
                var m = new Modifier(laKind, la.Value) { Location = la.Location };
                attr = m;
                if (laKind == Extern && Lexer.CurrentPeekToken.Kind == OpenParenthesis)
                {
                    Step(); // Skip extern
                    Step(); // Skip (

                    var sb = new StringBuilder ();
                    // Check if EOF and append IncompleteID
                    while (!IsEOF && laKind != CloseParenthesis)
                    {
                        Step();
                        sb.Append(t.ToString());

                        if (t.Kind == Identifier && laKind == Identifier)
                            sb.Append(' ');
                    }
                    if (IsEOF)
                        m.LiteralContent = DTokens.IncompleteId;
                    else
                        m.LiteralContent = sb.ToString();

                    Expect (CloseParenthesis);
                }
                else if (laKind == Align && Lexer.CurrentPeekToken.Kind == OpenParenthesis)
                {
                    Step();
                    Step();
                    if (Expect(Literal))
                        m.LiteralContent = new IdentifierExpression(t.LiteralValue, t.LiteralFormat);

                    if (!Expect(CloseParenthesis))
                        return;
                }
                else
                    Step();

                m.EndLocation = t.EndLocation;
            }

            //TODO: What about these semicolons after e.g. a pragma? Enlist these attributes anyway in the meta decl list?
            if (laKind != Semicolon)
                AttributeTrail (scope as DBlockNode, attr);
        }
Example #17
0
        public void Deprecated_WithReason_PropertyCheck()
        {
            var attrib = new DeprecatedAttribute("Because");

            Assert.AreEqual("Because", attrib.Reason);
        }
Example #18
0
        /// <summary>
        /// Read a list of attributes
        /// </summary>
        private void ReadAttributes(ConstantPool cp, IModifiableAttributeProvider provider)
        {
            var count = stream.ReadU2();

            for (var i = 0; i < count; i++)
            {
                var nameIndex = stream.ReadU2();
                var name      = cp.GetEntry <ConstantPoolUtf8>(nameIndex).Value;
                var length    = stream.ReadU4();

                Attribute attr;
                int       tmp;
                switch (name)
                {
                case CodeAttribute.AttributeName:
                    attr = ReadCodeAttribute((MethodDefinition)provider, cp);
                    break;

                case ConstantValueAttribute.AttributeName:
                    tmp  = stream.ReadU2();
                    attr = new ConstantValueAttribute(((IConstantPoolValue)cp[tmp]).Value);
                    break;

                case ExceptionsAttribute.AttributeName:
                    attr = ReadExceptionsAttribute(cp);
                    break;

                case InnerClassesAttribute.AttributeName:
                    attr = ReadInnerClassesAttribute(cp);
                    break;

                case SyntheticAttribute.AttributeName:
                    attr = new SyntheticAttribute();
                    break;

                case SourceFileAttribute.AttributeName:
                    tmp  = stream.ReadU2();
                    attr = new SourceFileAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value);
                    break;

                case LineNumberTableAttribute.AttributeName:
                    attr = ReadLineNumberTableAttribute();
                    break;

                case LocalVariableTableAttribute.AttributeName:
                    attr = ReadLocalVariableTableAttribute(cp);
                    break;

                case DeprecatedAttribute.AttributeName:
                    attr = new DeprecatedAttribute();
                    break;

                case OverrideAttribute.AttributeName:
                    attr = new OverrideAttribute();
                    break;

                case SignatureAttribute.AttributeName:
                    tmp  = stream.ReadU2();
                    attr = new SignatureAttribute(cp.GetEntry <ConstantPoolUtf8>(tmp).Value);
                    break;

                case RuntimeVisibleAnnotationsAttribute.AttributeName:
                    attr = new RuntimeVisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp));
                    break;

                case RuntimeInvisibleAnnotationsAttribute.AttributeName:
                    attr = new RuntimeInvisibleAnnotationsAttribute(ReadAnnotationsAttribute(cp));
                    break;

                case RuntimeVisibleParameterAnnotationsAttribute.AttributeName:
                    attr = new RuntimeVisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp));
                    break;

                case RuntimeInvisibleParameterAnnotationsAttribute.AttributeName:
                    attr = new RuntimeInvisibleParameterAnnotationsAttribute(ReadAnnotationsAttribute(cp));
                    break;

                case AnnotationDefaultAttribute.AttributeName:
                    attr = new AnnotationDefaultAttribute(ReadElementValue(cp));
                    break;

                default:
                    stream.Skip(length);
                    attr = new UnknownAttribute(name);
                    break;
                }
                provider.Add(attr);
            }
            provider.AttributesLoaded();
        }
Example #19
0
        public void Deprecated_WithReason_IsTrimmed()
        {
            var attrib = new DeprecatedAttribute("   Because  ");

            Assert.AreEqual("Because", attrib.Reason);
        }
		public virtual void VisitAttribute(DeprecatedAttribute a)
		{
			
		}
Example #21
0
 public CompletionItemKind VisitAttribute(DeprecatedAttribute a)
 {
     throw new NotImplementedException();
 }