protected override void Run(IClassDeclaration classDeclaration, ElementProblemAnalyzerData data, IHighlightingConsumer consumer) { if (!myIsEnabled.Value) { return; } var typeElement = classDeclaration.DeclaredElement; if (typeElement == null || !ZoneConstants.IsZoneClass(typeElement)) { return; } var mark = myMarks.GetMark(typeElement.GetContainingNamespace()); var classes = myMarks.EnumerateClasses(mark).ToList(); // find all base zones var baseZones = new HashSet <IClass>(); foreach (var cls in classes) { foreach (var baseZone in MarksService.EnumerableMarkClasses(cls, true)) { if (!baseZone.Equals(cls)) { baseZones.Add(baseZone); } } } foreach (var typeUsage in classDeclaration.SuperTypeUsageNodes.OfType <IUserDeclaredTypeUsage>()) { IDeclaredType superType = CSharpTypeFactory.CreateDeclaredType(typeUsage); var superTypeElement = superType.GetTypeElement(); if (superTypeElement != null) { if (ZoneConstants.IsIRequire(superTypeElement as IInterface)) { var substitution = superType.GetSubstitution(); foreach (var parameter in substitution.Domain) { var zoneType = substitution[parameter] as IDeclaredType; if (zoneType != null) { var zoneClass = zoneType.GetTypeElement() as IClass; if (zoneClass != null && baseZones.Contains(zoneClass)) { consumer.AddHighlighting(new RedundantDependencySpecificationError(typeUsage), classDeclaration.GetContainingNode <IFile>()); } } } } } } }
private static ITypeDeclaration GetTargetTypeDeclaration([NotNull] IDeclaredTypeUsage declaredTypeUsage) { if (!declaredTypeUsage.IsValid()) { return(null); } return(CSharpTypeFactory .CreateDeclaredType(declaredTypeUsage) .GetTypeElement() ?.GetDeclarations() .OfType <ITypeDeclaration>() .FirstOrDefault(decl => LanguageManager.Instance.TryGetService <IntentionLanguageSpecific>(decl.Language) != null)); }
protected override void AfterComplete(ITextControl textControl, IObjectCreationExpression expression) { var referencedType = CSharpTypeFactory.CreateDeclaredType(expression.CreatedTypeUsage); var canInstantiate = TypeUtils.CanInstantiateType(referencedType, expression); if ((canInstantiate & CanInstantiate.ConstructorWithParameters) != 0) { var lparRange = expression.LPar.GetDocumentRange(); var rparRange = expression.RPar.GetDocumentRange(); var documentRange = lparRange.SetEndTo(rparRange.TextRange.EndOffset); var argumentsMarker = documentRange.CreateRangeMarker(); var settingsStore = expression.GetSettingsStore(); var invokeParameterInfo = settingsStore.GetValue(PostfixTemplatesSettingsAccessor.InvokeParameterInfo); var solution = expression.GetSolution(); ExecuteRefactoring(textControl, expression, executeAfter: () => { var argumentsRange = argumentsMarker.Range; if (!argumentsRange.IsValid) { return; } var offset = argumentsRange.StartOffset + argumentsRange.Length / 2; // EWW textControl.Caret.MoveTo(offset, CaretVisualPlacement.DontScrollIfVisible); if (invokeParameterInfo) { var lookupItemsOwner = Info.ExecutionContext.LookupItemsOwner; LookupUtil.ShowParameterInfo(solution, textControl, lookupItemsOwner); } }); } else { ExecuteRefactoring(textControl, expression); } }