private void TestParseInstanceDeclarationInternal(Func <string, NativeXInstanceDeclaration> parser) { Action <NativeXInstanceDeclaration> vd1 = d => { Assert.IsNull(d.Name); Assert.IsNull(d.Linking); Assert.AreEqual("int", d.Type.ReferencedName); Assert.AreEqual("Eq", d.ConceptName.ReferenceName); Assert.IsNull(d.Functions); }; Action <NativeXInstanceDeclaration> vd2 = d => { Assert.IsNull(d.Name); Assert.IsNull(d.Linking); Assert.AreEqual("int", d.Type.ReferencedName); Assert.AreEqual("Eq", d.ConceptName.ReferenceName); Assert.AreEqual(2, d.Functions.Count); Assert.AreEqual("Equal", d.Functions[0].Name); Assert.AreEqual("IntEqual", ((NativeXReferenceExpression)d.Functions[0].Expression).ReferencedName); Assert.AreEqual("NotEqual", d.Functions[1].Name); Assert.AreEqual("IntNotEqual", ((NativeXReferenceExpression)d.Functions[1].Expression).ReferencedName); }; string d1 = "instance int : Eq;"; string d2 = "instance int : Eq{Equal = IntEqual; NotEqual = IntNotEqual;}"; { NativeXInstanceDeclaration d = parser(d1); vd1(d); } { NativeXInstanceDeclaration d = parser(d2); vd2(d); } { NativeXInstanceDeclaration d = parser(g1 + d1); vg1(d); vd1(d); } { NativeXInstanceDeclaration d = parser(g2 + d2); vg2(d); vd2(d); } }
public virtual string OnGetSimpleTooltip(TextPosition pos) { if (this.EditingObserverExtension.AnalyzingResult == null || this.EditingObserverExtension.AnalyzingResult.Unit == null) { return(null); } NativeXNode node = this.EditingObserverExtension.AnalyzingResult.Unit.FindDeepest <NativeXNode>(pos); NativeXNode hint = null; { NativeXReferenceExpression exp = node as NativeXReferenceExpression; if (exp != null && exp.Scope != null) { hint = (NativeXNode)exp.Scope.Find(exp.ReferencedName); goto SHOW_HINT; } } { NativeXReferenceType type = node as NativeXReferenceType; if (type != null && type.Scope != null) { hint = (NativeXNode)type.Scope.Find(type.ReferencedName); goto SHOW_HINT; } } { NativeXConceptReference concept = node as NativeXConceptReference; if (concept != null && concept.Scope != null) { hint = (NativeXNode)concept.Scope.Find(concept.ReferenceName); goto SHOW_HINT; } } { NativeXInstanciatedExpression exp = node as NativeXInstanciatedExpression; if (exp != null && exp.Scope != null) { hint = (NativeXNode)exp.Scope.Find(exp.ReferencedName); goto SHOW_HINT; } } { NativeXInstanceFunctionExpression exp = node as NativeXInstanceFunctionExpression; if (exp != null && exp.Scope != null && exp.ConceptName != null) { hint = (NativeXNode)exp.Scope.Find(exp.ConceptName.ReferenceName); goto SHOW_HINT; } } { NativeXInstanceDeclaration inst = node as NativeXInstanceDeclaration; if (inst != null && inst.Scope != null && inst.ConceptName != null) { if (this.EditingObserverExtension.AnalyzingResult.IdTokens.ContainsKey(pos.row)) { CodeToken token = this.EditingObserverExtension.AnalyzingResult.IdTokens[pos.row].Where(t => t.Start <= pos && pos <= t.End).FirstOrDefault(); if (token.Value == inst.ConceptName.ReferenceName) { hint = (NativeXNode)inst.Scope.Find(inst.ConceptName.ReferenceName); } } } } { NativeXGenericConstraint genecons = node as NativeXGenericConstraint; if (genecons != null && genecons.Scope != null && genecons.ConceptName != null) { if (this.EditingObserverExtension.AnalyzingResult.IdTokens.ContainsKey(pos.row)) { CodeToken token = this.EditingObserverExtension.AnalyzingResult.IdTokens[pos.row].Where(t => t.Start <= pos && pos <= t.End).FirstOrDefault(); if (token.Value == genecons.ConceptName.ReferenceName) { hint = (NativeXNode)genecons.Scope.Find(genecons.ConceptName.ReferenceName); } } } } SHOW_HINT: if (hint != null) { NativeXFunctionDeclaration function = hint as NativeXFunctionDeclaration; TextPosition start, end; if (function == null) { start = hint.Start; end = hint.End; } else { start = hint.Start; end = function.Statement == null ? function.End : function.Statement.Start; } if (start < end) { start = this.Callback.TextEditorBox.Controller.Normalize(start); end = this.Callback.TextEditorBox.Controller.Normalize(end); string text = this.Callback.TextEditorBox.TextProvider.GetString(start, end); if (!string.IsNullOrWhiteSpace(text)) { return(text); } } } return(null); }