コード例 #1
0
        private static void ProcessCSharpNode([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                              [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();

            var declaration = node as IDeclaration;

            if (declaration != null)
            {
                if (!declaration.IsSynthetic())
                {
                    ProcessCSharpDeclaration(declaration, parentElement, state);
                }
                return;
            }

            var multiDeclaration = node as IMultipleDeclaration;

            if (multiDeclaration != null)
            {
                ProcessCSharpMultipleDeclaration(multiDeclaration, parentElement, state);
                return;
            }

            var preprocessorDirective = node as IPreprocessorDirective;

            if (preprocessorDirective != null)
            {
                ProcessCSharpPreprocessorDirective(preprocessorDirective, parentElement, state);
            }
        }
コード例 #2
0
        public AbstractILCompilerParams(
            /*[NotNull] IResolveContext resolveContext, */ File file,
            OneToListMap <IMethod, IMethod> hierarchyMembers,
            IPsiSourceFile sourceFile,
            IPersistentIndexManager persistentIndexManager,
            /*Dictionary<Type, Pointer> exceptionTypeToPointer, */
            CSharpCacheProvider cacheProvider,
            bool buildExpressions = true)
        {
            myPersistentIndexManager = persistentIndexManager;
            SourceFile       = sourceFile;
            HierarchyMembers = hierarchyMembers;
            File             = file;
            CacheProvider    = cacheProvider;
            //ExceptionTypeToPointer = exceptionTypeToPointer;
            //ResolveContext = resolveContext;
            InterruptCheck = () =>
            {
                var interruptHandler = InterruptableActivityCookie.GetCheck();
                return(interruptHandler != null && interruptHandler());
            };
            //BuildExpressions = buildExpressions;

            LocalVariableIndexer = new LocalVariableIndexer(this);

            myCollectedInteractiveRequests = new List <Request>();
        }
コード例 #3
0
        public static TResult RunAsTask <TResult>([NotNull] this FSharpAsync <TResult> async,
                                                  [CanBeNull] Action interruptChecker = null)
        {
            const int interruptCheckTimeout = 30;

            interruptChecker = interruptChecker ?? (() => InterruptableActivityCookie.CheckAndThrow());
            var cancellationTokenSource = new CancellationTokenSource();
            var cancellationToken       = cancellationTokenSource.Token;
            var cancellationTokenOption = new FSharpOption <CancellationToken>(cancellationToken);

            var task = FSharpAsync.StartAsTask(async, null, cancellationTokenOption);

            while (!task.IsCompleted)
            {
                var finished = task.Wait(interruptCheckTimeout, cancellationToken);
                if (finished)
                {
                    break;
                }
                try
                {
                    interruptChecker();
                }
                catch (OperationCanceledException)
                {
                    cancellationTokenSource.Cancel();
                    throw;
                }
            }
            return(task.Result);
        }
コード例 #4
0
 public PerformanceCriticalCodeAnalysisProcess([NotNull] IDaemonProcess process, DaemonProcessKind processKind, [NotNull] IContextBoundSettingsStore settingsStore, [NotNull] ICSharpFile file)
     : base(process, file)
 {
     myProcessKind        = processKind;
     mySettingsStore      = settingsStore;
     ourCheckForInterrupt = InterruptableActivityCookie.GetCheck().NotNull();
 }
コード例 #5
0
        private void GetItems(out IEnumerable <IBulbAction> firstLevelItems, out IEnumerable <IBulbAction> secondLevelItems)
        {
            var firstLevelItemsList  = new List <IBulbAction>();
            var secondLevelItemsList = new List <IBulbAction>();

            var unorderedItems = myUnfilteredItems.Select(a => Tuple.Create(a, a.GetBulbItem()))
                                 .Where(i => i.Item2 != null)
                                 .ToList();

            var consistencyGroupToBulbItem = new OneToListMap <ICreatedElementConsistencyGroup, IBulbAction>();

            foreach (var unorderedItem in unorderedItems)
            {
                consistencyGroupToBulbItem.Add(unorderedItem.Item1.GetConsistencyGroup(), unorderedItem.Item2);
            }

            foreach (var consistencyGroup in consistencyGroupToBulbItem.Keys)
            {
                InterruptableActivityCookie.CheckAndThrow();

                var bulbItems = consistencyGroupToBulbItem[consistencyGroup];

                if (consistencyGroup.IsConsistent())
                {
                    firstLevelItemsList.AddRange(bulbItems);
                }
                else
                {
                    secondLevelItemsList.AddRange(bulbItems);
                }
            }

            firstLevelItems  = firstLevelItemsList;
            secondLevelItems = secondLevelItemsList;
        }
コード例 #6
0
        private void CheckInterruptAndThrow()
        {
            var interruptCheck = InterruptableActivityCookie.GetCheck();

            if (interruptCheck != null && interruptCheck())
            {
                throw new OperationCanceledException();
            }
        }
コード例 #7
0
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations,
                                    IRefactoringDriver driver)
        {
            // Rename the "declaration"
            var declaredElement  = myPointer.FindDeclaredElement();
            var originalTreeNode = declaredElement?.GetTreeNode();

            if (originalTreeNode == null)
            {
                return;
            }

            var originalRange     = originalTreeNode.GetDocumentRange();
            var factory           = JavaScriptElementFactory.GetInstance(originalTreeNode);
            var literalExpression = factory.CreateExpression("\"$0\"", NewName);
            var newExpression     = originalTreeNode.ReplaceBy(literalExpression);

            RemoveFromTextualOccurrences(executer, originalRange);

            var references = executer.Workflow.GetElementReferences(declaredElement);

            if (!Enumerable.Any(references))
            {
                return;
            }

            pi.Start(references.Count);

            // Create a new declared element (other implementations don't appear to cache this, either)
            var element = new AsmDefNameDeclaredElement(declaredElement.GetJsServices(), NewName,
                                                        declaredElement.SourceFile, newExpression.GetTreeStartOffset().Offset);

            // Rename/bind the references
            foreach (var pair in LanguageUtil.SortReferences(references.Where(r => r.IsValid())))
            {
                foreach (var sortedReference in LanguageUtil.GetSortedReferences(pair.Value))
                {
                    InterruptableActivityCookie.CheckAndThrow(pi);

                    var referenceRange = sortedReference.GetDocumentRange();

                    if (sortedReference.IsValid())
                    {
                        sortedReference.BindTo(element);
                    }

                    RemoveFromTextualOccurrences(executer, referenceRange);

                    pi.Advance();
                }
            }

            element.GetPsiServices().Caches.Update();
            myNewPointer = element.CreateElementPointer();
        }
コード例 #8
0
        public void Execute(Action <DaemonStageResult> committer)
        {
            MarkModulesAsUsed(collectUsagesStageProcess);

            var consumer           = new DefaultHighlightingConsumer(this, settingsStore);
            var referenceProcessor = new RecursiveReferenceProcessor <IMvcReference>(reference =>
            {
                InterruptableActivityCookie.CheckAndThrow();
                IHighlighting highlighting;
                switch (reference.MvcKind)
                {
                case MvcKind.Area:
                    highlighting = CheckArea(reference);
                    break;

                case MvcKind.Controller:
                    highlighting = CheckResolved(reference, _ => (IHighlighting) new MvcControllerHighlighting(_));
                    break;

                case MvcKind.Action:
                    highlighting = CheckResolved(reference, _ => (IHighlighting) new MvcActionHighlighting(_));
                    break;

                case MvcKind.View:
                case MvcKind.PartialView:
                case MvcKind.Master:
                case MvcKind.DisplayTemplate:
                case MvcKind.EditorTemplate:
                case MvcKind.Template:
                    highlighting = CheckResolved(reference,
                                                 _ => (IHighlighting) new MvcViewHighlighting((IMvcViewReference)_));
                    break;

                default:
                    highlighting = null;
                    break;
                }
                if (highlighting == null)
                {
                    return;
                }
                consumer.AddHighlighting(highlighting, GetMvcReferenceHighlightingRange(reference),
                                         reference.GetTreeNode().GetContainingFile());
            });

            foreach (IFile file in DaemonProcess.SourceFile.EnumerateDominantPsiFiles())
            {
                file.ProcessDescendants(referenceProcessor);
            }

            committer(new DaemonStageResult(consumer.Highlightings));
        }
コード例 #9
0
        public override void Execute(Action <DaemonStageResult> committer)
        {
            // todo: add more cases to GetSemanticClassification (e.g. methods, values, namespaces) and use it instead?
            var checkResults = DaemonProcess.CustomData.GetData(FSharpDaemonStageBase.TypeCheckResults);
            var declarations = myFsFile.GetAllDeclaredSymbols(checkResults?.Value);

            InterruptableActivityCookie.CheckAndThrow();

            var usages = myFsFile.GetAllResolvedSymbols();

            InterruptableActivityCookie.CheckAndThrow();

            HighlightUses(committer, declarations.Concat(usages), declarations.Length + usages.Length);
        }
コード例 #10
0
        private void MarkModulesAsUsed([CanBeNull] CollectUsagesStageProcess usagesStageProcess)
        {
            if (usagesStageProcess != null)
            {
                IEnumerable <IClass> nancyModules = NancyUtil.GetAvailableModules(DaemonProcess.PsiModule,
                                                                                  searchDomainFactory.CreateSearchDomain(DaemonProcess.SourceFile),
                                                                                  DaemonProcess.SourceFile.ResolveContext, true, null).SelectMany(_ => _.Value);

                foreach (IClass @class in nancyModules)
                {
                    InterruptableActivityCookie.CheckAndThrow();
                    collectUsagesStageProcess.SetElementState(@class, UsageState.ACCESSED | UsageState.TYPEOF);
                }
            }
        }
コード例 #11
0
        private bool IsHandlerExists(Lifetime lifetime, int projectId, string className, string methodName)
        {
            var indicator = NullProgressIndicator.CreateCancellable(lifetime);

            using (TryReadLockCookie.Create(indicator, _locks,
                                            () => !lifetime.IsAlive || _locks.ContentModelLocks.IsWriteLockRequested))
            {
                var project = _projectModelViewHost.GetItemById <IProject>(projectId);
                Assertion.AssertNotNull(project, "project instance should not be null");
                _logger.Verbose($"Searching handler with name '{className}.{methodName}' in the project {project}...");

                var psiModules = project.GetPsiModules();
                foreach (var psiModule in psiModules)
                {
                    using (CompilationContextCookie.OverrideOrCreate(psiModule.GetContextFromModule()))
                    {
                        var scope = _symbolCache.GetSymbolScope(psiModule, false, true);

                        var typeElements = scope.GetElementsByQualifiedName(className).OfType <IClass>();
                        foreach (var typeElement in typeElements)
                        {
                            InterruptableActivityCookie.CheckAndThrow(indicator);
                            foreach (var method in typeElement.Methods)
                            {
                                if (method.ShortName != methodName)
                                {
                                    continue;
                                }
                                if (!LambdaFinder.IsSuitableLambdaMethod(method))
                                {
                                    continue;
                                }

                                return(true);
                            }
                        }
                    }
                }
            }

            return(false);
        }
コード例 #12
0
        private void ProcessT4Node([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement, [NotNull] ICSharpFile cSharpFile,
                                   [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator, [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();


            var directive = node as IT4Directive;

            if (directive != null)
            {
                ProcessT4Directive(directive, parentElement);
                return;
            }

            var featureBlock = node as T4FeatureBlock;

            if (featureBlock != null)
            {
                ProcessT4FeatureBlock(featureBlock, parentElement, cSharpFile, secondaryRangeTranslator, state);
            }
        }
コード例 #13
0
        private void ExploreType(IMetadataTypeInfo type, IMetadataAssembly assembly, CancellationToken cancellationToken)
        {
            InterruptableActivityCookie.CheckAndThrow();
            cancellationToken.ThrowIfCancellationRequested();

            if (type.IsAbstract && type.GetMethods().Any(method => !(method.IsAbstract || method.IsStatic)))
            {
                return;
            }

            var testMethods = GetAllTestMethods(type);

            foreach (var method in testMethods)
            {
                var typeName = myTypeNameCache.GetClrName(method.DeclaringType);
                var id       = string.Format("{0}.{1}", typeName, method.Name);

                var testElement = GetOrCreateTest(id, typeName, method.Name);
                myUnitTestCollector.OnUnitTestElement(testElement);
            }
        }
コード例 #14
0
        private void ProcessT4Node(
            [NotNull] ITreeNode node,
            [NotNull] CodeStructureElement parentElement,
            [NotNull] ICSharpFile cSharpFile,
            [NotNull] ISecondaryRangeTranslator secondaryRangeTranslator,
            [NotNull] CSharpCodeStructureProcessingState state
            )
        {
            InterruptableActivityCookie.CheckAndThrow();

            switch (node)
            {
            case IT4Directive directive:
                ProcessT4Directive(directive, parentElement);
                return;

            case IT4FeatureBlock featureBlock:
                ProcessT4FeatureBlock(featureBlock, parentElement, cSharpFile, secondaryRangeTranslator, state);
                break;
            }
        }
コード例 #15
0
        private static void ProcessCSharpNode([NotNull] ITreeNode node, [NotNull] CodeStructureElement parentElement,
                                              [NotNull] CSharpCodeStructureProcessingState state)
        {
            InterruptableActivityCookie.CheckAndThrow();

            switch (node)
            {
            case IDeclaration declaration:
                if (!declaration.IsSynthetic())
                {
                    ProcessCSharpDeclaration(declaration, parentElement, state);
                }
                return;

            case IMultipleDeclaration multiDeclaration:
                ProcessCSharpMultipleDeclaration(multiDeclaration, parentElement, state);
                return;

            case IPreprocessorDirective preprocessorDirective:
                ProcessCSharpPreprocessorDirective(preprocessorDirective, parentElement, state);
                break;
            }
        }
コード例 #16
0
 public PerformanceCriticalCodeAnalysisProcess([NotNull] IDaemonProcess process, [NotNull] ICSharpFile file)
     : base(process, file)
 {
     myCheckForInterrupt = InterruptableActivityCookie.GetCheck().NotNull();
 }
コード例 #17
0
        public override void Rename(IRenameRefactoring executer, IProgressIndicator pi, bool hasConflictsWithDeclarations, IRefactoringDriver driver)
        {
            BuildDeclarations();

            //Logger.Assert(myDeclarations.Count > 0, "myDeclarations.Count > 0");

            IDeclaredElement declaredElement = myOriginalElementPointer.FindDeclaredElement();

            if (declaredElement == null)
            {
                return;
            }

            IPsiServices psiServices = declaredElement.GetPsiServices();

            IList <IReference> primaryReferences = executer.Workflow.GetElementReferences(PrimaryDeclaredElement);
            List <Pair <IDeclaredElement, IList <IReference> > > secondaryElementWithReferences = SecondaryDeclaredElements.Select(x => Pair.Of(x, executer.Workflow.GetElementReferences(x))).ToList();

            pi.Start(myDeclarations.Count + primaryReferences.Count);

            foreach (IDeclaration declaration in myDeclarations)
            {
                InterruptableActivityCookie.CheckAndThrow(pi);
                declaration.SetName(myNewName);
                pi.Advance();
            }

            psiServices.Caches.Update();

            IDeclaredElement newDeclaredElement;

            if (myDeclarations.Count > 0)
            {
                newDeclaredElement = myDeclarations[0].DeclaredElement;
            }
            else
            {
                if (myElement is RoleDeclaredElement)
                {
                    newDeclaredElement = myElement;
                    ((RoleDeclaredElement)myElement).ChangeName = true;
                    ((RoleDeclaredElement)myElement).NewName    = NewName;
                    ((RoleDeclaredElement)newDeclaredElement).SetName(NewName);
                }
                else
                {
                    newDeclaredElement = null;
                }
            }
            Assertion.Assert(newDeclaredElement != null, "The condition (newDeclaredElement != null) is false.");

            myNewElementPointer = newDeclaredElement.CreateElementPointer();
            Assertion.Assert(newDeclaredElement.IsValid(), "myNewDeclaredElement.IsValid()");


            myNewReferences.Clear();
            OneToSetMap <PsiLanguageType, IReference> references = LanguageUtil.SortReferences(primaryReferences.Where(x => x.IsValid()));
            IList <IReference> referencesToRename = new List <IReference>();

            foreach (var pair in references)
            {
                List <IReference> sortedReferences = pair.Value.ToList();//LanguageUtil.GetSortedReferences(pair.Value);
                foreach (IReference reference in sortedReferences)
                {
                    IReference oldReferenceForConflict = reference;
                    InterruptableActivityCookie.CheckAndThrow(pi);
                    if (reference.IsValid()) // reference may invalidate during additional reference processing
                    {
                        RenameHelperBase        rename     = executer.Workflow.LanguageSpecific[reference.GetTreeNode().Language];
                        IReference              reference1 = rename.TransformProjectedInitializer(reference);
                        DeclaredElementInstance subst      = GetSubst(newDeclaredElement, executer);
                        IReference              newReference;
                        if (subst != null)
                        {
                            if (subst.Substitution.Domain.IsEmpty())
                            {
                                newReference = reference1.BindTo(subst.Element);
                            }
                            else
                            {
                                newReference = reference1.BindTo(subst.Element, subst.Substitution);
                            }
                        }
                        else
                        {
                            newReference = reference1.BindTo(newDeclaredElement);
                        }
                        if (!(newReference is IImplicitReference))
                        {
                            IDeclaredElement element = newReference.Resolve().DeclaredElement;
                            if (!hasConflictsWithDeclarations && !myDoNotShowBindingConflicts && (element == null || !element.Equals(newDeclaredElement)) && !rename.IsAlias(newDeclaredElement))
                            {
                                driver.AddLateConflict(() => new Conflict(newReference.GetTreeNode().GetSolution(), "Usage {0} can not be updated correctly.", ConflictSeverity.Error, oldReferenceForConflict), "not bound");
                            }
                            referencesToRename.Add(newReference);
                        }
                        myNewReferences.Insert(0, newReference);
                        rename.AdditionalReferenceProcessing(newDeclaredElement, newReference, myNewReferences);
                    }

                    pi.Advance();
                }
            }

            foreach (var pair in secondaryElementWithReferences)
            {
                IDeclaredElement   element             = pair.First;
                IList <IReference> secondaryReferences = pair.Second;
                foreach (IReference reference in secondaryReferences)
                {
                    InterruptableActivityCookie.CheckAndThrow(pi);
                    if (reference.IsValid())
                    {
                        reference.BindTo(element);
                    }
                }
            }

            if (myElement is RoleDeclaredElement)
            {
                ((RoleDeclaredElement)myElement).ChangeName = false;
                ((RoleDeclaredElement)myElement).SetName(NewName);
                foreach (IReference reference in referencesToRename)
                {
                    ((PsiRoleReference)reference).SetName(NewName);
                    reference.CurrentResolveResult = null;
                    ((PsiFile)((RoleDeclaredElement)myElement).File).ClearTables();
                }
            }
        }