public FakeOptionType EatOption(ISnapshot snapshot, IReferenceExpression referenceExpression) { if (referenceExpression.QualifierExpression == null) { throw new MoqStubWrongSyntaxException("Moq-stub property-option has not parent reference", this, referenceExpression); } if (referenceExpression.QualifierExpression is IInvocationExpression) { return EatOption(snapshot, referenceExpression.QualifierExpression as IInvocationExpression); } if (referenceExpression.QualifierExpression is IReferenceExpression) { var declaredElement = _eatExpressionHelper.GetReferenceElement(referenceExpression.QualifierExpression as IReferenceExpression); if (declaredElement is ILambdaParameterDeclaration) { return FakeOptionType.Property; } return EatOption(snapshot, referenceExpression.QualifierExpression as IReferenceExpression); } throw new MoqStubOptionTargetWrongTypeException(this, referenceExpression.QualifierExpression); }
private static void CheckReferenceExpression([NotNull] IReferenceExpression referenceExpression, [NotNull] IHighlightingConsumer consumer) { var declaredElement = referenceExpression.Reference.Resolve().DeclaredElement; var property = declaredElement as IProperty; var getter = property?.Getter; if (getter != null && getter.IsIterator) { var languageService = referenceExpression.Language.LanguageServiceNotNull(); var accessType = languageService.GetReferenceAccessType(referenceExpression.Reference); if (accessType == ReferenceAccessType.READ) { consumer.AddHighlighting( new ObjectAllocationHighlighting(referenceExpression, "iterator property access"), referenceExpression.NameIdentifier.GetDocumentRange()); } } if (declaredElement is IMethod) { // todo: check inside delegate invocation var declaredType = referenceExpression.GetImplicitlyConvertedTo() as IDeclaredType; if (declaredType?.GetTypeElement() is IDelegate) { consumer.AddHighlighting( new DelegateAllocationHighlighting(referenceExpression, "from method group"), referenceExpression.NameIdentifier.GetDocumentRange()); } } }
private static void ApplyRenameHotspots( [NotNull] LiveTemplatesManager liveTemplatesManager, [NotNull] ITextControl textControl, [NotNull] IForeachStatement statement, [NotNull] IList <string> namesCollection, [CanBeNull] IReferenceExpression extraReference = null) { var variableDeclaration = statement.IteratorDeclaration; var endSelectionRange = new TextRange(textControl.Caret.Offset()); var suggestTypeName = new MacroCallExpressionNew(new SuggestVariableTypeMacroDef()); var typeNameInfo = new HotspotInfo( new TemplateField("type", suggestTypeName, 0), variableDeclaration.VarKeyword.GetDocumentRange()); var nameRanges = new LocalList <DocumentRange>(); nameRanges.Add(variableDeclaration.NameIdentifier.GetDocumentRange()); if (extraReference != null) { var documentRange = extraReference.GetDocumentRange(); nameRanges.Add(documentRange); endSelectionRange = new TextRange(documentRange.TextRange.EndOffset); } var variableNameInfo = new HotspotInfo( new TemplateField("name", new NameSuggestionsExpression(namesCollection), 0), nameRanges.ToArray()); var session = liveTemplatesManager.CreateHotspotSessionAtopExistingText( statement.GetSolution(), endSelectionRange, textControl, LiveTemplatesManager.EscapeAction.LeaveTextAndCaret, typeNameInfo, variableNameInfo); session.Execute(); }
private static void AddHighlighting(IReferenceExpression reference, IHighlightingConsumer consumer, int threshold, int currentValue) { var nameIdentifier = reference.NameIdentifier; var documentRange = nameIdentifier.GetDocumentRange(); var highlighting = new MaximumChainedReferencesHighlighting(documentRange, threshold, currentValue); consumer.AddHighlighting(highlighting); }
public void AddProperty(IReferenceExpression referenceExpression) { if (!myPropertiesMap.ContainsKey(referenceExpression)) { myPropertiesMap[referenceExpression] = new List <IReferenceExpression>(); } myPropertiesMap[referenceExpression].Add(referenceExpression); }
public CompoundAssignmentExpression(IReferenceExpression target, IExpression value, BinaryOperationKind binaryKind, IMethodSymbol operatorMethod, SyntaxNode syntax) { this.Target = target; this.Value = value; this.BinaryKind = binaryKind; this.Operator = operatorMethod; this.Syntax = syntax; }
private static void AddHighlighting(IReferenceExpression reference, IHighlightingConsumer consumer) { var nameIdentifier = reference.NameIdentifier; var documentRange = nameIdentifier.GetDocumentRange(); var highlighting = new MaximumChainedReferencesHighlighting(Warnings.ChainedReferences, documentRange); consumer.AddHighlighting(highlighting); }
/// <summary> /// Swap base to this unless local implementation. /// </summary> /// <param name="invocationExpression"> /// The invocation expression. /// </param> public static void SwapBaseToThisUnlessLocalImplementation(IInvocationExpression invocationExpression) { bool isOverride = false; bool isNew = false; IPrimaryExpression invokedExpression = invocationExpression.InvokedExpression; if (invokedExpression != null) { IReferenceExpression referenceExpressionNode = invokedExpression as IReferenceExpression; if (referenceExpressionNode != null) { IReferenceExpression referenceExpression = invokedExpression as IReferenceExpression; if (referenceExpression != null) { ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression is IBaseExpression) { string methodName = referenceExpressionNode.NameIdentifier.Name; ICSharpTypeDeclaration typeDeclaration = invocationExpression.GetContainingNode <ICSharpTypeDeclaration>(true); if (typeDeclaration != null) { foreach (ICSharpTypeMemberDeclaration memberDeclaration in typeDeclaration.MemberDeclarations) { if (memberDeclaration.DeclaredName == methodName) { IMethodDeclaration methodDeclaration = memberDeclaration as IMethodDeclaration; if (methodDeclaration != null) { isOverride = methodDeclaration.IsOverride; isNew = methodDeclaration.IsNew(); break; } } } if (isOverride || isNew) { return; } using (WriteLockCookie.Create(true)) { // swap the base to this ICSharpExpression expression = CSharpElementFactory.GetInstance(invocationExpression.GetPsiModule()).CreateExpression("this"); referenceExpression.SetQualifierExpression(expression); } } } } } } }
private static bool AddEnumerationMembers([NotNull] CSharpCodeCompletionContext context, [NotNull] GroupedItemsCollector collector, [NotNull] IDeclaredType qualifierType, [NotNull] IReferenceExpression referenceExpression) { var enumerationType = (IEnum)qualifierType.GetTypeElement().NotNull(); var substitution = qualifierType.GetSubstitution(); var memberValues = new List <Pair <IField, string> >(); var isFlagsEnum = enumerationType.HasAttributeInstance(FlagsAttributeClrName, false); if (!isFlagsEnum) { foreach (var member in enumerationType.EnumMembers) { var formattable = member.ConstantValue.Value as IFormattable; var memberValue = (formattable != null) ? formattable.ToString("D", CultureInfo.InvariantCulture) : string.Empty; memberValues.Add(Pair.Of(member, memberValue)); } } else { foreach (var member in enumerationType.EnumMembers) { var convertible = member.ConstantValue.Value as IConvertible; var memberValue = (convertible != null) ? GetBinaryRepresentation(convertible) : string.Empty; memberValues.Add(Pair.Of(member, memberValue)); } } if (memberValues.Count == 0) { return(false); } // create pointer to . in reference expression var maxLength = memberValues.Max(x => x.Second.Length); var reparsedDotRange = referenceExpression.Delimiter.GetTreeTextRange(); var originalDotRange = context.UnterminatedContext.ToOriginalTreeRange(reparsedDotRange); var file = context.BasicContext.File; var dotMarker = file.GetDocumentRange(originalDotRange).CreateRangeMarker(); foreach (var member in memberValues) { var normalizedValue = member.Second.PadLeft(maxLength, '0'); var value = isFlagsEnum ? normalizedValue : member.Second; var instance = new DeclaredElementInstance <IField>(member.First, substitution); var textLookupItem = new EnumMemberLookupItem(dotMarker, instance, normalizedValue, value, isFlagsEnum); collector.AddSomewhere(textLookupItem); } return(true); }
public VariableInfo(IReferenceExpression reference) { Node = reference; IsWriteUsage = reference.Parent is IPrefixExpression || reference.Parent is IPostfixExpression || IsAssignment(reference); FunctionLike = reference.GetContainingNode<IJsFunctionLike>(); DeclaredElement = reference.Reference.Resolve().DeclaredElement; }
public VariableInfo(IReferenceExpression reference) { Node = reference; IsWriteUsage = reference.Parent is IPrefixExpression || reference.Parent is IPostfixExpression || IsAssignment(reference); FunctionLike = reference.GetContainingNode <IJsFunctionLike>(); DeclaredElement = reference.Reference.Resolve().DeclaredElement; }
public CachePropertyValueQuickFix(InefficientPropertyAccessWarning warning) { myReferences = warning.References; myHighlightedReference = warning.HighlightedReference; myInlineCache = warning.InlineCacheValue; myInlineRestore = warning.InlineRestoreValue; myCacheAnchor = warning.CacheAnchor; myRestoreAnchor = warning.RestoreAnchor; }
public void ReplaceResultToAsync(IReferenceExpression referenceExpression) { var replaceBy = referenceExpression.QualifierExpression; if (replaceBy != null) { ReplaceToAwait(referenceExpression, replaceBy); } }
private static void CheckStructMethodConversionToDelegateInstance( [NotNull] IReferenceExpression referenceExpression, [NotNull] IHighlightingConsumer consumer) { var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression); if (invocationExpression != null) { return; // also filters out 'nameof(o.M)' } var(declaredElement, _, resolveErrorType) = referenceExpression.Reference.Resolve(); if (!resolveErrorType.IsAcceptable) { return; } var method = declaredElement as IMethod; if (method == null || method.IsStatic) { return; } var qualifierType = TryGetQualifierExpressionType(referenceExpression); if (qualifierType == null) { return; } var targetType = referenceExpression.GetImplicitlyConvertedTo(); if (!targetType.IsDelegateType()) { return; } var qualifierTypeKind = IsQualifierOfValueType(qualifierType, includeStructTypeParameters: true); if (qualifierTypeKind == Classification.Not) { return; } var description = BakeDescriptionWithTypes( "conversion of value type '{0}' instance method to '{1}' delegate type", qualifierType, targetType); if (qualifierTypeKind == Classification.Definitely) { consumer.AddHighlighting( new BoxingAllocationHighlighting(referenceExpression.NameIdentifier, description)); } else { consumer.AddHighlighting( new PossibleBoxingAllocationHighlighting(referenceExpression.NameIdentifier, description)); } }
public ContractResultPredicateArgument(IDeclaredType resultTypeName, IReferenceExpression contractResultReference) { Contract.Requires(resultTypeName != null); Contract.Requires(contractResultReference != null); _resultTypeName = resultTypeName; _contractResultReference = contractResultReference; }
/// <summary> /// Swap to built in type alias. /// </summary> /// <param name="node"> /// The node to process. /// </param> public static void SwapToBuiltInTypeAlias(ITreeNode node) { for (ITreeNode currentNode = node; currentNode != null; currentNode = currentNode.NextSibling) { ITypeArgumentList typeArgumentListNode = currentNode as ITypeArgumentList; if (typeArgumentListNode != null) { SwapGenericDeclarationToBuiltInType(typeArgumentListNode); } else { IMethodDeclaration methodDeclarationNode = currentNode as IMethodDeclaration; if (methodDeclarationNode != null) { SwapReturnTypeToBuiltInType(methodDeclarationNode); } else { IVariableDeclaration variableDeclaration = currentNode as IVariableDeclaration; if (variableDeclaration != null) { SwapVariableDeclarationToBuiltInType(variableDeclaration); } else { IObjectCreationExpression creationExpressionNode = currentNode as IObjectCreationExpression; if (creationExpressionNode != null) { //// No need to call this now and its messing up nested {} //// SwapObjectCreationToBuiltInType(creationExpressionNode); } else { IArrayCreationExpression arrayCreationNode = currentNode as IArrayCreationExpression; if (arrayCreationNode != null) { SwapArrayCreationToBuiltInType(arrayCreationNode); } else { IReferenceExpression referenceExpressionNode = currentNode as IReferenceExpression; if (referenceExpressionNode != null) { SwapReferenceExpressionToBuiltInType(referenceExpressionNode); } } } } } } if (currentNode != null && currentNode.FirstChild != null) { SwapToBuiltInTypeAlias(currentNode.FirstChild); } } }
private bool IsUsageSetTransformParent([NotNull] IReferenceExpression referenceExpression, out bool stayInWorldCoords, [CanBeNull] out ICSharpExpression expression) { stayInWorldCoords = true; expression = null; var declaredElement = referenceExpression.Reference.Resolve().DeclaredElement as IClrDeclaredElement; if (declaredElement == null) { return(false); } if (declaredElement is IProperty property) { expression = AssignmentExpressionNavigator.GetByDest(referenceExpression)?.Source; if (!property.ShortName.Equals("parent")) { return(false); } } if (declaredElement is IMethod setParentMethod) { if (!setParentMethod.ShortName.Equals("SetParent")) { return(false); } var invocation = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression); if (invocation == null) { return(false); } expression = invocation.Arguments[0].Value; if (setParentMethod.Parameters.Count == 2) { var argument = invocation.Arguments[1].Value; if (argument?.ConstantValue.Value is bool constantValue) { stayInWorldCoords = constantValue; } else { return(false); } } } var containingType = declaredElement.GetContainingType(); if (containingType != null && containingType.GetClrName().Equals(KnownTypes.Transform)) { return(true); } return(false); }
public override IAssignableReference VisitReferenceExpression(IReferenceExpression reference, IList <IStatement> body) { if (reference.QualifierExpression == null) { return(FindLocalVariable(reference)); } return(FindFieldReference(reference)); }
private static IType TryGetQualifierExpressionType([NotNull] IReferenceExpression referenceExpression) { var qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression.IsThisOrBaseOrNull()) { var typeDeclaration = referenceExpression.GetContainingTypeDeclaration(); if (typeDeclaration is IStructDeclaration { DeclaredElement : { } structTypeElement })
private static int GetExistingArgumentsCount([NotNull] IReferenceExpression referenceExpression) { var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression); if (invocationExpression == null) { return(0); // todo: -1 to indicate there is no invocation after? } return(invocationExpression.Arguments.Count); }
private bool InSameBlock(IReferenceExpression fullReferenceExpression, ITreeNode storage) { var firstStatement = fullReferenceExpression.GetContainingStatement(); var secondStatement = storage.GetContainingNode <IStatement>(); if (firstStatement == null || secondStatement == null) { return(false); } return(firstStatement.Parent == secondStatement.Parent); }
private static bool IsReferenceToArgument(IReferenceExpression referenceExpression, IDeclaredElement toFind) { if (referenceExpression == null) { return(false); } var resolveResultWithInfo = referenceExpression.Reference.GetResolveResult(); var declaredElement = resolveResultWithInfo.DeclaredElement; return(declaredElement != null && declaredElement.ShortName == toFind.ShortName); }
public ReferenceArgument(IReferenceExpression referenceExpression) { Contract.Requires(referenceExpression != null); Contract.Requires(referenceExpression.NameIdentifier != null); _referenceExpression = referenceExpression; _argumentName = referenceExpression.NameIdentifier.Name; var qualifierReference = referenceExpression.QualifierExpression as IReferenceExpression; _baseArgumentName = (qualifierReference ?? referenceExpression).NameIdentifier.Name; }
private static IColorReference ReferenceFromInvocation(IReferenceExpression qualifier, IReferenceExpression methodReferenceExpression) { var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(methodReferenceExpression); if (invocationExpression == null || invocationExpression.Arguments.IsEmpty) { return(null); } var methodReference = methodReferenceExpression.Reference; var name = methodReference.GetName(); if (!string.Equals(name, "HSVToRGB", StringComparison.Ordinal)) { return(null); } var arguments = invocationExpression.Arguments; if (arguments.Count < 3 || arguments.Count > 4) { return(null); } var color = GetColorFromHSV(arguments); if (color == null) { return(null); } var qualifierType = qualifier.Reference.Resolve().DeclaredElement as ITypeElement; if (qualifierType == null) { return(null); } var unityColorTypes = UnityColorTypes.GetInstance(qualifierType.Module); if (!unityColorTypes.IsUnityColorTypeSupportingHSV(qualifierType)) { return(null); } var colorElement = new ColorElement(color.Value); var argumentList = invocationExpression.ArgumentList; return(new UnityColorReference(colorElement, invocationExpression, argumentList, argumentList.GetDocumentRange())); }
public override MethodInvocation ProcessUsage(IReference reference) { var referenceExpression = reference.GetTreeNode() as IReferenceExpression; if (referenceExpression == null) { Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage")); return(null); } bool isExtensionMethod = referenceExpression.IsExtensionMethod(); IInvocationExpression invocation = InvocationExpressionNavigator.GetByInvokedExpression(referenceExpression); if (invocation == null) { Driver.AddConflict(ReferenceConflict.CreateError(reference, "{0} can not be updated correctly.", "Usage")); return(null); } ITreeNode element = GetArgument(invocation, isExtensionMethod); var argument = element as ICSharpArgument; IType type = argument != null?GetTypeOfValue(argument.Value) : GetTypeOfValue(element); if (type == null || !type.CanUseExplicitly(invocation)) { Driver.AddConflict(ReferenceConflict.CreateError( reference, "Argument of {0} is not valid 'typeof' expression.", "usage")); return(null); } // we can rely on resolve result since method declaration is not yet changed. ResolveResultWithInfo resolveResult = reference.Resolve(); ISubstitution substitution = resolveResult.Result.Substitution; var method = resolveResult.DeclaredElement as IMethod; if (method == null) { return(null); } if (argument != null) { invocation.RemoveArgument(argument); return(new MethodInvocation(reference, type, method, substitution)); } CSharpElementFactory factory = CSharpElementFactory.GetInstance(invocation.GetPsiModule()); IReferenceExpression newInvokedExpression = invocation.InvokedExpression.ReplaceBy(factory.CreateReferenceExpression("$0", Executer.Method)); return(new MethodInvocation(newInvokedExpression.Reference, type, method, substitution)); }
private static UnityComponentRelatedReferenceExpressionFinder GetFinder(IReferenceExpression referenceExpression) { // Register here custom finders for unity components. var declaredElement = (referenceExpression.Reference.Resolve().DeclaredElement as IClrDeclaredElement).NotNull("declaredElement != null"); var containingType = declaredElement.GetContainingType().NotNull("declaredElement.GetContainingType() != null"); if (containingType.GetClrName().Equals(KnownTypes.Transform)) { return(new TransformRelatedReferenceFinder(referenceExpression)); } return(new UnityComponentRelatedReferenceExpressionFinder(referenceExpression)); }
private static string GetReferencePath(IReferenceExpression referenceExpression) { var typeMember = referenceExpression.Reference.Resolve().DeclaredElement as ITypeMember; var containingType = typeMember?.GetContainingType(); if (containingType == null) { return(null); } return($"{containingType.GetClrName()}.{typeMember.ShortName}"); }
private static IAssignableReference FindLocalVariable(IReferenceExpression reference) { var declaredElement = Resolve(reference.Reference); if (declaredElement != null) { return(new VariableReference { Identifier = declaredElement.ShortName }); } return(new VariableReference()); }
public UnityComponentRelatedReferenceExpressionFinder([NotNull] IReferenceExpression referenceExpression, bool ignoreNotComponentInvocations = false) { ReferenceExpression = referenceExpression; myIgnoreNotComponentInvocations = ignoreNotComponentInvocations; DeclaredElement = ReferenceExpression.Reference.Resolve().DeclaredElement as IClrDeclaredElement; Assertion.Assert(DeclaredElement != null, "DeclaredElement != null"); ContainingType = DeclaredElement.GetContainingType(); Assertion.Assert(ContainingType != null, "ContainingType != null"); ComponentReferenceExpression = referenceExpression.QualifierExpression as IReferenceExpression; }
internal IntentionalBlockingAttemptWarning( [NotNull] string message, [NotNull] ICSharpExpression expression, [NotNull] ICSharpExpression valueTaskExpression, [NotNull] IReferenceExpression getAwaiterReferenceExpression, [NotNull] IReferenceExpression getResultReferenceExpression) : base(message) { this.getAwaiterReferenceExpression = getAwaiterReferenceExpression; this.getResultReferenceExpression = getResultReferenceExpression; ValueTaskExpression = valueTaskExpression; Expression = expression; }
private static bool IsInvokedOverContantValue([NotNull] IReferenceExpression reference) { var resolveResult = reference.Reference.Resolve(); var field = resolveResult.DeclaredElement as IField; if (field == null) { return(false); } return(field.IsConstant || field.IsEnumMember); }
// This will be called multiple times in the case of chained method calls. public override void VisitInvocationExpression(IInvocationExpression invocationExpressionParam) { // TODO: Loop through here somehow and work up through the string calls like ToLower().ToUpper() et et. //do // { IReferenceExpression expression = invocationExpressionParam.InvokedExpression as IReferenceExpression; if (expression == null) { return; } // As I understand it this takes the abstract syntax element that is e.ToString() and resolves it such that // we know it's the System.Enum.ToString() method call. IResolveResult resolveResult = expression.Reference.Resolve(); IDeclaredElement e = resolveResult.DeclaredElement; if (e == null) { return; } ITypeElement containingType = e.GetContainingType(); // work up through the string calls //invocationExpressionParam = invocationExpressionParam.InvocationExpressionReference as IInvocationExpression; //var allowed = new[] { "ToUpper", "ToLower", "ToString" }; //if (!new List<string>(allowed).Contains(e.ShortName)) // return; // } //while (containingType != null && containingType.CLRName == "System.String"); if (containingType == null) { return; } if (containingType.CLRName == "System.Enum" && e.ShortName == "ToString") { Found = true; // Save the enum declaration so we can implement the fix. this.FoundEnumReference = invocationExpressionParam.Reference; this.EnumReferenceName = expression.QualifierExpression.GetText(); IExpressionType qe = expression.QualifierExpression.GetExpressionType(); this.EnumDeclaredName = ((IDeclaredType)qe).GetPresentableName(PsiLanguageType.GetByProjectFile(invocationExpressionParam.GetProjectFile())); } }
public override bool IsAvailable(IUserDataHolder cache) { var reference = _provider.GetSelectedElement<IReferenceExpression>(true, true); if (reference != null && reference.IsValid()) { var qualifier = reference.Qualifier; var nameIdentifier = reference.NameIdentifier; if (qualifier != null && nameIdentifier != null) { _referenceExpression = reference; _replacement = string.Format("{0}['{1}']", qualifier.GetText(), nameIdentifier.GetText()); return true; } } return false; }
/// <summary>Reads the specified reference expression. </summary> /// <param name="analyzeUnit">The analyze unit. </param> /// <param name="exceptionsOrigin">The exceptions origin. </param> /// <param name="referenceExpression">The reference expression.</param> /// <returns>The list of thrown exceptions. </returns> public static IEnumerable<ThrownExceptionModel> Read(IAnalyzeUnit analyzeUnit, IExceptionsOriginModel exceptionsOrigin, IReferenceExpression referenceExpression) { var result = new List<ThrownExceptionModel>(); var resolveResult = referenceExpression.Parent is IElementAccessExpression ? ((IElementAccessExpression)referenceExpression.Parent).Reference.Resolve() : referenceExpression.Reference.Resolve(); var declaredElement = resolveResult.DeclaredElement; if (declaredElement == null) return result; var declarations = declaredElement.GetDeclarations(); if (declarations.Count == 0) return Read(analyzeUnit, exceptionsOrigin, declaredElement); foreach (var declaration in declarations) { #if R8 var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwnerNode; if (docCommentBlockOwnerNode == null) return result; var docCommentBlockNode = docCommentBlockOwnerNode.GetDocCommentBlockNode(); if (docCommentBlockNode == null) return result; #endif #if R9 || R10 var docCommentBlockOwnerNode = declaration as IDocCommentBlockOwner; if (docCommentBlockOwnerNode == null) return result; var docCommentBlockNode = docCommentBlockOwnerNode.DocCommentBlock; if (docCommentBlockNode == null) return result; #endif var docCommentBlockModel = new DocCommentBlockModel(null, docCommentBlockNode); foreach (var comment in docCommentBlockModel.DocumentedExceptions) { result.Add(new ThrownExceptionModel(analyzeUnit, exceptionsOrigin, comment.ExceptionType, comment.ExceptionDescription, false, comment.Accessor)); } } return result; }
public Assignment(IReferenceExpression target, IExpression value, SyntaxNode syntax) { _assignment = new AssignmentExpression(target, value, syntax); this.Syntax = syntax; }
public AssignmentExpression(IReferenceExpression target, IExpression value, SyntaxNode syntax) { this.Value = value; this.Target = target; this.Syntax = syntax; }
/// <summary> /// Generates CIL for an assignment expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> private void GenerateAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target) { // Load the value to assign. var rhs = this.GetOperand(1); rhs.GenerateCode(generator, optimizationInfo); // Support the inferred function displayName property. if (rhs is FunctionExpression) ((FunctionExpression)rhs).GenerateDisplayName(generator, optimizationInfo, target.ToString(), false); // Duplicate the value so it remains on the stack afterwards. //if (optimizationInfo.SuppressReturnValue == false) generator.Duplicate(); // Store the value. target.GenerateSet(generator, optimizationInfo, rhs.ResultType, optimizationInfo.StrictMode); }
/// <summary> /// Swap reference expression to built in type. /// </summary> /// <param name="referenceExpression"> /// The reference expression. /// </param> private static void SwapReferenceExpressionToBuiltInType(IReferenceExpression referenceExpression) { IPsiModule project = referenceExpression.GetPsiModule(); ICSharpExpression qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression != null) { using (WriteLockCookie.Create(true)) { foreach (string[] builtInType in BuiltInTypes) { string text = qualifierExpression.GetText(); if (text == builtInType[0] || text == builtInType[1]) { ICSharpExpression expression = CSharpElementFactory.GetInstance(project).CreateExpression(builtInType[2], new object[0]); referenceExpression.SetQualifierExpression(expression); break; } } } } }
private static IColorReference ReferenceFromProperty(IReferenceExpression qualifier, IReferenceExpression colorQualifiedMemberExpression) { var name = colorQualifiedMemberExpression.Reference.GetName(); var color = UnityNamedColors.Get(name); if (color == null) return null; var qualifierType = qualifier.Reference.Resolve().DeclaredElement as ITypeElement; if (qualifierType == null) return null; var unityColorTypes = UnityColorTypes.GetInstance(qualifierType.Module); if (!unityColorTypes.IsUnityColorTypeSupportingProperties(qualifierType)) return null; var property = colorQualifiedMemberExpression.Reference.Resolve().DeclaredElement as IProperty; if (property == null) return null; var colorElement = new ColorElement(color.Value, name); return new UnityColorReference(colorElement, colorQualifiedMemberExpression, colorQualifiedMemberExpression, colorQualifiedMemberExpression.NameIdentifier.GetDocumentRange()); }
/// <summary> /// Generates CIL for an increment or decrement expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> /// <param name="postfix"> <c>true</c> if this is the postfix version of the operator; /// <c>false</c> otherwise. </param> /// <param name="increment"> <c>true</c> if this is the increment operator; <c>false</c> if /// this is the decrement operator. </param> private void GenerateIncrementOrDecrement(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target, bool postfix, bool increment) { // Note: increment and decrement can produce a number that is out of range if the // target is of type Int32. The only time this should happen is for a loop variable // where the range has been carefully checked to make sure an out of range condition // cannot happen. // Evaluate the left hand side only once. target.GenerateReference(generator, optimizationInfo); target.DuplicateReference(generator, optimizationInfo); // For the GenerateSet, later on. // Get the target value. target.GenerateGet(generator, optimizationInfo, true); // Convert it to a number. if (target.Type != PrimitiveType.Int32) EmitConversion.ToNumber(generator, target.Type); // If this is PostIncrement or PostDecrement, store the value so it can be returned later. var result = generator.CreateTemporaryVariable(target.Type == PrimitiveType.Int32 ? PrimitiveType.Int32 : PrimitiveType.Number); if (postfix == true) { generator.Duplicate(); generator.StoreVariable(result); } // Load the increment constant. if (target.Type == PrimitiveType.Int32) generator.LoadInt32(1); else generator.LoadDouble(1.0); // Add or subtract the constant to the target value. if (increment == true) generator.Add(); else generator.Subtract(); // If this is PreIncrement or PreDecrement, store the value so it can be returned later. if (postfix == false) { generator.Duplicate(); generator.StoreVariable(result); } // Store the value. target.GenerateSet(generator, optimizationInfo, target.Type == PrimitiveType.Int32 ? PrimitiveType.Int32 : PrimitiveType.Number, optimizationInfo.StrictMode); // Restore the expression result. generator.LoadVariable(result); generator.ReleaseTemporaryVariable(result); }
/// <summary> /// Generates CIL for a compound assignment expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> private void GenerateCompoundAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target) { // Evaluate the left hand side only once. target.GenerateReference(generator, optimizationInfo); target.DuplicateReference(generator, optimizationInfo); // For the GenerateSet, later on. // Load the value to assign. var compoundOperator = new BinaryExpression(GetCompoundBaseOperator(this.OperatorType), new ReferenceGetExpression(target), this.GetOperand(1)); compoundOperator.GenerateCode(generator, optimizationInfo); // Store the resulting value so we can return it as the result of the expression. var result = generator.CreateTemporaryVariable(compoundOperator.ResultType); generator.Duplicate(); generator.StoreVariable(result); // Store the value. target.GenerateSet(generator, optimizationInfo, compoundOperator.ResultType, optimizationInfo.StrictMode); // Restore the expression result. generator.LoadVariable(result); generator.ReleaseTemporaryVariable(result); }
/// <summary> /// Generates CIL for a compound assignment expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> private void GenerateCompoundAddAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target) { //var rhs = this.GetOperand(1); //if (PrimitiveTypeUtilities.IsString(rhs.ResultType) == true) //{ // // Load the value of the left-hand side and convert it to a concantenated string. // target.GenerateGet(generator, optimizationInfo, true); // EmitConversion.ToConcatenatedString(generator, target.Type); // // Transform expressions of the form "a += b + c;" into "a += b; a += c;". // List<Expression> nonAddExpressions = new List<Expression>(); // Stack<Expression> expressionStack = new Stack<Expression>(1); // expressionStack.Push(rhs); // do // { // var expression = expressionStack.Pop(); // if (expression is BinaryExpression && ((BinaryExpression)expression).OperatorType == OperatorType.Add) // { // expressionStack.Push(((BinaryExpression)expression).Right); // expressionStack.Push(((BinaryExpression)expression).Left); // } // else // nonAddExpressions.Add(expression); // } while (expressionStack.Count > 0); // foreach (var nonAddExpression in nonAddExpressions) // { // // Duplicate the ConcatenatedString instance. // generator.Duplicate(); // nonAddExpression.GenerateCode(generator, optimizationInfo); // var rhsType = nonAddExpression.ResultType; // if (rhsType == PrimitiveType.String) // { // // Concatenate. // generator.Call(ReflectionHelpers.ConcatenatedString_Append_String); // } // else if (rhsType == PrimitiveType.ConcatenatedString) // { // // Concatenate. // generator.Call(ReflectionHelpers.ConcatenatedString_Append_ConcatenatedString); // } // else // { // // Convert the operand to an object. // EmitConversion.ToAny(generator, rhsType); // // Concatenate. // generator.Call(ReflectionHelpers.ConcatenatedString_Append_Object); // } // } // if (target.Type != PrimitiveType.ConcatenatedString) // { // // Set the original variable. // generator.Duplicate(); // target.GenerateSet(generator, optimizationInfo, PrimitiveType.ConcatenatedString, optimizationInfo.StrictMode); // } //} //else //{ // Do the standard compound add. GenerateCompoundAssignment(generator, optimizationInfo, target); //} }
/// <summary> /// Generates CIL for an assignment expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> private void GenerateAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target) { // Evaluate the left hand side first! target.GenerateReference(generator, optimizationInfo); // Load the value to assign. var rhs = this.GetOperand(1); rhs.GenerateCode(generator, optimizationInfo); // Support the inferred function displayName property. if (rhs is FunctionExpression) ((FunctionExpression)rhs).GenerateDisplayName(generator, optimizationInfo, target.ToString(), false); // Store the RHS value so we can return it as the result of the expression. var result = generator.CreateTemporaryVariable(rhs.ResultType); generator.Duplicate(); generator.StoreVariable(result); // Store the value. target.GenerateSet(generator, optimizationInfo, rhs.ResultType, optimizationInfo.StrictMode); // Restore the RHS value. generator.LoadVariable(result); generator.ReleaseTemporaryVariable(result); }
/// <summary> /// Generates CIL for a compound assignment expression. /// </summary> /// <param name="generator"> The generator to output the CIL to. </param> /// <param name="optimizationInfo"> Information about any optimizations that should be performed. </param> /// <param name="target"> The target to modify. </param> private void GenerateCompoundAssignment(ILGenerator generator, OptimizationInfo optimizationInfo, IReferenceExpression target) { // Load the value to assign. var compoundOperator = new BinaryExpression(GetCompoundBaseOperator(this.OperatorType), this.GetOperand(0), this.GetOperand(1)); compoundOperator.GenerateCode(generator, optimizationInfo); // Duplicate the value so it remains on the stack afterwards. //if (optimizationInfo.SuppressReturnValue == false) generator.Duplicate(); // Store the value. target.GenerateSet(generator, optimizationInfo, compoundOperator.ResultType, optimizationInfo.StrictMode); }
public UseOfPrivateMemberInInheritedNestedClassHighlight(IReferenceExpression referenceExpression) { ReferenceExpression = referenceExpression; this.ToolTip = referenceExpression.GetText() + " is a private member and is accessed from an inherited class. This is not allowed."; this.ErrorStripeToolTip = "Private member is accessed from an inherited class."; }
public ReferenceGetExpression(IReferenceExpression reference) { this.reference = reference; }
/// <summary>Handles the specified expression.</summary> /// <param name="referenceExpression">The invoked expression.</param> /// <param name="statementParameters">The parameters.</param> /// <returns>Returns the string.</returns> public ExpressionDescriptor Handle(IReferenceExpression referenceExpression, Dictionary<string, string> statementParameters) { var result = new ExpressionDescriptor(); var qualifierExpression = referenceExpression.QualifierExpression; if (qualifierExpression != null) { var descriptor = ExpressionTemplateBuilder.Handle(qualifierExpression, statementParameters); if (descriptor != null) { result.Template = descriptor.Template; foreach (var variable in descriptor.TemplateVariables) { result.TemplateVariables[variable.Key] = variable.Value; } } else { result.Template += qualifierExpression.GetText(); } } if (!string.IsNullOrEmpty(result.Template)) { result.Template += "."; } var resolveResult = referenceExpression.Reference.Resolve(); var declaredElement = resolveResult.DeclaredElement; string qualifiedName = null; if (qualifierExpression == null && declaredElement != null) { var typeElement = declaredElement as ITypeElement; if (typeElement != null) { qualifiedName = typeElement.ShortName; var ns = typeElement.GetContainingNamespace(); if (!string.IsNullOrEmpty(ns.QualifiedName)) { qualifiedName = ns.QualifiedName + "." + qualifiedName; } } } if (string.IsNullOrEmpty(qualifiedName)) { qualifiedName = referenceExpression.NameIdentifier.GetText(); } string variableName; if (!statementParameters.TryGetValue("VariableName", out variableName)) { variableName = string.Empty; } if (qualifiedName == variableName) { qualifiedName = "$VariableName$"; } else { if (declaredElement != null) { var localVariable = declaredElement as ILocalVariable; if (localVariable != null) { if (localVariable.Type.IsUnknown) { var name = declaredElement.ShortName; qualifiedName = "$" + name + "$"; result.TemplateVariables[name] = "suggestVariableName()"; } else { var name = localVariable.Type.GetPresentableName(declaredElement.PresentationLanguage).Replace("<", string.Empty).Replace(">", string.Empty).Replace(".", string.Empty); qualifiedName = "$" + name + "$"; result.TemplateVariables[name] = string.Format("variableOfType(\"{0}\")", localVariable.Type.GetLongPresentableName(declaredElement.PresentationLanguage)); } } var parameter = declaredElement as IParameter; if (parameter != null) { if (parameter.Type.IsUnknown) { var name = declaredElement.ShortName; qualifiedName = "$" + name + "$"; result.TemplateVariables[name] = "suggestVariableName()"; } else { var name = parameter.Type.GetPresentableName(declaredElement.PresentationLanguage).Replace("<", string.Empty).Replace(">", string.Empty).Replace(".", string.Empty); qualifiedName = "$" + name + "$"; result.TemplateVariables[name] = string.Format("variableOfType(\"{0}\")", parameter.Type.GetLongPresentableName(declaredElement.PresentationLanguage)); } } } } result.Template += qualifiedName; return result; }
private static string GetExtensionMethodReturnType(IReferenceExpression unresolvedThing) { string extensionMethodReturnType = "void"; var localVariable = unresolvedThing.Parent.Parent.Parent as ILocalVariableDeclaration; if (localVariable != null) { var variableType = localVariable.TypeUsage as IPredefinedTypeUsage; var varType = variableType.ScalarPredefinedTypeName.TypeKeyword; extensionMethodReturnType = varType.GetText(); } return extensionMethodReturnType; }
private static IColorReference ReferenceFromInvocation(IReferenceExpression qualifier, IReferenceExpression methodReferenceExpression) { var invocationExpression = InvocationExpressionNavigator.GetByInvokedExpression(methodReferenceExpression); if (invocationExpression == null || invocationExpression.Arguments.IsEmpty) { return null; } var methodReference = methodReferenceExpression.Reference; var name = methodReference.GetName(); if (!string.Equals(name, "HSVToRGB", StringComparison.Ordinal)) return null; var arguments = invocationExpression.Arguments; if (arguments.Count < 3 || arguments.Count > 4) return null; var color = GetColorFromHSV(arguments); if (color == null) return null; var qualifierType = qualifier.Reference.Resolve().DeclaredElement as ITypeElement; if (qualifierType == null) return null; var unityColorTypes = UnityColorTypes.GetInstance(qualifierType.Module); if (!unityColorTypes.IsUnityColorTypeSupportingHSV(qualifierType)) return null; var colorElement = new ColorElement(color.Value); var argumentList = invocationExpression.ArgumentList; return new UnityColorReference(colorElement, invocationExpression, argumentList, argumentList.GetDocumentRange()); }
public override void VisitReferenceExpression(IReferenceExpression referenceExpressionParam, IHighlightingConsumer context) { tooManyChainedReferencesCheck.ExecuteIfEnabled(referenceExpressionParam, context); }
public CompoundAssignment(IReferenceExpression target, IExpression value, BinaryOperationKind binaryKind, IMethodSymbol operatorMethod, SyntaxNode syntax) { _compoundAssignment = new CompoundAssignmentExpression(target, value, binaryKind, operatorMethod, syntax); this.Syntax = syntax; }
public AddRhinoStub(string referenceName, IReferenceExpression referenceExpression, IBlock anchor) { _referenceName = referenceName; _referenceExpression = referenceExpression; _anchor = anchor; }
public ReferenceMessage(IExpression originalExpression, IReferenceExpression reference) : base(originalExpression) { Contract.Requires(reference != null); _reference = reference; }