internal override bool IsMemberAccessOnKnownType(MemberAccessExpressionSyntax memberAccess, string name, KnownType knownType, SemanticModel model) => memberAccess.IsMemberAccessOnKnownType(name, knownType, model);
private static bool TryGetFloatingPointType(ExpressionSyntax expression, SemanticModel semanticModel, out KnownType floatingPointType) { floatingPointType = null; var memberAccess = expression as MemberAccessExpressionSyntax; if (memberAccess == null) { return(false); } var fieldSymbol = semanticModel.GetSymbolInfo(memberAccess).Symbol as IFieldSymbol; if (fieldSymbol?.Name != nameof(double.NaN)) { return(false); } floatingPointType = KnownType.FloatingPointNumbers.FirstOrDefault(fieldSymbol.Type.Is); return(floatingPointType != null); }
private protected override bool IsGetTempPathAssignment(InvocationExpressionSyntax invocationExpression, KnownType type, string methodName, SemanticModel semanticModel) => invocationExpression.IsMethodInvocation(type, methodName, semanticModel) && invocationExpression.Parent.IsAnyKind(SyntaxKind.EqualsValueClause, SyntaxKind.SimpleAssignmentExpression, SyntaxKind.ArrowExpressionClause, SyntaxKind.ReturnStatement);
public static SyntaxKind ToTypeKeyword(this KnownType knownType) => knownType switch {
internal static bool IsMemberAccessOnKnownType(this InvocationExpressionSyntax invocation, string identifierName, KnownType knownType, SemanticModel semanticModel) => invocation.Expression is MemberAccessExpressionSyntax memberAccess &&
internal static IEnumerable <ISymbol> GetSymbolsOfKnownType(this SeparatedSyntaxList <ArgumentSyntax> syntaxList, KnownType knownType, SemanticModel semanticModel) => syntaxList.GetArgumentsOfKnownType(knownType, semanticModel) .Select(argument => semanticModel.GetSymbolInfo(argument.GetExpression()).Symbol);
public static IEnumerable <ArgumentSyntax> GetArgumentsOfKnownType(this ObjectCreationExpressionSyntax objectCreation, KnownType knownType, SemanticModel semanticModel) => objectCreation?.ArgumentList?.Arguments.GetArgumentsOfKnownType(knownType, semanticModel) ?? Enumerable.Empty <ArgumentSyntax>();
private static bool HasAttribute(ISymbol symbol, KnownType attribute) { return(symbol != null && symbol.GetAttributes().Any(a => a.AttributeClass.Is(attribute))); }
internal MethodSignature(KnownType containingType, string name) { ContainingType = containingType; Name = name; }
public static bool IsMemberAccessOnKnownType(this MemberAccessExpressionSyntax memberAccess, string name, KnownType knownType, SemanticModel semanticModel) => memberAccess.NameIs(name) && semanticModel.GetSymbolInfo(memberAccess).Symbol is {
public static bool IsKnownType(this ObjectCreationExpressionSyntax objectCreation, KnownType knownType, SemanticModel semanticModel) => objectCreation.Type.GetName().EndsWith(knownType.ShortName) && SymbolHelper.IsKnownType(objectCreation, knownType, semanticModel);
// private constructor for specifying also the known matrix type private ColorMatrix(KnownType knownType, object knownParam, double[,] matrix) { _knownType = knownType; _knownParam = knownParam; _cells = matrix; }
// converts a matrix to a known type private static ColorMatrix _cast(ColorMatrix matrix, KnownType knownType, object knownParam) { matrix._knownType = knownType; matrix._knownParam = knownParam; return matrix; }
/// <summary> /// Creates a known type registration for the specified type. /// </summary> /// <param name="type">The type for which to create a registration.</param> /// <param name="attr">The attribute that marks the type as a known type.</param> /// <returns>The <see cref="KnownType"/> registration that was created.</returns> private KnownType CreateKnownTypeRegistration(Type type, UvmlKnownTypeAttribute attr) { var registration = new KnownType(attr.Name ?? type.Name, type); return(registration); }
public DataType FindByKnownType(KnownType type) { return(FindByExternalTypeName(_knownTypeData[type].ExternalTypeName)); }
public static bool IsMethodInvocation(this InvocationExpressionSyntax expression, KnownType type, string methodName, SemanticModel semanticModel) => semanticModel.GetSymbolInfo(expression).Symbol is IMethodSymbol methodSymbol &&
private protected abstract bool IsInsecureEnvironmentVariableRetrieval(TInvocationExpression invocation, KnownType type, string methodName, SemanticModel semanticModel);
public void Db4oTypeIsNotBusinessType() { var theType = KnownType.Create(typeof(ActivatableList <string>)); Assert.IsFalse(theType.IsBusinessEntity); }
private static IEnumerable <ArgumentSyntax> GetArgumentsOfKnownType(this SeparatedSyntaxList <ArgumentSyntax> syntaxList, KnownType knownType, SemanticModel semanticModel) => syntaxList.Where(argument => semanticModel.GetTypeInfo(argument.GetExpression()).Type.Is(knownType));
public void KnownTypeIsBusinessType() { var theType = KnownType.Create(typeof(ClassWithFields)); Assert.IsTrue(theType.IsBusinessEntity); }
internal abstract bool IsMemberAccessOnKnownType(TMemberAccessSyntax memberAccess, string name, KnownType knownType, SemanticModel model);
public void KnownTypeReturnsPropertyFields() { var theType = KnownType.Create(typeof(ClassWithProperty)); Assert.AreEqual(1, theType.Fields.Count()); }
public override void OnInspectorGUI() { if (!Initialize()) { return; } InspectorUtils.DrawDefaultScriptField(serializedObject); GUILayout.Label("Description", EditorStyles.boldLabel); EditorGUILayout.TextArea(Node.Description, EditorStyles.wordWrappedLabel); EditorGUILayout.Space(); GUILayout.Label("Settings", EditorStyles.boldLabel); InspectorUtils.DrawDefaultInspectorWithoutScriptField(serializedObject); EditorGUILayout.Space(); GUILayout.Label("Parameters", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); EditorGUIUtility.labelWidth -= FieldLeftShift; var requiredParameters = Node.GetType().GetProperties().Where(p => System.Attribute.IsDefined(p, typeof(Blackboard.Required))); foreach (PropertyInfo propertyInfo in requiredParameters) { if (!propertyInfo.CanRead || !propertyInfo.CanWrite) { EditorGUILayout.HelpBox(string.Format("Property '{0}' must be both readable and writable", propertyInfo.Name), MessageType.Error); continue; } var typename = KnownType.GetDisplayedName(propertyInfo.PropertyType); if (typename == null) { EditorGUILayout.HelpBox(string.Format("Type {0} is not a known type!", propertyInfo.PropertyType), MessageType.Error); continue; } var matchingParameters = Parameters.Where(p => p.GetHoldType().Type == propertyInfo.PropertyType).ToList(); int oldIndex = -1;//Node.GetGenericParameterIndex(propertyInfo.Name, propertyInfo.PropertyType, matchingParameters); bool wasConstant = Node.IsGenericParameterConstant(propertyInfo.Name); BeginPanelBackground(wasConstant, oldIndex == -1); { GUILayout.BeginHorizontal(); { DrawLabel(propertyInfo.Name); var fieldRect = EditorGUILayout.GetControlRect(true, LockSize, SpaceEditorStyles.LightObjectField); var lockRect = new Rect(fieldRect.x + fieldRect.width - LockSize, fieldRect.y + 2, LockSize, fieldRect.height); bool isConstant = EditorGUI.Toggle(lockRect, wasConstant, SpaceEditorStyles.LockButton); fieldRect.width -= LockSize; if (isConstant) { // Variant parameter = wasConstant // ? Node.ParametrizedProperties[propertyInfo.Name].Parameter // : new Variant(propertyInfo.PropertyType); // // VariantUtils.DrawParameter(fieldRect, parameter, false); // // Node.SetRequiredParameter(propertyInfo.Name, parameter, true); } else { fieldRect.y += 2; /*var paramListContent = BuildParameterGUIList(typename, matchingParameters); * int newIndex = EditorGUI.Popup(fieldRect, GUIContent.none, oldIndex + 1, paramListContent.ToArray(), SpaceEditorStyles.LightObjectField); * * if (!Editor.ExecuteInRuntime() && (oldIndex != (newIndex - 1) || (isConstant != wasConstant))) * { * ProcessSelectionResult(newIndex, propertyInfo, matchingParameters); * }*/ } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); } }
public void NameOfGenericInstance() { var listType = KnownType.Create(typeof(List <>), new[] { KnownType.String }); Assert.IsTrue(listType.TypeName.FullName.StartsWith("System.Collections.Generic.List`1[")); }
internal static IEnumerable <ISymbol> GetArgumentSymbolsOfKnownType(this InvocationExpressionSyntax invocation, KnownType knownType, SemanticModel semanticModel) => invocation.ArgumentList.Arguments.GetSymbolsOfKnownType(knownType, semanticModel);
public void NestedClassesAreUnderlined() { var listType = KnownType.Create(typeof(ClassWithProperty.NestedClass)); Assert.IsTrue(listType.TypeName.NameWithGenerics.EndsWith("ClassWithProperty_NestedClass")); }
internal Condition MethodReturnTypeIs(KnownType returnType) => context => context.MethodSymbol.Value != null && context.MethodSymbol.Value.ReturnType.DerivesFrom(returnType);
bool Initialize(ref Rect position, ref bool displayLock, SerializedProperty property, Framework.Parameter asGeneric) { Type targetType = property.serializedObject.targetObject.GetType(); SerializedType isTypeRestricted = null; var path = property.GetPath(); FieldInfo paramFieldInfo = path.MaterializeToFieldInfo(targetType); var typeAttribute = paramFieldInfo.GetCustomAttribute <TypeRestricted>(); if (typeAttribute != null) { switch (typeAttribute.Source) { case TypeRestricted.TypeSource.Value: { isTypeRestricted = new SerializedType(typeAttribute.Type); break; } case TypeRestricted.TypeSource.Field: { var field = targetType.GetField(typeAttribute.SourceValue); if (field != null) { var typeValue = field.GetValue(property.serializedObject.targetObject); switch (typeValue) { case SerializedType asSerialized: { isTypeRestricted = asSerialized; break; } case Type asSystem: { isTypeRestricted = new SerializedType(asSystem); break; } } break; } return(false); } default: return(false); } } View.Target = property.serializedObject.targetObject; View.AsParametrized = View.Target as IBaseObject; View.DataProvider = View.AsParametrized?.GetProvider(); if (isTypeRestricted != null && isTypeRestricted.Type != null) { displayLock = true; View.Parameters = View.DataProvider.GetParameters(t => { if (string.IsNullOrEmpty(isTypeRestricted.Metadata)) { return(isTypeRestricted.Type.IsAssignableFrom(t.GetHoldType().Type)); } else { return(isTypeRestricted.Equals(t.GetHoldType())); } }); View.Typename = KnownType.GetDisplayedName(isTypeRestricted.Type); } else { displayLock = false; View.Parameters = View.DataProvider.GetParameters(); View.Typename = "Parameter"; } if (asGeneric.GetHoldType() != isTypeRestricted) { asGeneric.Value.HoldType = isTypeRestricted; } if (View.Typename == null) { EditorGUI.HelpBox(position, string.Format("Type {0} is not a known type!", fieldInfo.FieldType), MessageType.Error); return(false); } if (!View.DataProvider.HasObject(View.Target)) { EditorGUI.HelpBox(position, "Unable to edit this object!", MessageType.Error); return(false); } if (View.DataProvider == null) { EditorGUI.HelpBox(position, $"{property.name}: Unable to get instance of IDataSetProvider!", MessageType.Error); return(false); } return(true); }
private protected override bool IsInsecureEnvironmentVariableRetrieval(InvocationExpressionSyntax invocation, KnownType type, string methodName, SemanticModel semanticModel) => invocation.IsMethodInvocation(type, methodName, semanticModel) && invocation.ArgumentList?.Arguments.FirstOrDefault() is {
private protected abstract bool IsGetTempPathAssignment(TInvocationExpression invocationExpression, KnownType type, string methodName, SemanticModel semanticModel);
public Argument(string type, KnownType knownType, string name) { Type = type; KnownType = knownType; Name = name; }
private static string GetShortNameWithoutAttributeSuffix(KnownType knownType) => knownType.ShortName == nameof(Attribute) || !knownType.ShortName.EndsWith(nameof(Attribute)) ? knownType.ShortName : knownType.ShortName.Remove(knownType.ShortName.Length - AttributeLength);