private void AppendDeclaredType([NotNull] IDeclaredType declaredType, QualifierDisplays expectedQualifierDisplay, Context context) { if (declaredType.IsNullable()) { IType underlyingType = declaredType.GetNullableUnderlyingType(); if (underlyingType != null) { AppendTypeWithoutModule(underlyingType, expectedQualifierDisplay, context); AppendText("?", _highlighterIdProvider.Operator); return; } } if (declaredType is IDynamicType) { AppendText("dynamic", _highlighterIdProvider.Keyword); return; } if (context.Options.UseTypeKeywords) { string typeKeyword = CSharpTypeFactory.GetTypeKeyword(declaredType.GetClrName()); if (typeKeyword != null) { AppendText(typeKeyword, _highlighterIdProvider.Keyword); return; } } else if (declaredType.IsVoid()) { AppendText("void", _highlighterIdProvider.Keyword); return; } ITypeElement typeElement = declaredType.GetTypeElement(); if (typeElement == null || !typeElement.IsValid()) { PsiLanguageType language = CSharpLanguage.Instance ?? (PsiLanguageType)UnknownLanguage.Instance; AppendText(declaredType.GetPresentableName(language), null); } else { AppendTypeElement(typeElement, declaredType.GetSubstitution(), expectedQualifierDisplay, context); } }
// TODO: move close to the rest of errors and messages!! private static string ErrorForIncompatibleEnsuresAndReturnType(IType methodResult, IDeclaredType contractResult, ICSharpFunctionDeclaration method) { string kind = "method"; string name = method.DeclaredName; var property = method as IAccessorDeclaration; if (property != null) { kind = "property"; name = name.Replace("get_", ""); } return string.Format("Detected a call to Result with '{0}' in {1} '{2}', should be '{3}'", contractResult.GetPresentableName(CSharpLanguage.Instance), kind, name, methodResult.GetPresentableName(CSharpLanguage.Instance)); }
public void HandleRead(TypeHandlingContext context) { IDeclaredType valueType = context.Type.GetScalarType(); if (valueType == null) { throw new NotSupportedException(); } ITypeHandler valueHandler = TypeHandlers.All.SingleOrDefault(h => h.CanHandle(context.WithType(valueType))); if (valueHandler == null) { throw new NotSupportedException(); } var indexName = context.Variables.Declare(Index); var lengthName = context.Variables.Declare(Length); var exists = context.Variables.Declare(VariableKeys.NotNull); TypeHandlers.Boolean.HandleRead(new TypeHandlingContext(context) { TypeOwnerName = String.Format("var {0}", exists) }); context.Builder.AppendFormat("if({0})", exists); context.Builder.Append("{"); context.Builder.AppendFormat("var {0} = BitConverter.ToInt32(bytes, index);", lengthName); context.Builder.Append("index += sizeof(Int32);"); context.Builder.AppendFormat("{0} = new {1}[{2}];", context.TypeOwnerName, valueType.GetPresentableName(context.PresentationLanguage), lengthName); context.Builder.AppendFormat("if({0} > 0)", lengthName); context.Builder.Append("{"); context.Builder.AppendFormat("for(Int32 {0} = 0; {0} < {1}; {0}++)", indexName, lengthName); context.Builder.Append("{"); valueHandler.HandleRead(new TypeHandlingContext(context) { TypeOwnerName = String.Format("{0}[{1}]", context.TypeOwnerName, indexName), Type = valueType, TypeName = valueType.GetPresentableName(context.PresentationLanguage), TypeOwner = context.TypeOwner }); context.Builder.Append("}}}"); context.Variables.Dispose(Index); context.Variables.Dispose(Length); }
// TODO: move close to the rest of errors and messages!! private static string ErrorForIncompatibleEnsuresAndReturnType(IType methodResult, IDeclaredType contractResult, ICSharpFunctionDeclaration method) { string kind = "method"; string name = method.DeclaredName; var property = method as IAccessorDeclaration; if (property != null) { kind = "property"; name = name.Replace("get_", ""); } return(string.Format("Detected a call to Result with '{0}' in {1} '{2}', should be '{3}'", contractResult.GetPresentableName(CSharpLanguage.Instance), kind, name, methodResult.GetPresentableName(CSharpLanguage.Instance))); }
private void AppendDeclaredType([NotNull] IDeclaredType declaredType, NamespaceDisplays expectedNamespaceDisplay) { if (declaredType.IsNullable()) { IType underlyingType = declaredType.GetNullableUnderlyingType(); if (underlyingType != null) { AppendType(underlyingType, expectedNamespaceDisplay); AppendText("?", VsHighlightingAttributeIds.Operator); return; } } if (declaredType is IDynamicType) { AppendText("dynamic", VsHighlightingAttributeIds.Keyword); return; } if (_options.UseTypeKeywords) { string typeKeyword = CSharpTypeFactory.GetTypeKeyword(declaredType.GetClrName()); if (typeKeyword != null) { AppendText(typeKeyword, VsHighlightingAttributeIds.Keyword); return; } } else if (declaredType.IsVoid()) { AppendText("void", VsHighlightingAttributeIds.Keyword); return; } ITypeElement typeElement = declaredType.GetTypeElement(); if (typeElement == null || !typeElement.IsValid()) { AppendText(declaredType.GetPresentableName(UnknownLanguage.Instance), null); return; } AppendTypeElement(typeElement, declaredType.GetSubstitution(), expectedNamespaceDisplay); }
public void HandleWrite(TypeHandlingContext context) { IDeclaredType valueType = context.Type.GetScalarType(); if (valueType == null) { throw new NotSupportedException(); } ITypeHandler valueHandler = TypeHandlers.All.SingleOrDefault(h => h.CanHandle(context.WithType(valueType))); if (valueHandler == null) { throw new NotSupportedException(); } String indexName = context.Variables.Declare(Index); var exists = context.Variables.Declare(VariableKeys.NotNull); context.Builder.AppendFormat("var {0} = {1} != null;", exists, context.TypeOwnerName); TypeHandlers.Boolean.HandleWrite(new TypeHandlingContext(context) { TypeOwnerName = exists }); context.Builder.AppendFormat("if({0})", exists); context.Builder.Append("{"); TypeHandlers.Int32.HandleWrite(new TypeHandlingContext(context) { TypeName = TypeHandlers.Int32.TypeName, TypeOwnerName = String.Format("{0}.Length", context.TypeOwnerName) }); context.Builder.AppendFormat("if({0}.Length > 0)", context.TypeOwnerName); context.Builder.Append("{"); context.Builder.AppendFormat("for(Int32 {0} = 0; {0} < {1}.Length; {0}++)", indexName, context.TypeOwnerName); context.Builder.Append("{"); valueHandler.HandleWrite(new TypeHandlingContext(context) { TypeName = valueType.GetPresentableName(context.PresentationLanguage), TypeOwnerName = String.Format("{0}[{1}]", context.TypeOwnerName, indexName) }); context.Builder.Append("}}}"); context.Variables.Dispose(Index); }