protected override void Analyze(IPropertiesValue element, ElementProblemAnalyzerData data, IHighlightingConsumer consumer)
        {
            var propertiesByName = new OneToListMap <string, IPropertyDeclaration>();

            foreach (var propertyDeclaration in element.DeclarationsEnumerable)
            {
                var propertyName = propertyDeclaration.Name?.GetText();
                if (string.IsNullOrEmpty(propertyName))
                {
                    continue;
                }

                propertiesByName.AddValue(propertyName, propertyDeclaration);
            }

            foreach (var pair in propertiesByName)
            {
                if (pair.Value.Count > 1)
                {
                    var propertyDeclaration = pair.Value[0];
                    consumer.AddHighlighting(new ShaderLabFirstDuplicatePropertyWarning(propertyDeclaration, pair.Key,
                                                                                        propertyDeclaration.Name.GetHighlightingRange()));
                    for (var i = 1; i < pair.Value.Count; i++)
                    {
                        propertyDeclaration = pair.Value[i];
                        consumer.AddHighlighting(new ShaderLabSubsequentDuplicatePropertyWarning(propertyDeclaration,
                                                                                                 pair.Key, propertyDeclaration.Name.GetHighlightingRange()));
                    }
                }
            }
        }
Exemple #2
0
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element         = unityAssetDataElement as AssetInspectorValuesDataElement;
            var inspectorUsages = new OneToListMap <string, InspectorVariableUsage>();

            foreach (var variableUsage in element.VariableUsages)
            {
                var guid = (variableUsage.ScriptReference as ExternalReference)?.ExternalAssetGuid;
                if (guid == null)
                {
                    continue;
                }

                myNameToSourceFile.Add(variableUsage.Name, sourceFile);

                var mbField = new MonoBehaviourField(guid, variableUsage.Name);
                myUniqueValuesCount.Add(mbField, variableUsage.Value);
                AddUniqueValue(mbField, variableUsage);
                myChangesInFiles.Add(mbField, sourceFile);
                AddChangesPerFile(new MonoBehaviourField(guid, variableUsage.Name, sourceFile), variableUsage);

                inspectorUsages.Add(variableUsage.Name, variableUsage);

                if (variableUsage.ScriptReference is ExternalReference externalReference)
                {
                    myNameToGuids.Add(variableUsage.Name, externalReference.ExternalAssetGuid);
                }
            }

            myPsiSourceFileToInspectorValues.Add(sourceFile, inspectorUsages);
        }
Exemple #3
0
 private UnitySceneData(OneToListMap <MonoBehaviourProperty, MonoBehaviourPropertyValue> propertiesData, OneToSetMap <string, FileID> eventHandlers, OneToSetMap <string, string> scriptMapping, SceneHierarchy sceneHierarchy)
 {
     PropertiesData          = propertiesData;
     SceneHierarchy          = sceneHierarchy;
     ShortNameToScriptFileId = eventHandlers;
     ScriptMapping           = scriptMapping;
 }
Exemple #4
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;
        }
        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>();
        }
        private IEnumerable <KeyValuePair <string, IList <DeclaredElementInstance <IMethod> > > > GetTaskMethods(ISymbolScope symbolScope)
        {
            var map = new OneToListMap <string, DeclaredElementInstance <IMethod> >();

            foreach (var shortName in symbolScope.GetAllShortNames())
            {
                if (!shortName.EndsWith("Tasks"))
                {
                    continue;
                }
                var symbols = symbolScope.GetElementsByShortName(shortName);

                foreach (var symbol in symbols)
                {
                    if (!(symbol is IClass @class))
                    {
                        continue;
                    }
                    if ([email protected]().QualifiedName.StartsWith("Nuke"))
                    {
                        continue;
                    }

                    foreach (var classMethod in @class.Methods
                             .Where(x => x.AccessibilityDomain.DomainType == AccessibilityDomain.AccessibilityDomainType.PUBLIC && x.IsStatic))
                    {
                        map.Add(classMethod.ShortName, new DeclaredElementInstance <IMethod>(classMethod));
                    }
                }
            }

            return(map);
        }
        public void Merge(IPsiSourceFile sourceFile, AssetDocumentHierarchyElement assetDocumentHierarchyElement, IUnityAssetDataElement unityAssetDataElement)
        {
            var element      = (unityAssetDataElement as AssetMethodsDataElement).NotNull("element != null");
            var groupMethods = new OneToListMap <string, AssetMethodData>();

            foreach (var method in element.Methods)
            {
                myShortNameToScriptTarget.Add(method.MethodName, method);
                groupMethods.Add(method.MethodName, method);

                if (method.TargetScriptReference is ExternalReference)
                {
                    myExternalCount.Add(method.MethodName);
                }
                else if (method.TargetScriptReference is LocalReference localReference)
                {
                    if (assetDocumentHierarchyElement.GetHierarchyElement(null, localReference.LocalDocumentAnchor, null) is IScriptComponentHierarchy script)
                    {
                        if (script.IsStripped)
                        {
                            myExternalCount.Add(method.MethodName);
                        }
                        else
                        {
                            myLocalUsages.Add(method.MethodName, new AssetMethodData(LocalReference.Null,
                                                                                     method.MethodName, TextRange.InvalidRange,
                                                                                     method.Mode, method.Type, script.ScriptReference));
                        }
                    }
                }
            }

            myPsiSourceFileToMethods.Add(sourceFile, groupMethods);
        }
Exemple #8
0
 public AnimatorUsagesDataElement()
 {
     GuidToAnchors                    = new OneToListMap <Guid, long>();
     ScriptAnchorToStateUsages        = new OneToListMap <long, AnimatorStateScriptUsage>();
     ScriptAnchorToStateMachineUsages = new OneToListMap <long, AnimatorStateMachineScriptUsage>();
     StateMachineAnchorToUsage        = new Dictionary <long, AnimatorStateMachineScriptUsage>();
     ChildToParent                    = new Dictionary <long, long>();
     StateNames = new List <string>();
 }
Exemple #9
0
        private static OneToListMap <Guid, long> ReadGuidToAnchorsMap([NotNull] UnsafeReader reader)
        {
            var guidToAnchorsCount = reader.ReadInt32();
            var anchorToUsages     = new OneToListMap <Guid, long>(guidToAnchorsCount);

            for (var i = 0; i < guidToAnchorsCount; i++)
            {
                ReadGuidToAnchors(reader, anchorToUsages);
            }
            return(anchorToUsages);
        }
Exemple #10
0
        private static void ReadGuidToAnchors([NotNull] UnsafeReader reader,
                                              [NotNull] OneToListMap <Guid, long> guidToAnchors)
        {
            var guid        = reader.ReadGuid();
            var usagesCount = reader.ReadInt32();

            for (var i = 0; i < usagesCount; i++)
            {
                guidToAnchors.Add(guid, reader.ReadLong());
            }
        }
        private static IEnumerable <T> GetUsages <T>(
            [NotNull] AnimatorUsagesDataElement element,
            Guid boxedGuid,
            [NotNull] OneToListMap <long, T> d) where T : IScriptUsage
        {
            var stateUsages = new List <T>();

            foreach (var scriptAnchor in element.GuidToAnchors.GetValuesSafe(boxedGuid))
            {
                stateUsages.AddRange(d.GetValuesSafe(scriptAnchor));
            }
            return(stateUsages);
        }
Exemple #12
0
        private static OneToListMap <long, T> ReadAnchorToUsagesMap <T>([NotNull] UnsafeReader reader,
                                                                        [NotNull] Func <UnsafeReader, T> read)
            where T : IAnimatorScriptUsage
        {
            var anchorToUsagesCount = reader.ReadInt32();
            var anchorToUsages      = new OneToListMap <long, T>(anchorToUsagesCount);

            for (var i = 0; i < anchorToUsagesCount; i++)
            {
                ReadAnchorToUsagesEntry(reader, anchorToUsages, read);
            }
            return(anchorToUsages);
        }
Exemple #13
0
        private static void ReadAnchorToUsagesEntry <T>([NotNull] UnsafeReader reader,
                                                        [NotNull] OneToListMap <long, T> anchorToUsages,
                                                        [NotNull] Func <UnsafeReader, T> read)
            where T : IAnimatorScriptUsage
        {
            var anchor      = reader.ReadLong();
            var usagesCount = reader.ReadInt32();

            for (var i = 0; i < usagesCount; i++)
            {
                anchorToUsages.Add(anchor, read(reader));
            }
        }
Exemple #14
0
 private static void WriteGuidToAnchorsMap([NotNull] UnsafeWriter writer,
                                           [NotNull] OneToListMap <Guid, long> guidToAnchors)
 {
     writer.Write(guidToAnchors.Count);
     foreach (var(guid, anchors) in guidToAnchors)
     {
         if (anchors is null)
         {
             continue;
         }
         WriteGuidToAnchorsEntry(writer, guid, anchors);
     }
 }
Exemple #15
0
 private static void WriteAnchorToUsagesMap <T>([NotNull] UnsafeWriter writer,
                                                [NotNull] OneToListMap <long, T> anchorToUsages)
     where T : IAnimatorScriptUsage
 {
     writer.Write(anchorToUsages.Count);
     foreach (var(anchor, usages) in anchorToUsages)
     {
         if (usages is null)
         {
             continue;
         }
         WriteAnchorToUsagesEntry(writer, anchor, usages);
     }
 }
Exemple #16
0
        private static void FillProperties(Dictionary <string, string> simpleValues, Dictionary <string, FileID> referenceValues,
                                           OneToListMap <MonoBehaviourProperty, MonoBehaviourPropertyValue> result)
        {
            var anchor = simpleValues.GetValueSafe("&anchor");

            if (anchor == null)
            {
                return;
            }

            var guid = referenceValues.GetValueSafe(UnityYamlConstants.ScriptProperty)?.guid;

            if (guid == null)
            {
                return;
            }

            var gameObject = referenceValues.GetValueSafe(UnityYamlConstants.GameObjectProperty)?.fileID;

            if (gameObject == null)
            {
                return;
            }

            foreach (var(fieldName, value) in simpleValues)
            {
                if (ourIgnoredMonoBehaviourEntries.Contains(fieldName))
                {
                    continue;
                }

                var property      = new MonoBehaviourProperty(guid, fieldName);
                var propertyValue = new MonoBehaviourPrimitiveValue(value, anchor, gameObject);
                result.Add(property, propertyValue);
            }

            foreach (var(fieldName, value) in referenceValues)
            {
                if (ourIgnoredMonoBehaviourEntries.Contains(fieldName))
                {
                    continue;
                }

                var property      = new MonoBehaviourProperty(guid, fieldName);
                var propertyValue = new MonoBehaviourReferenceValue(value, anchor, gameObject);
                result.Add(property, propertyValue);
            }
        }
Exemple #17
0
 private AnimatorUsagesDataElement([NotNull] OneToListMap <Guid, long> guidToAnchors,
                                   [NotNull]
                                   OneToListMap <long, AnimatorStateScriptUsage> scriptAnchorToStateUsages,
                                   [NotNull] OneToListMap <long, AnimatorStateMachineScriptUsage>
                                   scriptAnchorToStateMachineUsages,
                                   [NotNull]
                                   IDictionary <long, AnimatorStateMachineScriptUsage> stateMachineAnchorToUsage,
                                   [NotNull] IDictionary <long, long> childToParent,
                                   [NotNull] ICollection <string> stateNames)
 {
     GuidToAnchors                    = guidToAnchors;
     ScriptAnchorToStateUsages        = scriptAnchorToStateUsages;
     ScriptAnchorToStateMachineUsages = scriptAnchorToStateMachineUsages;
     StateMachineAnchorToUsage        = stateMachineAnchorToUsage;
     ChildToParent                    = childToParent;
     StateNames = stateNames;
 }
Exemple #18
0
        private static List <IMetadataMethod> GetAllTestMethods(IMetadataTypeInfo typeInfo)
        {
            var list = new List <IMetadataMethod>();
            var map  = new OneToListMap <string, IMetadataMethod>();

            while (typeInfo != null)
            {
                foreach (IMetadataMethod method in typeInfo.GetMethods())
                {
                    if (!IsTestMethod(method))
                    {
                        continue;
                    }

                    if (map.ContainsKey(method.Name) && (method.IsVirtual))
                    {
                        bool hasOverride = false;
                        foreach (IMetadataMethod metadataMethod in map[method.Name])
                        {
                            if (metadataMethod.IsVirtual && !metadataMethod.IsNewSlot)
                            {
                                hasOverride = true;
                            }
                        }

                        if (hasOverride)
                        {
                            continue;
                        }
                    }

                    map.AddValue(method.Name, method);
                    list.Add(method);
                }

                IMetadataClassType baseType = typeInfo.Base;
                typeInfo = (baseType != null) ? baseType.Type : null;
            }

            return(list);
        }
Exemple #19
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));
        }
        protected override void Analyze(IMemberOwnerDeclaration element, ElementProblemAnalyzerData data,
                                        IHighlightingConsumer consumer)
        {
            var typeElement = element.DeclaredElement;

            if (typeElement == null)
            {
                return;
            }

            if (!Api.IsUnityType(typeElement))
            {
                return;
            }

            var map = new OneToListMap <UnityEventFunction, Candidate>(new UnityEventFunctionKeyComparer());

            foreach (var member in typeElement.GetMembers())
            {
                if (member is IMethod method)
                {
                    var unityEventFunction = Api.GetUnityEventFunction(method, out var match);
                    if (unityEventFunction != null)
                    {
                        map.Add(unityEventFunction, new Candidate(method, match));
                    }
                }
            }

            foreach (var pair in map)
            {
                var function   = pair.Key;
                var candidates = pair.Value;
                if (candidates.Count == 1)
                {
                    // Only one function, mark it as a unity function, even if it's not an exact match
                    // We'll let other inspections handle invalid signatures. Add inspections
                    var method = candidates[0].Method;
                    AddGutterMark(consumer, method, function);
                    AddMethodSignatureInspections(consumer, method, function, candidates[0].Match);
                }
                else
                {
                    var hasExactMatch = false;

                    // All exact matches should be marked as an event function
                    var duplicates = new FrugalLocalList <IMethod>();
                    foreach (var candidate in candidates)
                    {
                        if (candidate.Match == EventFunctionMatch.ExactMatch)
                        {
                            AddGutterMark(consumer, candidate.Method, function);
                            hasExactMatch = true;
                            duplicates.Add(candidate.Method);
                        }
                    }

                    // Multiple exact matches should be marked as duplicate/ambiguous
                    if (duplicates.Count > 1)
                    {
                        foreach (var method in duplicates)
                        {
                            foreach (var declaration in method.GetDeclarations())
                            {
                                consumer.AddHighlighting(
                                    new DuplicateEventFunctionWarning((IMethodDeclaration)declaration));
                            }
                        }
                    }

                    // If there are no exact matches, mark all as unity functions, with inspections
                    // to fix up signature errors
                    if (!hasExactMatch)
                    {
                        foreach (var candidate in candidates)
                        {
                            var method = candidate.Method;
                            AddGutterMark(consumer, method, function);
                            AddMethodSignatureInspections(consumer, method, function, candidate.Match);
                        }
                    }
                }
            }
        }
Exemple #21
0
 private UnitySceneData(OneToListMap <MonoBehaviourProperty, MonoBehaviourPropertyValue> propertiesData, SceneHierarchy sceneHierarchy)
 {
     PropertiesData = propertiesData;
     SceneHierarchy = sceneHierarchy;
 }