Example #1
0
        static bool IsUsedAsTypeArgument(TypeDefinitionBase typeArgument, ConstructedTypeDefinition constructedType)
        {
            var arguments = constructedType.typeArguments;

            if (arguments == null)
            {
                return(false);
            }

            for (int i = arguments.Length; i-- > 0;)
            {
                var argRef = arguments[i];
                if (argRef == null)
                {
                    continue;
                }
                var arg = argRef.definition;
                if (arg == null)
                {
                    continue;
                }

                if (arg.GetGenericSymbol() == typeArgument)
                {
                    return(true);
                }

                var constructedArg = arg as ConstructedTypeDefinition;
                if (constructedArg != null && IsUsedAsTypeArgument(typeArgument, constructedArg))
                {
                    return(true);
                }
            }
            return(false);
        }
Example #2
0
    public static FGTooltip Create(FGTextEditor editor, Rect tokenRect, ParseTree.Leaf leaf, bool horizontal = false, bool showError = true)
    {
        string tooltipText      = null;
        var    symbolDefinition = leaf.resolvedSymbol;

        SymbolDefinition[] overloads = null;
        int currentOverload          = 0;

        if (symbolDefinition != null)
        {
            try
            {
                //Debug.Log("Creating tooltip: " + symbolDefinition.GetTooltipText());

                ConstructedTypeDefinition constructedType = symbolDefinition.parentSymbol as ConstructedTypeDefinition;

                if (symbolDefinition.kind == SymbolKind.MethodGroup)
                {
                    var group = symbolDefinition as MethodGroupDefinition;
                    if (group == null)
                    {
                        var constructedGroup = symbolDefinition as ConstructedSymbolReference;
                        if (constructedGroup != null)
                        {
                            var genericGroup = constructedGroup.referencedSymbol as MethodGroupDefinition;
                            if (constructedType != null)
                            {
                                symbolDefinition = constructedType.GetConstructedMember(genericGroup.methods.FirstOrDefault());
                            }
                        }
                    }
                    if (group != null && group.methods != null)
                    {
                        symbolDefinition = group.methods.FirstOrDefault() ?? symbolDefinition;
                    }
                    //else
                    //	Debug.Log("Can't convert to MethodGroupDefinition. " + symbolDefinition.GetTooltipText());
                }

                tooltipText = GetTooltipText(symbolDefinition, leaf);
                //tooltipText += symbolDefinition.IsValid();

                var methodGroup = symbolDefinition;
                if (methodGroup.parentSymbol != null)
                {
                    if (methodGroup.parentSymbol.kind == SymbolKind.MethodGroup)
                    {
                        var constructedMethodGroup = methodGroup.parentSymbol as ConstructedMethodGroupDefinition;
                        methodGroup = constructedMethodGroup ?? methodGroup.parentSymbol;
                    }
                    else
                    {
                        if (constructedType != null)
                        {
                            var constructedMethod = methodGroup as ConstructedSymbolReference;
                            methodGroup = constructedMethod != null ?
                                          constructedMethod.referencedSymbol.parentSymbol as MethodGroupDefinition : null;
                        }
                    }
                }
                if (methodGroup != null && methodGroup.kind == SymbolKind.MethodGroup)
                {
                    var group = methodGroup as MethodGroupDefinition;
                    if (group != null && group.methods.Count > 1)
                    {
                        var methodOverloads = new MethodDefinition[group.methods.Count];
                        //group.methods.CopyTo(methodOverloads);
                        Scope leafScope = null;
                        for (var i = leaf.parent; i != null; i = i.parent)
                        {
                            if (i.scope != null)
                            {
                                leafScope = i.scope;
                                break;
                            }
                        }
                        var candidates = group.CollectCandidates(null, null, leafScope);
                        if (candidates != null)
                        {
                            methodOverloads = candidates.ToArray();
                            if (constructedType != null)
                            {
                                overloads = new SymbolDefinition[methodOverloads.Length];
                                for (int i = 0; i < overloads.Length; ++i)
                                {
                                    overloads[i] = constructedType.GetConstructedMember(methodOverloads[i]);
                                }
                            }
                            else
                            {
                                overloads = methodOverloads;
                            }
                            currentOverload = Mathf.Clamp(System.Array.IndexOf(overloads, symbolDefinition), 0, overloads.Length - 1);
                        }
                    }
                    //else if (group == null)
                    //	Debug.Log("Can't convert to MethodGroupDefinition. " + symbolDefinition);
                }
                //else if (methodGroup != null)
                //	Debug.Log("symbolDefinition: " + symbolDefinition.GetType());
                //if (overloads != null)
                //{
                //	var constructedMethodGroup = methodGroup as ConstructedMethodGroupDefinition;
                //	if (constructedMethodGroup != null)
                //	{
                //		var typeParameters = constructedMethodGroup.GetTypeParameters();
                //		Debug.Log(string.Join(", ", (from x in typeParameters select x.ToString()).ToArray()));
                //	}
                //}

                if (overloads == null && symbolDefinition.kind == SymbolKind.Method)
                {
                    overloads       = new SymbolDefinition[] { symbolDefinition };
                    currentOverload = 0;
                }
            }
            catch (System.Exception e)
            {
                //	Debug.LogException(e);
                tooltipText = e.ToString();
            }
        }
        if (showError)
        {
            if (leaf.syntaxError != null)
            {
                tooltipText = leaf.syntaxError;
            }
            else if (leaf.semanticError != null && (symbolDefinition == null || symbolDefinition.kind != SymbolKind.Error))
            {
                if (tooltipText != "")
                {
                    tooltipText = tooltipText + "\n\nSemantic error:\n\t" + leaf.semanticError;
                }
                else
                {
                    tooltipText = leaf.semanticError;
                }
            }
        }

        if (string.IsNullOrEmpty(tooltipText))
        {
            return(null);
        }

        Rect position = horizontal
                        ? new Rect(tokenRect.xMax, tokenRect.y, 1f, 1f)
                        : new Rect(tokenRect.x, tokenRect.yMax, 1f, 1f);

        var owner = EditorWindow.focusedWindow;

        var window = CreatePopup <FGTooltip>();

        window.wantsMouseMove = true;
        window.dropDownRect   = tokenRect;
        window.horizontal     = horizontal;
        window.hideFlags      = HideFlags.HideAndDontSave;

        window.textEditor = editor;
#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5_0
        window.title = string.Empty;
#else
        window.titleContent.text = string.Empty;
#endif
        window.minSize         = Vector2.one;
        window.owner           = owner;
        window.tokenLeaf       = leaf;
        window.text            = tooltipText;
        window.overloads       = overloads;
        window.currentOverload = currentOverload;

        //window.style = new GUIStyle(editor.styles.style);
        //window.style.wordWrap = true;
        //	window.style.fixedWidth = 300f;
        //	window.style.stretchHeight = true;
        window.style = editor.styles.tooltipTextStyle;
        window.style.normal.textColor = SISettings.useStandardColorInPopups ? editor.CurrentTheme.text : editor.CurrentTheme.tooltipText;
        window.style.font             = EditorStyles.standardFont;
        window.style.fontSize         = SISettings.fontSizeDelta + 11;

        window.boldStyle      = new GUIStyle(window.style);
        window.boldStyle.font = EditorStyles.boldFont;

        //window.backgroundStyle = new GUIStyle(editor.styles.style);
        //if (window.backgroundStyle.normal.background)

        window.position = position;
        window.ShowPopup();

        //if (window.owner != null)
        //	window.owner.Focus();
        return(window);
    }
Example #3
0
	static bool IsUsedAsTypeArgument(TypeDefinitionBase typeArgument, ConstructedTypeDefinition constructedType)
	{
		var arguments = constructedType.typeArguments;
		if (arguments == null)
			return false;
		
		for (int i = arguments.Length; i --> 0; )
		{
			var argRef = arguments[i];
			if (argRef == null)
				continue;
			var arg = argRef.definition;
			if (arg == null)
				continue;
			
			if (arg.GetGenericSymbol() == typeArgument)
				return true;
			
			var constructedArg = arg as ConstructedTypeDefinition;
			if (constructedArg != null && IsUsedAsTypeArgument(typeArgument, constructedArg))
				return true;
		}
		return false;
	}