-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1982 from JetBrains/net211-yarkov-support-find-us…
…ages-and-completion-for-animator Support find usages and completion for animator
- Loading branch information
Showing
137 changed files
with
28,968 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
resharper/resharper-unity/src/CSharp/Daemon/Stages/Analysis/PlayAnimatorStateAnalyzer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Linq; | ||
using JetBrains.Annotations; | ||
using JetBrains.DataFlow; | ||
using JetBrains.ProjectModel; | ||
using JetBrains.ReSharper.Feature.Services.Daemon; | ||
using JetBrains.ReSharper.Plugins.Unity.CSharp.Daemon.Errors; | ||
using JetBrains.ReSharper.Plugins.Unity.Yaml; | ||
using JetBrains.ReSharper.Plugins.Unity.Yaml.Psi.DeferredCaches.AnimatorUsages; | ||
using JetBrains.ReSharper.Plugins.Yaml.Settings; | ||
using JetBrains.ReSharper.Psi.CSharp.Tree; | ||
using JetBrains.ReSharper.Psi.Tree; | ||
|
||
namespace JetBrains.ReSharper.Plugins.Unity.CSharp.Daemon.Stages.Analysis | ||
{ | ||
[ElementProblemAnalyzer(typeof(IInvocationExpression), | ||
HighlightingTypes = new[] {typeof(UnknownAnimatorStateNameWarning)})] | ||
public class PlayAnimatorStateAnalyzer : UnityElementProblemAnalyzer<IInvocationExpression> | ||
{ | ||
[NotNull] private readonly AssetSerializationMode myAssetSerializationMode; | ||
[NotNull] private readonly YamlSupport myUnityYamlSupport; | ||
|
||
public PlayAnimatorStateAnalyzer([NotNull] UnityApi unityApi, | ||
[NotNull] AssetSerializationMode assetSerializationMode, | ||
[NotNull] YamlSupport unityYamlSupport) | ||
: base(unityApi) | ||
{ | ||
myAssetSerializationMode = assetSerializationMode; | ||
myUnityYamlSupport = unityYamlSupport; | ||
} | ||
|
||
protected override void Analyze([NotNull] IInvocationExpression invocation, | ||
ElementProblemAnalyzerData data, | ||
[NotNull] IHighlightingConsumer consumer) | ||
{ | ||
if (!myAssetSerializationMode.IsForceText || !myUnityYamlSupport.IsParsingEnabled.Value) return; | ||
var argument = GetStateNameArgumentFrom(invocation); | ||
if (!(argument?.Value is ICSharpLiteralExpression literal) || | ||
!invocation.InvocationExpressionReference.IsAnimatorPlayMethod()) return; | ||
var container = invocation.GetSolution().TryGetComponent<AnimatorScriptUsagesElementContainer>(); | ||
if (container == null || | ||
!(literal.ConstantValue.Value is string stateName) || | ||
container.ContainsStateName(stateName)) return; | ||
consumer.AddHighlighting(new UnknownAnimatorStateNameWarning(argument)); | ||
} | ||
|
||
[CanBeNull] | ||
private static ICSharpArgument GetStateNameArgumentFrom([NotNull] IInvocationExpression invocationExpression) | ||
{ | ||
return invocationExpression | ||
.ArgumentList? | ||
.Arguments | ||
.FirstOrDefault(t => | ||
t != null && | ||
(t.IsNamedArgument && t.ArgumentName?.Equals("stateName") == true || !t.IsNamedArgument)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.