Example #1
0
        public void Run(ILexer <int> lexer, ShaderLabParser parser, SeldomInterruptChecker interruptChecker)
        {
            for (var tokenType = lexer.TokenType; tokenType != null; tokenType = lexer.TokenType)
            {
                interruptChecker.CheckForInterrupt();

                if (tokenType == ShaderLabTokenType.PP_ERROR ||
                    tokenType == ShaderLabTokenType.PP_WARNING ||
                    tokenType == ShaderLabTokenType.PP_LINE)
                {
                    var startOffset = lexer.TokenStart;
                    var directive   = parser.ParsePreprocessorDirective();
                    myPpDirectivesByOffset[startOffset] = directive;
                    myRanges.Add(new TextRange(startOffset, lexer.TokenStart));
                }
                else if (tokenType == ShaderLabTokenType.CG_INCLUDE ||
                         tokenType == ShaderLabTokenType.GLSL_INCLUDE ||
                         tokenType == ShaderLabTokenType.HLSL_INCLUDE)
                {
                    var startOffset = lexer.TokenStart;
                    var include     = parser.ParseIncludeBlock();
                    myPpDirectivesByOffset[startOffset] = include;
                    myRanges.Add(new TextRange(startOffset, lexer.TokenStart));
                }
                else
                {
                    lexer.Advance();
                }
            }
        }
Example #2
0
 public PsiParser(ILexer lexer)
 {
     myCheckForInterrupt = new SeldomInterruptChecker();
     myOriginalLexer     = lexer;
     myLexer             = new FilteringPsiLexer(lexer);
     myLexer.Start();
 }
        private void HighlightUses(Action <DaemonStageResult> committer, IEnumerable <FSharpResolvedSymbolUse> symbols, int allSymbolsCount)
        {
            var highlightings = new List <HighlightingInfo>(allSymbolsCount);

            foreach (var resolvedSymbolUse in symbols)
            {
                var symbolUse = resolvedSymbolUse.SymbolUse;
                var symbol    = symbolUse.Symbol;

                var highlightingId =
                    symbolUse.IsFromComputationExpression
            ? HighlightingAttributeIds.KEYWORD
            : symbol.GetHighlightingAttributeId();

                if (symbolUse.IsFromDefinition && symbol is FSharpMemberOrFunctionOrValue mfv)
                {
                    if (myDocument.Buffer.GetText(resolvedSymbolUse.Range).Equals("new", StringComparison.Ordinal) &&
                        mfv.LogicalName.Equals(".ctor", StringComparison.Ordinal))
                    {
                        continue;
                    }
                }

                var documentRange = new DocumentRange(myDocument, resolvedSymbolUse.Range);
                var highlighting  = new FSharpIdentifierHighlighting(highlightingId, documentRange);
                highlightings.Add(new HighlightingInfo(documentRange, highlighting));

                SeldomInterruptChecker.CheckForInterrupt();
            }
            committer(new DaemonStageResult(highlightings));
        }
Example #4
0
 public PsiParser(ILexer lexer)
 {
   myCheckForInterrupt = new SeldomInterruptChecker();
   myOriginalLexer = lexer;
   myLexer = new FilteringPsiLexer(lexer);
   myLexer.Start();
 }
    public static void Run(TreeElement node, ILexer lexer, ITokenOffsetProvider offsetProvider, bool trimTokens, SeldomInterruptChecker interruptChecker)
    {
      Assertion.Assert(node.parent == null, "node.parent == null");

      var root = node as CompositeElement;
      if (root == null)
      {
        return;
      }

      var inserter = new PsiMissingTokensInserter(lexer, offsetProvider, interruptChecker);
      lexer.Start();

      if (trimTokens)
      {
        using (var container = new DummyContainer(root))
        {
          inserter.Run(container);
        }
      }
      else
      {
        var terminator = new EofToken(lexer.Buffer);
        root.AppendNewChild(terminator);
        inserter.Run(root);
        root.DeleteChildRange(terminator, terminator);
      }
    }
 public NTriplesParser(ILexer lexer, CommonIdentifierIntern commonIdentifierIntern)
 {
     this.commonIdentifierIntern = commonIdentifierIntern;
     this.originalLexer = lexer;
     this.myCheckForInterrupt = new SeldomInterruptChecker();
     this.setLexer(new NTriplesFilteringLexer(lexer));
 }
Example #7
0
 public NTriplesParser(ILexer lexer, CommonIdentifierIntern commonIdentifierIntern)
 {
     this.commonIdentifierIntern = commonIdentifierIntern;
     this.originalLexer          = lexer;
     this.myCheckForInterrupt    = new SeldomInterruptChecker();
     this.setLexer(new NTriplesFilteringLexer(lexer));
 }
Example #8
0
        public IUnityAssetDataElement Build(SeldomInterruptChecker seldomInterruptChecker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument)
        {
            if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer))
            {
                var anchor = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);
                if (!anchor.HasValue)
                {
                    return(null);
                }

                var dictionary = new Dictionary <string, IAssetValue>();
                var entries    = assetDocument.Document.FindRootBlockMapEntries()?.Entries;
                if (entries == null)
                {
                    return(null);
                }

                foreach (var entry in entries)
                {
                    var key = entry.Key.GetPlainScalarText();
                    if (key == null || ourIgnoredMonoBehaviourEntries.Contains(key))
                    {
                        continue;
                    }

                    foreach (var deserializer in myDeserializers)
                    {
                        try
                        {
                            if (deserializer.TryGetInspectorValue(currentSourceFile, entry.Content, out var result))
                            {
                                dictionary[key] = result;
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            myLogger.Error(e, "An error occurred while deserializing value {0}", deserializer.GetType().Name);
                        }
                    }
                }

                if (dictionary.TryGetValue(UnityYamlConstants.ScriptProperty, out var scriptValue) && scriptValue is AssetReferenceValue referenceValue)
                {
                    var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor.Value);
                    var script   = referenceValue.Reference;
                    var list     = new List <InspectorVariableUsage>();
                    foreach (var(key, value) in dictionary)
                    {
                        list.Add(new InspectorVariableUsage(location, script, key, value));
                    }

                    var result = new AssetInspectorValuesDataElement(list);
                    return(result);
                }
            }

            return(null);
        }
 public LexParser(ILexer lexer, CommonIdentifierIntern commonIdentifierIntern)
 {
     myCheckForInterrupt      = new SeldomInterruptChecker();
     myOriginalLexer          = lexer;
     myCommonIdentifierIntern = commonIdentifierIntern;
     myLexer = new FilteringLexLexer(lexer);
     myLexer.Start();
 }
        public PsiParser(ILexer lexer, CommonIdentifierIntern commonIdentifierIntern)
        {
            myCheckForInterrupt      = new SeldomInterruptChecker();
            myOriginalLexer          = lexer;
            myCommonIdentifierIntern = commonIdentifierIntern;
            var tokenBuffer = new TokenBuffer(lexer);

            myLexer = new FilteringPsiLexer(tokenBuffer.CreateLexer());
            myLexer.Start();
        }
            public override bool InteriorShouldBeProcessed(ITreeNode element)
            {
                SeldomInterruptChecker.CheckForInterrupt();

                if (element == StartTreeNode)
                {
                    return(true);
                }

                return(!UnityCallGraphUtil.IsFunctionNode(element) && !IsBurstProhibitedNode(element));
            }
        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);

            SeldomInterruptChecker.CheckForInterrupt();

            var usages = myFsFile.GetAllResolvedSymbols();

            SeldomInterruptChecker.CheckForInterrupt();

            HighlightUses(committer, declarations.Concat(usages), declarations.Length + usages.Length);
        }
Example #13
0
        public int[] Build(IPsiSourceFile sourceFile, SeldomInterruptChecker interruptChecker)
        {
            using (UnsafeWriter.Cookie unsafeWriterCookie = UnsafeWriter.NewThreadLocalWriter())
            {
                TrigramIndexEntryBuilder indexEntryBuilder = new TrigramIndexEntryBuilder(unsafeWriterCookie);
                foreach (TrigramToken trigramToken in new BufferTrigramSource(new StringBuffer(ASSET_REFERENCE_IDENTIFIER)))
                {
                    indexEntryBuilder.Add(trigramToken);
                }

                UnsafeIntArray entryData = indexEntryBuilder.Build();
                return(entryData.ToIntArray());
            }
        }
        public object Build(SeldomInterruptChecker checker, IPsiSourceFile file, AssetDocument document)
        {
            if (AssetUtils.IsMonoBehaviourDocument(document.Buffer))
            {
                return(ExtractStateMachineBehaviour(document, file));
            }
            var animatorExtractor = new AnimatorExtractor(file, document);

            if (AssetUtils.IsAnimatorStateMachine(document.Buffer))
            {
                return(animatorExtractor.TryExtractStateMachine());
            }
            return(AssetUtils.IsAnimatorState(document.Buffer) ? animatorExtractor.TryExtractUsage() : null);
        }
        public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument)
        {
            // TODO: deps for other assets
            if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer))
            {
                var  anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);
                bool stripped  = AssetUtils.IsStripped(assetDocument.Buffer);
                if (stripped) // we will handle it in prefabs
                {
                    return(null);
                }

                if (!anchorRaw.HasValue)
                {
                    return(null);
                }

                var anchor = anchorRaw.Value;

                var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;
                if (entries == null)
                {
                    return(null);
                }
                foreach (var entry in entries)
                {
                    if (!entry.Key.MatchesPlainScalarText("m_Script"))
                    {
                        continue;
                    }

                    var deps = entry.Content.Value.AsFileID()?.ToReference(currentSourceFile);
                    if (deps == null)
                    {
                        continue;
                    }

                    return(new AssetUsagesDataElement(
                               new AssetUsage(
                                   new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor), new [] { deps })));
                }
            }

            return(null);
        }
Example #16
0
        public object Build(SeldomInterruptChecker checker, IPsiSourceFile currentAssetSourceFile, AssetDocument assetDocument)
        {
            // TODO: deps for other assets
            if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer))
            {
                var  anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);
                bool stripped  = AssetUtils.IsStripped(assetDocument.Buffer);
                if (stripped) // we will handle it in prefabs
                {
                    return(null);
                }

                if (!anchorRaw.HasValue)
                {
                    return(null);
                }

                var anchor = anchorRaw.Value;

                var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;
                if (entries == null)
                {
                    return(null);
                }

                var result = new LocalList <AssetScriptUsage>();
                foreach (var entry in entries)
                {
                    if (!entry.Key.MatchesPlainScalarText("m_Script"))
                    {
                        continue;
                    }

                    var deps = entry.Content.Value.ToHierarchyReference(currentAssetSourceFile);
                    if (deps is ExternalReference externalReference)
                    {
                        result.Add(new AssetScriptUsage(new LocalReference(currentAssetSourceFile.Ptr().Id, anchor), externalReference));
                    }
                }

                return(result);
            }

            return(null);
        }
        public void Run(ILexer <int> lexer, CgParser parser, SeldomInterruptChecker interruptChecker)
        {
            for (var tokenType = lexer.TokenType; tokenType != null; tokenType = lexer.TokenType)
            {
                interruptChecker.CheckForInterrupt();

                if (tokenType == CgTokenNodeTypes.DIRECTIVE)
                {
                    var startOffset      = lexer.TokenStart;
                    var directiveElement = parser.ParseDirective();
                    myPpDirectivesByOffset[startOffset] = directiveElement;
                    myRanges.Add(new TextRange(startOffset, lexer.TokenStart));
                }
                else
                {
                    lexer.Advance();
                }
            }
        }
Example #18
0
        public static UnitySceneData Build(IUnityYamlFile file)
        {
            Assertion.Assert(file.IsValid(), "file.IsValid()");
            Assertion.Assert(file.GetSolution().Locks.IsReadAccessAllowed(), "ReadLock is required");

            var interruptChecker            = new SeldomInterruptChecker();
            var unityPropertyValueCacheItem = new OneToListMap <MonoBehaviourProperty, MonoBehaviourPropertyValue>();
            var sceneHierarchy = new SceneHierarchy();

            var anchorToEventHandler       = new OneToSetMap <string, string>();
            var scriptMapping              = new OneToSetMap <string, string>();
            var eventHandlerToScriptTarget = new OneToSetMap <string, FileID>();

            foreach (var document in file.DocumentsEnumerable)
            {
                interruptChecker.CheckForInterrupt();
                var buffer = document.GetTextAsBuffer();
                if (ourPrefabModificationSearcher.Find(buffer, 0, Math.Min(buffer.Length, 100)) > 0)
                {
                    sceneHierarchy.AddPrefabModification(buffer);
                }
                else
                {
                    var simpleValues    = new Dictionary <string, string>();
                    var referenceValues = new Dictionary <string, FileID>();
                    UnitySceneDataUtil.ExtractSimpleAndReferenceValues(buffer, simpleValues, referenceValues, eventHandlerToScriptTarget);

                    FillProperties(simpleValues, referenceValues, unityPropertyValueCacheItem);
                    FillScriptMapping(simpleValues, referenceValues, scriptMapping);

                    sceneHierarchy.AddSceneHierarchyElement(simpleValues, referenceValues);
                }
            }

            if (unityPropertyValueCacheItem.Count == 0 && sceneHierarchy.Elements.Count == 0)
            {
                return(null);
            }

            return(new UnitySceneData(unityPropertyValueCacheItem, eventHandlerToScriptTarget, scriptMapping, sceneHierarchy));
        }
        private FindExecution RunForNamedReferences(ITreeNode scope)
        {
            var suspiciousRefs = new List <IReference>();

            var interruptChecker = new SeldomInterruptChecker();

            for (var descendants = new FixedThisAndDescendantsEnumerator(myRoot); descendants.MoveNext();)
            {
                var element = descendants.Current;

                foreach (var reference in GetReferences(element))
                {
                    suspiciousRefs.Add(reference);
                }

                if (!ShouldVisitScope(element))
                {
                    descendants.SkipThisNode();
                }

                interruptChecker.CheckForInterrupt();
            }

            if (suspiciousRefs.Count > 0)
            {
                MultipleReferencesResolver.ResolveReferences(scope, suspiciousRefs);
            }

            foreach (var reference in suspiciousRefs)
            {
                var execution = ProcessReference(reference);
                if (execution == FindExecution.Stop)
                {
                    return(FindExecution.Stop);
                }
                interruptChecker.CheckForInterrupt();
            }

            return(FindExecution.Continue);
        }
        public static void Run(
            TreeElement node,
            ILexer lexer,
            ITokenOffsetProvider offsetProvider,
            bool trimTokens,
            SeldomInterruptChecker interruptChecker,
            ITokenIntern intern)
        {
            Assertion.Assert(node.parent == null, "node.parent == null");

            var root = node as CompositeElement;

            if (root == null)
            {
                return;
            }

            var inserter = new NTriplesMissingTokensInserter(lexer, offsetProvider, interruptChecker, intern);

            lexer.Start();

            if (trimTokens)
            {
                using (var container = new DummyContainer(root))
                {
                    inserter.Run(container);
                }
            }
            else
            {
                var terminator = new EofToken(lexer.Buffer);
                root.AppendNewChild(terminator);
                inserter.Run(root);
                root.DeleteChildRange(terminator, terminator);
            }
        }
        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());
            }
        }
Example #22
0
 private PsiMissingTokensInserter(ILexer lexer, ITokenOffsetProvider offsetProvider, SeldomInterruptChecker interruptChecker)
     : base(offsetProvider, interruptChecker)
 {
     myLexer = lexer;
 }
 public int[] Build(IDocument document, SeldomInterruptChecker interruptChecker, string displayName)
 {
     myLogger.Error("Unsupported operation for yaml file");
     return(Array.Empty <int>());
 }
        public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument)
        {
            var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);

            if (!anchorRaw.HasValue)
            {
                return(null);
            }

            var anchor = anchorRaw.Value;

            var isStripped                = AssetUtils.IsStripped(assetDocument.Buffer);
            var gameObject                = AssetUtils.GetGameObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference;
            var prefabInstance            = AssetUtils.GetPrefabInstance(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference;
            var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference;
            var location = new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor);

            if (AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer))
            {
                var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;
                if (entries == null)
                {
                    return(null);
                }

                AssetDocumentReference documentReference = null;

                foreach (var entry in entries)
                {
                    if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty))
                    {
                        documentReference = entry.Content.Value.AsFileID();
                        break;
                    }
                }

                var scriptAnchor = documentReference?.AnchorLong;
                var scriptGuid   = documentReference?.ExternalAssetGuid;
                if (isStripped || scriptAnchor != null && scriptGuid != null)
                {
                    return(new AssetDocumentHierarchyElement(
                               new ScriptComponentHierarchy(location,
                                                            isStripped ? null : new ExternalReference(scriptGuid, scriptAnchor.Value),
                                                            gameObject,
                                                            prefabInstance,
                                                            correspondingSourceObject,
                                                            isStripped
                                                            )));
                }
            }
            else if (AssetUtils.IsTransform(assetDocument.Buffer))
            {
                var father    = AssetUtils.GetTransformFather(assetDocument.Buffer)?.ToReference(currentSourceFile) as LocalReference;
                var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer);
                return(new AssetDocumentHierarchyElement(
                           new TransformHierarchy(location, gameObject, father, rootIndex, prefabInstance, correspondingSourceObject, isStripped)));
            }
            else if (AssetUtils.IsGameObject(assetDocument.Buffer))
            {
                var name = AssetUtils.GetGameObjectName(assetDocument.Buffer);
                if (isStripped || name != null)
                {
                    return(new AssetDocumentHierarchyElement(new GameObjectHierarchy(location, name, prefabInstance, correspondingSourceObject, isStripped)));
                }
            }
            else if (AssetUtils.IsPrefabModification(assetDocument.Buffer))
            {
                var modification    = AssetUtils.GetPrefabModification(assetDocument.Document);
                var parentTransform = modification?.GetValue("m_TransformParent")?.AsFileID()?.ToReference(currentSourceFile) as LocalReference;
                var modifications   = modification?.GetValue("m_Modifications") as IBlockSequenceNode;
                var result          = new List <PrefabModification>();
                if (modifications != null)
                {
                    foreach (var entry in modifications.Entries)
                    {
                        var map = entry.Value as IBlockMappingNode;
                        if (map == null)
                        {
                            continue;
                        }

                        var target = map.GetValue("target").AsFileID()?.ToReference(currentSourceFile);
                        if (target == null)
                        {
                            continue;
                        }

                        var name = map.GetValue("propertyPath").GetPlainScalarText();
                        if (name == null)
                        {
                            continue;
                        }

                        var valueNode = map.FindMapEntryBySimpleKey("value")?.Content;
                        if (valueNode == null)
                        {
                            continue;
                        }

                        IAssetValue value = null;
                        foreach (var assetInspectorValueDeserializer in myAssetInspectorValueDeserializers)
                        {
                            if (assetInspectorValueDeserializer.TryGetInspectorValue(currentSourceFile, valueNode, out value))
                            {
                                break;
                            }
                        }
                        if (value == null)
                        {
                            continue;
                        }

                        result.Add(new PrefabModification(target, name, value));
                    }
                }

                var sourcePrefabGuid = AssetUtils.GetSourcePrefab(assetDocument.Buffer)?.ToReference(currentSourceFile) as ExternalReference;
                if (sourcePrefabGuid == null)
                {
                    return(null);
                }
                return(new AssetDocumentHierarchyElement(new PrefabInstanceHierarchy(location, sourcePrefabGuid.ExternalAssetGuid, parentTransform, result)));
            }
            else // regular component
            {
                var name = AssetUtils.GetRawComponentName(assetDocument.Buffer);
                if (name == null)
                {
                    return(null);
                }

                return(new AssetDocumentHierarchyElement(
                           new ComponentHierarchy(name, location, gameObject, prefabInstance, correspondingSourceObject, isStripped)));
            }
            return(null);
        }
Example #25
0
        private void InsertMissingTokens(TreeElement root, ITokenIntern intern)
        {
            var interruptChecker = new SeldomInterruptChecker();

            ShaderLabMissingTokensInserter.Run(root, myOriginalLexer, this, interruptChecker, intern);
        }
        public static void Run(TreeElement node, ILexer lexer, ITokenOffsetProvider offsetProvider, ShaderLabPreProcessor preProcessor, SeldomInterruptChecker interruptChecker, ITokenIntern intern)
        {
            Assertion.Assert(node.parent == null, "node.parent == null");

            var root = node as CompositeElement;

            if (root == null)
            {
                return;
            }

            // Append an EOF token so we insert filtered tokens right up to
            // the end of the file
            var eof = new EofToken(lexer.Buffer.Length);

            root.AppendNewChild(eof);

            var inserter = new ShaderLabMissingTokensInserter(lexer, offsetProvider, preProcessor, interruptChecker, intern);

            // Reset the lexer, walk the tree and call ProcessLeafElement on each leaf element
            lexer.Start();
            inserter.Run(root);

            root.DeleteChildRange(eof, eof);
        }
 private PsiMissingTokensInserter(ILexer lexer, ITokenOffsetProvider offsetProvider, SeldomInterruptChecker interruptChecker)
   : base(offsetProvider, interruptChecker)
 {
   myLexer = lexer;
 }
 private ShaderLabMissingTokensInserter(ILexer lexer, ITokenOffsetProvider offsetProvider, ShaderLabPreProcessor preProcessor, SeldomInterruptChecker interruptChecker, ITokenIntern intern)
     : base(offsetProvider, interruptChecker, intern)
 {
     myLexer        = lexer;
     myPreProcessor = preProcessor;
 }
 private NTriplesMissingTokensInserter(
     ILexer lexer, ITokenOffsetProvider offsetProvider, SeldomInterruptChecker interruptChecker, ITokenIntern intern)
     : base(offsetProvider, interruptChecker, intern)
 {
     this.myLexer = lexer;
 }
Example #30
0
 private T4MissingTokenInserter(
     ILexer lexer,
     ITokenOffsetProvider offsetProvider,
     SeldomInterruptChecker interruptChecker,
     ITokenIntern intern
     ) : base(offsetProvider, interruptChecker, intern) => myLexer = lexer;
        public IUnityAssetDataElement Build(SeldomInterruptChecker checker, IPsiSourceFile currentSourceFile, AssetDocument assetDocument)
        {
            var buffer = assetDocument.Buffer;

            if (ourMethodNameSearcher.Find(buffer) < 0)
            {
                return(null);
            }

            var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);

            if (!anchorRaw.HasValue)
            {
                return(null);
            }

            var anchor = anchorRaw.Value;

            var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;

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

            var result = new List <AssetMethodData>();

            foreach (var entry in entries)
            {
                if (ourMethodNameSearcher.Find(entry.Content.GetTextAsBuffer()) >= 0)
                {
                    var rootMap            = entry.Content.Value as IBlockMappingNode;
                    var persistentCallsMap = rootMap.GetValue("m_PersistentCalls") as IBlockMappingNode;
                    var mCalls             = persistentCallsMap.GetValue("m_Calls") as IBlockSequenceNode;
                    if (mCalls == null)
                    {
                        return(null);
                    }

                    var eventTypeName = rootMap.GetValue("m_TypeName").GetPlainScalarText();

                    foreach (var call in mCalls.Entries)
                    {
                        var methodDescription = call.Value as IBlockMappingNode;
                        if (methodDescription == null)
                        {
                            continue;
                        }

                        var fileID = methodDescription.FindMapEntryBySimpleKey("m_Target")?.Content.Value.AsFileID();
                        if (fileID == null || fileID.IsNullReference)
                        {
                            continue;
                        }

                        var methodNameNode = methodDescription.GetValue("m_MethodName");
                        var methodName     = methodNameNode?.GetPlainScalarText();
                        if (methodName == null)
                        {
                            continue;
                        }

                        var methodNameRange = methodNameNode.GetTreeTextRange();

                        var arguments = methodDescription.GetValue("m_Arguments") as IBlockMappingNode;
                        var modeText  = methodDescription.GetValue("m_Mode")?.GetPlainScalarText();
                        var argMode   = EventHandlerArgumentMode.EventDefined;
                        if (int.TryParse(modeText, out var mode))
                        {
                            if (1 <= mode && mode <= 6)
                            {
                                argMode = (EventHandlerArgumentMode)mode;
                            }
                        }

                        var argumentTypeName = arguments.GetValue("m_ObjectArgumentAssemblyTypeName")?.GetPlainScalarText();

                        var type = argumentTypeName?.Split(',').FirstOrDefault();
                        if (argMode == EventHandlerArgumentMode.EventDefined)
                        {
                            type = eventTypeName?.Split(',').FirstOrDefault();
                        }
                        else if (argMode == EventHandlerArgumentMode.Void)
                        {
                            type = null;
                        }

                        var range = new TextRange(assetDocument.StartOffset + methodNameRange.StartOffset.Offset,
                                                  assetDocument.StartOffset + methodNameRange.EndOffset.Offset);

                        var target = fileID.ToReference(currentSourceFile);
                        if (target != null)
                        {
                            result.Add(new AssetMethodData(
                                           new LocalReference(currentSourceFile.PsiStorage.PersistentIndex, anchor), methodName,
                                           range,
                                           argMode, type, target));
                        }
                    }
                }
            }

            if (result.Count > 0)
            {
                return(new AssetMethodsDataElement(result));
            }
            return(null);
        }
Example #32
0
 public object Build(SeldomInterruptChecker checker,
                     IPsiSourceFile file,
                     AssetDocument assetDocument)
 {
     return(new AnimationExtractor(file, assetDocument).TryExtractEventUsage());
 }
Example #33
0
        public object Build(SeldomInterruptChecker checker, IPsiSourceFile currentAssetSourceFile, AssetDocument assetDocument)
        {
            var anchorRaw = AssetUtils.GetAnchorFromBuffer(assetDocument.Buffer);

            if (!anchorRaw.HasValue)
            {
                return(null);
            }

            var anchor     = anchorRaw.Value;
            var isStripped = AssetUtils.IsStripped(assetDocument.Buffer);
            var location   = new LocalReference(currentAssetSourceFile.PsiStorage.PersistentIndex.NotNull("owningPsiPersistentIndex != null"), anchor);

            if (isStripped)
            {
                var prefabInstance            = AssetUtils.GetPrefabInstance(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?;
                var correspondingSourceObject = AssetUtils.GetCorrespondingSourceObject(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?;

                if (prefabInstance != null && correspondingSourceObject != null)
                {
                    return(new StrippedHierarchyElement(location, prefabInstance.Value, correspondingSourceObject.Value));
                }

                return(null);
            }

            var gameObject = AssetUtils.GetGameObjectReference(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?;

            if (gameObject != null && AssetUtils.IsMonoBehaviourDocument(assetDocument.Buffer))
            {
                var entries = assetDocument.Document.FindRootBlockMapEntries()?.Entries;
                if (entries == null)
                {
                    return(null);
                }

                IHierarchyReference documentReference = null;

                foreach (var entry in entries)
                {
                    if (entry.Key.MatchesPlainScalarText(UnityYamlConstants.ScriptProperty))
                    {
                        documentReference = entry.Content.Value.ToHierarchyReference(currentAssetSourceFile);
                        break;
                    }
                }

                if (documentReference is ExternalReference scriptReference)
                {
                    return(new ScriptComponentHierarchy(location, gameObject.Value, scriptReference));
                }
            }
            else if (gameObject != null && AssetUtils.IsTransform(assetDocument.Buffer))
            {
                var father = AssetUtils.GetTransformFather(currentAssetSourceFile, assetDocument.Buffer) as LocalReference?;
                if (father == null)
                {
                    return(null);
                }

                var rootIndex = AssetUtils.GetRootIndex(assetDocument.Buffer);
                return(new TransformHierarchy(location, gameObject.Value, father.Value, rootIndex));
            }
            else if (AssetUtils.IsGameObject(assetDocument.Buffer))
            {
                var name = AssetUtils.GetGameObjectName(assetDocument.Buffer);
                if (name != null)
                {
                    return(new GameObjectHierarchy(location, name));
                }
            }
            else if (AssetUtils.IsPrefabModification(assetDocument.Buffer))
            {
                var modification    = AssetUtils.GetPrefabModification(assetDocument.Document);
                var parentTransform = modification?.GetValue("m_TransformParent")?.ToHierarchyReference(currentAssetSourceFile) as LocalReference? ?? LocalReference.Null;
                var modifications   = modification?.GetValue("m_Modifications") as IBlockSequenceNode;
                var result          = new List <PrefabModification>();
                if (modifications != null)
                {
                    foreach (var entry in modifications.Entries)
                    {
                        var map = entry.Value as IBlockMappingNode;

                        var target = map?.GetValue("target").ToHierarchyReference(currentAssetSourceFile);
                        if (target == null)
                        {
                            continue;
                        }

                        var name = map.GetValue("propertyPath").GetPlainScalarText();
                        if (name == null)
                        {
                            continue;
                        }

                        var valueNode = map.FindMapEntryBySimpleKey("value")?.Content;
                        if (valueNode == null)
                        {
                            continue;
                        }

                        IAssetValue value = null;
                        foreach (var assetInspectorValueDeserializer in myAssetInspectorValueDeserializers)
                        {
                            if (assetInspectorValueDeserializer.TryGetInspectorValue(currentAssetSourceFile, valueNode, out value))
                            {
                                break;
                            }
                        }

                        var objectReference = map.FindMapEntryBySimpleKey("objectReference")?.Content.Value.ToHierarchyReference(currentAssetSourceFile);

                        var valueRange = valueNode.GetTreeTextRange();

                        result.Add(new PrefabModification(target, name, value,
                                                          new TextRange(assetDocument.StartOffset + valueRange.StartOffset.Offset,
                                                                        assetDocument.StartOffset + valueRange.EndOffset.Offset), objectReference));
                    }
                }

                var sourcePrefabGuid = AssetUtils.GetSourcePrefab(currentAssetSourceFile, assetDocument.Buffer) as ExternalReference?;
                if (sourcePrefabGuid == null)
                {
                    return(null);
                }

                return(new PrefabInstanceHierarchy(location, parentTransform, result, sourcePrefabGuid.Value.ExternalAssetGuid));
            }
            else if (gameObject != null)// regular component
            {
                var name = AssetUtils.GetRawComponentName(assetDocument.Buffer);
                if (name == null)
                {
                    return(null);
                }

                return(new ComponentHierarchy(location, gameObject.Value, name));
            }
            return(null);
        }
 private NTriplesMissingTokensInserter(
     ILexer lexer, ITokenOffsetProvider offsetProvider, SeldomInterruptChecker interruptChecker, ITokenIntern intern)
     : base(offsetProvider, interruptChecker, intern)
 {
     this.myLexer = lexer;
 }