Esempio n. 1
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            if (!(sourceFile.GetDominantPsiFile <YamlLanguage>() is IYamlFile yamlFile))
            {
                return(null);
            }

            // Note that this opens the document body chameleon, but we don't care for .meta files. They're lightweight
            var document = yamlFile.Documents.FirstOrDefault();

            if (document?.Body.BlockNode is IBlockMappingNode blockMappingNode)
            {
                foreach (var entry in blockMappingNode.Entries)
                {
                    if (entry.Key?.CompareBufferText("guid") == true && entry.Value is IPlainScalarNode valueScalarNode)
                    {
                        var guid = valueScalarNode.Text?.GetText();
                        if (guid != null)
                        {
                            return(new MetaFileCacheItem(guid));
                        }
                    }
                }
            }

            return(null);
        }
Esempio n. 2
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            var file = sourceFile.GetDominantPsiFile <JsonNewLanguage>();

            if (file == null)
            {
                return(null);
            }

            var cacheBuilder = new AsmDefCacheItemBuilder();
            var processor    = new RecursiveElementProcessor <IJsonNewLiteralExpression>(e =>
            {
                // Only accept the first name. If there are multiple name definitions, it's an error, and that's just tough luck
                if (e.IsNameLiteral() && !cacheBuilder.HasNameDefinition)
                {
                    cacheBuilder.SetNameDefinition(e.GetStringValue(), e.GetTreeStartOffset().Offset);
                }
                else if (e.IsReferenceLiteral())
                {
                    cacheBuilder.AddReference(e.GetStringValue());
                }
            });

            file.ProcessDescendants(processor);

            return(cacheBuilder.Build());
        }
        /// <summary>
        /// Process clean-up on file.
        /// </summary>
        /// <param name="projectFile">
        /// The project file to process.
        /// </param>
        /// <param name="rangeMarker">
        /// The range marker to process.
        /// </param>
        /// <param name="profile">
        /// The code cleanup settings to use.
        /// </param>
        /// <param name="progressIndicator">
        /// The progress indicator.
        /// </param>
        public void Process(
            IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator)
        {
            if (!this.IsAvailable(projectFile))
            {
                return;
            }

            ISolution solution = projectFile.GetSolution();

            ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile;

            if (file == null)
            {
                return;
            }


            if (!profile.GetSetting(FIX_VIOLATIONS))
            {
                return;
            }

            var services = solution.GetPsiServices();

            services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, profile.GetSetting(CREATE_XML_DOC_STUB)));

            StyleCopTrace.Out();
        }
        /// <summary>
        /// Process clean-up on file.
        /// </summary>
        /// <param name="projectFile">
        /// The project file to process.
        /// </param>
        /// <param name="rangeMarker">
        /// The range marker to process.
        /// </param>
        /// <param name="profile">
        /// The code cleanup settings to use.
        /// </param>
        /// <param name="progressIndicator">
        /// The progress indicator.
        /// </param>
        public void Process(
            IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator)
        {
            if (!this.IsAvailable(projectFile))
            {
                return;
            }

            ISolution solution = projectFile.GetSolution();

            ICSharpFile file = projectFile.GetDominantPsiFile <CSharpLanguage>() as ICSharpFile;

            if (file == null)
            {
                return;
            }

            StyleCopCodeCleanupOptions options = profile.GetSetting(Descriptor);

            if (!options.FixViolations)
            {
                return;
            }

            var services = solution.GetPsiServices();

            services.Transactions.Execute("Code cleanup", () => this.InternalProcess(projectFile.ToProjectFile(), file, options.CreateXmlDocStubs));

            StyleCopTrace.Out();
        }
        public void Build(IPsiSourceFile sourceFile, ProjectSettingsCacheItem cacheItem)
        {
            {
                var file   = sourceFile.GetDominantPsiFile <YamlLanguage>() as IYamlFile;
                var inputs = GetCollection(file, "InputManager", "m_Axes");

                if (inputs == null)
                {
                    myLogger.Error("inputs != null");
                    return;
                }

                if (inputs is IBlockSequenceNode node)
                {
                    foreach (var s in node.Entries)
                    {
                        var input       = s.Value;
                        var inputRecord = input as IBlockMappingNode;
                        if (inputRecord == null)
                        {
                            continue;
                        }

                        var name = inputRecord.Entries.FirstOrDefault(t => t.Key.GetText().Equals(UnityYamlConstants.NameProperty))?.Content.Value.GetPlainScalarText();

                        if (!name.IsNullOrEmpty())
                        {
                            cacheItem.Inputs.Add(name);
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            // If YAML parsing is disabled, this will return null
            var file = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IYamlFile;

            if (file == null)
            {
                return(null);
            }

            var cacheItems         = new JetHashSet <UnityEventHandlerCacheItem>();
            var referenceProcessor = new ConditionalRecursiveReferenceProcessor(reference =>
            {
                var assetGuid = reference.GetScriptAssetGuid();
                if (assetGuid != null)
                {
                    cacheItems.Add(new UnityEventHandlerCacheItem(assetGuid, reference.EventHandlerName));
                }
            });

            foreach (var document in file.DocumentsEnumerable)
            {
                if (UnityEventTargetReferenceFactory.CanContainReference(document))
                {
                    referenceProcessor.ProcessForResolve(document);
                }
            }

            return(cacheItems.Count > 0 ? cacheItems : null);
        }
Esempio n. 7
0
        public ISelectedRange GetSelectedRange(IPsiSourceFile sourceFile, DocumentRange documentRange)
        {
            var file = (SpringFile)sourceFile.GetDominantPsiFile <SpringLanguage>();
            var node = file.FindNodeAt(documentRange);

            return(new SpringTreeNodeSelection(file, node));
        }
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }


            // If YAML parsing is disabled, this will return null
            var file = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IUnityYamlFile;

            if (file == null)
            {
                return(null);
            }

            var result = new Dictionary <string, string>();

            foreach (var document in file.Documents)
            {
                var buffer = document.GetTextAsBuffer();
                if (ourGameObjectReferenceStringSearcher.Find(buffer, 0, Math.Min(100, buffer.Length)) >= 0)
                {
                    var anchor = UnitySceneDataUtil.GetAnchorFromBuffer(buffer);
                    if (anchor == null)
                    {
                        continue;
                    }

                    var name = GetNameFromBuffer(buffer);
                    if (name == null)
                    {
                        continue;
                    }
                    result[anchor] = name;
                }
                else
                {
                    FillDictionary(result, buffer);
                }
            }

            foreach (var componentDocument in file.ComponentDocuments)
            {
                FillDictionary(result, componentDocument.GetTextAsBuffer());
            }

            if (result.Count == 0)
            {
                return(null);
            }
            return(result);
        }
        public void Build(IPsiSourceFile sourceFile, ProjectSettingsCacheItem cacheItem)
        {
            var file        = sourceFile.GetDominantPsiFile <YamlLanguage>() as IYamlFile;
            var scenesArray = GetSceneCollection(file);

            if (scenesArray == null)
            {
                myLogger.Error("scenesArray != null");
                return;
            }

            if (scenesArray is IBlockSequenceNode node)
            {
                foreach (var s in node.Entries)
                {
                    var scene       = s.Value;
                    var sceneRecord = scene as IBlockMappingNode;
                    if (sceneRecord == null)
                    {
                        continue;
                    }

                    if (sceneRecord.Entries.Count < 2)
                    {
                        continue;
                    }

                    var scenePath = sceneRecord.Entries[1].Content?.Value.GetPlainScalarText();
                    if (scenePath == null)
                    {
                        continue;
                    }

                    var path = GetUnityScenePathRepresentation(scenePath);
                    var isEnabledPlaneScalarNode = sceneRecord.Entries[0].Content?.Value as IPlainScalarNode;
                    var isEnabled = isEnabledPlaneScalarNode?.Text.GetText().Equals("1");
                    if (path == null || !isEnabled.HasValue)
                    {
                        continue;
                    }

                    cacheItem.Scenes.SceneNamesFromBuildSettings.Add(path);
                    if (!isEnabled.Value)
                    {
                        cacheItem.Scenes.DisabledSceneNamesFromBuildSettings.Add(path);
                    }
                }
            }
        }
Esempio n. 10
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            if (!(sourceFile.GetDominantPsiFile <YamlLanguage>() is IYamlFile yamlFile))
            {
                return(null);
            }

            var isBinary = yamlFile.CachingLexer.TokenBuffer[0].Type == YamlTokenType.NON_PRINTABLE;

            return(new BinaryFileCacheItem(isBinary));
        }
Esempio n. 11
0
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            // If YAML parsing is disabled, this will return null
            var file = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IUnityYamlFile;

            if (file == null)
            {
                return(null);
            }

            return(UnitySceneData.Build(file));
        }
Esempio n. 12
0
        public void Build(IPsiSourceFile sourceFile, ProjectSettingsCacheItem cacheItem)
        {
            var file      = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IYamlFile;
            var tagsArray = GetCollection(file, "TagManager", "tags");

            if (tagsArray == null)
            {
                myLogger.Error("tagsArray != null");
                return;
            }

            if (tagsArray is IBlockSequenceNode node)
            {
                foreach (var s in node.Entries)
                {
                    var text = (s.Value as IPlainScalarNode)?.Text.GetText();
                    if (!text.IsNullOrEmpty())
                    {
                        cacheItem.Tags.Add(text);
                    }
                }
            }

            var layersArray = GetCollection(file, "TagManager", "layers");

            if (layersArray == null)
            {
                myLogger.Error("layersArray != null");
                return;
            }

            if (layersArray is IBlockSequenceNode layersNode)
            {
                foreach (var s in layersNode.Entries)
                {
                    var text = (s.Value as IPlainScalarNode)?.Text.GetText();
                    if (!text.IsNullOrEmpty())
                    {
                        cacheItem.Layers.Add(text);
                    }
                }
            }
        }
        public override object Build(IPsiSourceFile sourceFile, bool isStartup)
        {
            if (!IsApplicable(sourceFile))
            {
                return(null);
            }

            // TODO: Check if this works for JS islands in HTML
            var jsFile = sourceFile.GetDominantPsiFile <JavaScriptLanguage>() as IJavaScriptFile;

            if (jsFile == null)
            {
                return(null);
            }

            var processor = new RecursiveElementProcessor();

            jsFile.ProcessDescendants(processor);
            return(processor.CacheObject.IsEmpty ? null : processor.CacheObject);
        }
        public int[] Build(IPsiSourceFile sourceFile, SeldomInterruptChecker interruptChecker)
        {
            var file = sourceFile.GetDominantPsiFile <UnityYamlLanguage>() as IYamlFile;

            if (file == null)
            {
                return(null);
            }

            using (UnsafeWriter.Cookie unsafeWriterCookie = UnsafeWriter.NewThreadLocalWriter())
            {
                TrigramIndexEntryBuilder indexEntryBuilder = new TrigramIndexEntryBuilder(unsafeWriterCookie);
                foreach (var yamlDocument in file.Documents)
                {
                    foreach (TrigramToken trigramToken in new BufferTrigramSource(yamlDocument.GetTextAsBuffer()))
                    {
                        indexEntryBuilder.Add(trigramToken);
                    }
                }

                UnsafeIntArray entryData = indexEntryBuilder.Build();
                return(entryData.ToIntArray());
            }
        }
Esempio n. 15
0
 protected override IEnumerable <SpringFile> GetPsiFiles(IPsiSourceFile sourceFile)
 {
     yield return((SpringFile)sourceFile.GetDominantPsiFile <SpringLanguage>());
 }
 protected override IEnumerable <PascalFile> GetPsiFiles(IPsiSourceFile sourceFile)
 {
     yield return((PascalFile)sourceFile.GetDominantPsiFile <PascalLanguage>());
 }
Esempio n. 17
0
 protected override bool IsApplicable([NotNull] IPsiSourceFile sourceFile)
 {
     return(sourceFile.GetDominantPsiFile <CSharpLanguage>() != null);
 }
 /// <summary>
 /// Check if this module can handle given project file.
 /// </summary>
 /// <param name="projectFile">
 /// The project file to check.
 /// </param>
 /// <returns>
 /// <c>True.</c>if the project file is available; otherwise
 /// <c>False.</c>.
 /// </returns>
 public bool IsAvailable(IPsiSourceFile projectFile)
 {
     return(projectFile.GetDominantPsiFile <CSharpLanguage>() != null);
 }
 /// <summary>
 /// Check if this module can handle given project file.
 /// </summary>
 /// <param name="projectFile">
 /// The project file to check.
 /// </param>
 /// <returns>
 /// <c>True.</c>if the project file is available; otherwise 
 /// <c>False.</c>.
 /// </returns>
 public bool IsAvailable(IPsiSourceFile projectFile)
 {
     return projectFile.GetDominantPsiFile<CSharpLanguage>() != null;
 }
        /// <summary>
        /// Process clean-up on file.
        /// </summary>
        /// <param name="projectFile">
        /// The project file to process.
        /// </param>
        /// <param name="rangeMarker">
        /// The range marker to process.
        /// </param>
        /// <param name="profile">
        /// The code cleanup settings to use.
        /// </param>
        /// <param name="progressIndicator">
        /// The progress indicator.
        /// </param>
        public void Process(
            IPsiSourceFile projectFile, IRangeMarker rangeMarker, CodeCleanupProfile profile, JetBrains.Application.Progress.IProgressIndicator progressIndicator)
        {
            if (projectFile == null)
            {
                return;
            }

            if (!this.IsAvailable(projectFile))
            {
                return;
            }

            ISolution solution = projectFile.GetSolution();

            ICSharpFile file = projectFile.GetDominantPsiFile<CSharpLanguage>() as ICSharpFile;

            if (file == null)
            {
                return;
            }

            var services = solution.GetPsiServices(); 
            services.Transactions.Execute("Code cleanup", () => this.InternalProcess(profile, file));

            StyleCopTrace.Out();
        }