public bool GetElementsNames(LocalReference location, [NotNull] IDeclaredElement declaredElement, [CanBeNull] out string[] names, out bool isStateMachine) { AssertShellLocks(); var element = GetDataElement(location); if (element is null) { names = null; isStateMachine = false; return(false); } var namesConsumer = new PathConsumer <string>(usage => usage.Name); var anchor = location.LocalDocumentAnchor; var namesAndAnchors = namesConsumer.Elements; AddBottomElement(element, namesConsumer, anchor, declaredElement, out isStateMachine); ProcessPath(element, namesConsumer, anchor); namesAndAnchors.Reverse(); names = namesAndAnchors.ToArray(); return(true); }
/** * Copies {@code sourceFiles} to the {@code destDir} directory. * * @param sourceFiles the list of source files. * @param destDir the directory to copy the files to. * @throws IOException if the copy fails. */ public static void Copy(ImmutableArray <SystemPath> sourceFiles, SystemPath destDir) { foreach (SystemPath sourceFile in sourceFiles) { PathConsumer copyPathConsumer = path => { // Creates the same path in the destDir. SystemPath destPath = destDir.Resolve(sourceFile.GetParent().Relativize(path)); if (Files.IsDirectory(path)) { Files.CreateDirectories(destPath); } else { Files.Copy(path, destPath); } }; if (Files.IsDirectory(sourceFile)) { new DirectoryWalker(sourceFile).Walk(copyPathConsumer); } else { copyPathConsumer.Accept(sourceFile); } } }
/** * Walks {@link #rootDir} and applies {@code pathConsumer} to each file. Note that {@link * #rootDir} itself is visited as well. * * @param pathConsumer the consumer that is applied to each file. * @return a list of Paths that were walked. * @throws IOException if the walk fails. */ public ImmutableArray <SystemPath> Walk(PathConsumer pathConsumer) { ImmutableArray <SystemPath> files = Walk(); foreach (SystemPath path in files) { pathConsumer.Accept(path); } return(files); }
private static bool TryAddBottomStateMachine([NotNull] AnimatorUsagesDataElement element, [NotNull] PathConsumer <string> namesConsumer, long anchor) { if (!element.StateMachineAnchorToUsage.TryGetValue(anchor, out var bottomElement) || bottomElement is null) { return(false); } namesConsumer.Elements.Add(bottomElement.Name); return(true); }
private static void ProcessPath <T>([NotNull] AnimatorUsagesDataElement element, [NotNull] PathConsumer <T> consumer, long currentAnchor) { var childToParent = element.ChildToParent; var anchorToStateMachineUsage = element.StateMachineAnchorToUsage; while (childToParent.TryGetValue(currentAnchor, out var parent) && anchorToStateMachineUsage.TryGetValue(parent, out var usage) && usage != null) { consumer.Consume(usage); currentAnchor = parent; } }
private void AddBottomElement([NotNull] AnimatorUsagesDataElement element, [NotNull] PathConsumer <string> namesConsumer, long anchor, [NotNull] IDeclaredElement declaredElement, out bool isStateMachine) { if (TryAddBottomStateMachine(element, namesConsumer, anchor)) { isStateMachine = true; return; } isStateMachine = false; AddBottomStateElement(element, namesConsumer, anchor, declaredElement); }
public string GetStateMachinePathFor(LocalReference location) { AssertShellLocks(); var element = GetDataElement(location); if (element is null) { return(null); } var namesConsumer = new PathConsumer <string>(usage => usage.Name); ProcessPath(element, namesConsumer, location.LocalDocumentAnchor); var names = namesConsumer.Elements; names.Reverse(); return(names.Join("/")); }
private void AddBottomStateElement([NotNull] AnimatorUsagesDataElement element, [NotNull] PathConsumer <string> namesConsumer, long anchor, [NotNull] IDeclaredElement declaredElement) { if (!(declaredElement is ITypeElement typeElement)) { return; } var boxedGuid = AssetUtils.GetGuidFor(myMetaFileGuidCache, typeElement); if (!boxedGuid.HasValue) { return; } var name = GetUsages(element, boxedGuid.Value, element.ScriptAnchorToStateUsages) .Where(usage => usage.Location.LocalDocumentAnchor == anchor) .Select(usage => usage.Name) .FirstOrDefault(); namesConsumer.Elements.Add(name); }
public void SetUp() { testDir = Paths.Get(TestResources.GetResource("core/layer").ToURI()); walkedPaths = new HashSet <SystemPath>(); addToWalkedPaths = p => walkedPaths.Add(p); }
public static void Accept(this PathConsumer c, SystemPath path) { c = c ?? throw new ArgumentNullException(nameof(c)); c(path); }