public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module = null) { if (!element.IsFromUnityProject()) return null; var method = element as IMethod; if (method != null) { var eventFunction = myUnityApi.GetUnityEventFunction(method); if (eventFunction?.Description != null) return new RichTextBlock(eventFunction.Description); } var parameter = element as IParameter; var owner = parameter?.ContainingParametersOwner as IMethod; if (owner != null) { var eventFunction = myUnityApi.GetUnityEventFunction(owner); var eventFunctionParameter = eventFunction?.GetParameter(parameter.ShortName); if (eventFunctionParameter?.Description != null) return new RichTextBlock(eventFunctionParameter.Description); } return null; }
public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module = null) { if (!element.IsFromUnityProject()) { return(null); } var method = element as IMethod; if (method != null) { var message = myUnityApi.GetUnityMessage(method); if (message?.Description != null) { return(new RichTextBlock(message.Description)); } } var parameter = element as IParameter; var owner = parameter?.ContainingParametersOwner as IMethod; if (owner != null) { var message = myUnityApi.GetUnityMessage(owner); var messageParameter = message?.GetParameter(parameter.ShortName); if (messageParameter?.Description != null) { return(new RichTextBlock(messageParameter.Description)); } } return(null); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; if (!element.IsFromUnityProject()) { return(false); } var solution = element.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); var cls = element as IClass; if (cls != null) { if (unityApi.IsUnityType(cls)) { flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); } } var method = element as IMethod; if (method != null) { EventFunctionMatch match; var function = unityApi.GetUnityEventFunction(method, out match); if (function != null && match == EventFunctionMatch.ExactMatch) { foreach (var parameter in function.Parameters) { if (parameter.IsOptional) { // Allows optional parameters to be marked as unused // TODO: Might need to process IParameter if optional gets more complex flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); } } flags = ImplicitUseKindFlags.Access; return(true); } } var field = element as IField; if (field != null && unityApi.IsUnityField(field)) { // Public fields gets exposed to the Unity Editor and assigned from the UI. // But it still should be checked if the field is ever accessed from the code. flags = ImplicitUseKindFlags.Assign; return(true); } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return(false); }
public bool IsApplicable(IDeclaredElement declaredElement) { if (!declaredElement.IsFromUnityProject()) { return(false); } return(IsEventHandler(declaredElement)); }
public bool IsApplicable(IDeclaredElement declaredElement) { if (!declaredElement.IsFromUnityProject()) { return(false); } var unityApi = declaredElement.GetSolution().GetComponent <UnityApi>(); return(unityApi.IsSerialisedField(declaredElement as IField)); }
public override string GetEntityKind(IDeclaredElement declaredElement) { if (declaredElement.IsFromUnityProject()) { var unityApi = declaredElement.GetSolution().GetComponent <UnityApi>(); switch (declaredElement) { case IMethod method when unityApi.IsEventFunction(method): return("event function"); case IField field when unityApi.IsSerialisedField(field): return("serialised field"); } } return(base.GetEntityKind(declaredElement)); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; if (!element.IsFromUnityProject()) { return(false); } var solution = element.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); var cls = element as IClass; if (cls != null) { if (unityApi.IsUnityType(cls)) { flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); } } var method = element as IMethod; if (method != null && unityApi.IsUnityMessage(method)) { flags = ImplicitUseKindFlags.Access; return(true); } var field = element as IField; if (field != null && field.GetAccessRights() == AccessRights.PUBLIC) { var containingType = field.GetContainingType(); if (containingType != null && unityApi.IsUnityType(containingType)) { // Public fields gets exposed to the Unity Editor and assigned from the UI. But it still should be checked if the field is ever accessed from the code. flags = ImplicitUseKindFlags.Assign; return(true); } } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return(false); }
private static bool IsSerialisedField(IDeclaredElement declaredElement) { if (!(declaredElement is IField field)) { return(false); } if (!declaredElement.IsFromUnityProject()) { return(false); } var solution = declaredElement.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); return(unityApi.IsSerialisedField(field)); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; if (!element.IsFromUnityProject()) return false; var solution = element.GetSolution(); var unityApi = solution.GetComponent<UnityApi>(); var cls = element as IClass; if (cls != null) { if(unityApi.IsUnityType(cls)) { flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return true; } } var method = element as IMethod; if (method != null && unityApi.IsEventFunction(method)) { flags = ImplicitUseKindFlags.Access; return true; } var field = element as IField; if (field != null && unityApi.IsUnityField(field)) { // Public fields gets exposed to the Unity Editor and assigned from the UI. But it still should be checked if the field is ever accessed from the code. flags = ImplicitUseKindFlags.Assign; return true; } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return false; }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; if (!element.IsFromUnityProject()) { return(false); } var solution = element.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); switch (element) { case IClass cls when unityApi.IsUnityType(cls) || unityApi.IsComponentSystemType(cls) || IsUxmlFactory(cls): flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case ITypeElement typeElement when unityApi.IsSerializableTypeDeclaration(typeElement): // TODO: We should only really mark it as in use if it's actually used somewhere // That is, it should be used as a field in a Unity type, or another serializable type flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case ITypeElement typeElement when IsImplicitlyUsedInterfaceType(typeElement): flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case IMethod method: var function = unityApi.GetUnityEventFunction(method, out var match); if (function != null) { if (match == MethodSignatureMatch.ExactMatch) { flags = HasOptionalParameter(function) ? ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature : ImplicitUseKindFlags.Access; return(true); } return(false); } if (IsEventHandler(unityApi, method) || IsRequiredSignatureMethod(method) || IsAnimationEvent(solution, method) || IsImplicitlyUsedInterfaceMethod(method)) { flags = ImplicitUseKindFlags.Access; return(true); } break; case IField field when unityApi.IsSerialisedField(field): flags = ImplicitUseKindFlags.Assign; return(true); case IProperty property when IsEventHandler(unityApi, property.Setter) || IsImplicitlyUsedInterfaceProperty(property) || IsAnimationEvent(solution, property): flags = ImplicitUseKindFlags.Assign; return(true); } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return(false); }
public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module = null) { if (!element.IsFromUnityProject()) { return(null); } var method = element as IMethod; if (method != null) { var eventFunction = myUnityApi.GetUnityEventFunction(method); if (eventFunction?.Description != null) { var richTextBlock = new RichTextBlock(eventFunction.Description); if (eventFunction.Coroutine) { richTextBlock.Add("This function can be a coroutine."); } if (eventFunction.Undocumented) { richTextBlock.Add("This function is undocumented."); } return(richTextBlock); } } var parameter = element as IParameter; var owner = parameter?.ContainingParametersOwner as IMethod; if (owner != null) { EventFunctionMatch match; var eventFunction = myUnityApi.GetUnityEventFunction(owner, out match); if (eventFunction == null || (match & EventFunctionMatch.MatchingSignature) == 0) { return(null); } var eventFunctionParameter = eventFunction.GetParameter(parameter.ShortName); if (eventFunctionParameter == null) { var parameters = parameter.ContainingParametersOwner.Parameters; for (var i = 0; i < parameters.Count; i++) { if (Equals(parameters[i], parameter)) { eventFunctionParameter = eventFunction.Parameters[i]; break; } } } if (eventFunctionParameter?.Description != null) { var richTextBlock = new RichTextBlock(eventFunctionParameter.Description); if (eventFunctionParameter.IsOptional) { if (string.IsNullOrEmpty(eventFunctionParameter.Justification)) { richTextBlock.Add("This parameter is optional and can be removed if not used."); } else { richTextBlock.Add($"This parameter is optional: {eventFunctionParameter.Justification}"); } } return(richTextBlock); } } return(null); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; try { if (!element.IsFromUnityProject()) { return(false); } } catch (Exception e) { /* * TODO: radically rethink Unity / non-Unity project detection. * Currently we check project's assemblies using extensions for IProject, * with no way to log errors and/or react to targetFrameworkChanges should they happen on the fly. * This should be replaced with something more stable and fast. */ myLogger.LogExceptionSilently(e); return(false); } var solution = element.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); switch (element) { case IClass cls when unityApi.IsUnityType(cls) || unityApi.IsUnityECSType(cls): flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case ITypeElement typeElement when IsImplicitlyUsedInterfaceType(typeElement): flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case ITypeElement typeElement when unityApi.IsSerializableType(typeElement): // TODO: We should only really mark it as in use if it's actually used somewhere // That is, it should be used as a field in a Unity type, or another serializable type flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case IMethod method when IsImplicitlyUsedInterfaceMethod(method): flags = ImplicitUseKindFlags.Access; return(true); case IMethod method: var function = unityApi.GetUnityEventFunction(method, out var match); if (function != null) { if (match == MethodSignatureMatch.ExactMatch) { foreach (var parameter in function.Parameters) { if (parameter.IsOptional) { // Allows optional parameters to be marked as unused // TODO: Might need to process IParameter if optional gets more complex flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); } } flags = ImplicitUseKindFlags.Access; return(true); } return(false); } if (IsEventHandler(unityApi, method)) { flags = ImplicitUseKindFlags.Access; return(true); } if (IsSettingsProvider(method)) { flags = ImplicitUseKindFlags.Access; return(true); } break; case IField field when unityApi.IsSerialisedField(field) || unityApi.IsInjectedField(field): flags = ImplicitUseKindFlags.Assign; return(true); case IProperty property when IsEventHandler(unityApi, property.Setter) || IsImplicitlyUsedInterfaceProperty(property): flags = ImplicitUseKindFlags.Assign; return(true); } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return(false); }
public bool SuppressUsageInspectionsOnElement(IDeclaredElement element, out ImplicitUseKindFlags flags) { flags = ImplicitUseKindFlags.Default; try { if (!element.IsFromUnityProject()) { return(false); } } catch (Exception e) { /* * TODO: radically rethink Unity / non-Unity project detection. * Currently we check project's assemblies using extensions for IProject, * with no way to log errors and/or react to targetFrameworkChanges should they happen on the fly. * This should be replaced with something more stable and fast. */ myLogger.LogExceptionSilently(e); return(false); } var solution = element.GetSolution(); var unityApi = solution.GetComponent <UnityApi>(); switch (element) { case IClass cls when unityApi.IsUnityType(cls): flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); case IMethod method: var function = unityApi.GetUnityEventFunction(method, out var match); if (function != null && match == EventFunctionMatch.ExactMatch) { foreach (var parameter in function.Parameters) { if (parameter.IsOptional) { // Allows optional parameters to be marked as unused // TODO: Might need to process IParameter if optional gets more complex flags = ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature; return(true); } } flags = ImplicitUseKindFlags.Access; return(true); } break; case IField field when unityApi.IsUnityField(field): // Public fields gets exposed to the Unity Editor and assigned from the UI. // But it still should be checked if the field is ever accessed from the code. flags = ImplicitUseKindFlags.Assign; return(true); } flags = ImplicitUseKindFlags.Default; // Value not used if we return false return(false); }
public bool IsAvailable(IDeclaredElement element) { return(element.IsFromUnityProject()); }