Exemple #1
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 #2
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 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 #4
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);
        }
        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);
        }
Exemple #6
0
        static TypeResolver()
        {
            FullNames.Add("string", typeof(string).FullName);
            FullNames.Add("int", typeof(int).FullName);
            FullNames.Add("void", typeof(void).FullName);
            FullNames.Add("bool", typeof(bool).FullName);
            FullNames.Add("object", typeof(object).FullName);
            FullNames.Add("float", typeof(float).FullName);
            FullNames.Add("double", typeof(double).FullName);

            // UnityEngine.Experimental.Director.Playable moved to UnityEngine.Playables in 2017.1
            // We correctly set the max version to 5.6, but if we resolve against types in a newer
            // UnityEngine.dll, we resolve PlayState incorrectly. The heuristic when we have multiple
            // candidates (such as UnityEngine.Experimental.Director.PlayState and
            // UnityEngine.Playables.PlayState) is to prefer the one in the same namespace. This
            // works nicely, so let's give an extra candidate
            FullNames.Add("FrameData", "UnityEngine.Experimental.Director.FrameData");
            FullNames.Add("PlayState", "UnityEngine.Experimental.Director.PlayState");
        }
Exemple #7
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());
            }
        }
Exemple #8
0
        private void AddToLocalCache(IPsiSourceFile sourceFile, [CanBeNull] AsmDefCacheItem asmDefCacheItem)
        {
            if (asmDefCacheItem == null)
            {
                return;
            }

            myNames.Add(asmDefCacheItem.Name, sourceFile);
            if (!myDeclaredElements.ContainsKey(sourceFile))
            {
                myDeclaredElements.Add(sourceFile, CreateDeclaredElement(sourceFile, asmDefCacheItem));
            }
        }
Exemple #9
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));
            }
        }
        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 #11
0
 private void AddScriptInfos(AnimatorScript script)
 {
     GuidToAnchors.Add(script.Guid, script.Anchor);
 }