TypeSystemAstBuilder GetBuilder(ICompilation compilation) { var ctx = editorCompletion.CSharpUnresolvedFile.GetTypeResolveContext(compilation, editorCompletion.Document.Editor.Caret.Location) as CSharpTypeResolveContext; var state = new CSharpResolver(ctx); var builder = new TypeSystemAstBuilder(state); builder.AddAnnotations = true; var dt = state.CurrentTypeDefinition; var declaring = ctx.CurrentTypeDefinition != null ? ctx.CurrentTypeDefinition.DeclaringTypeDefinition : null; if (declaring != null) { while (dt != null) { if (dt.Equals(declaring)) { builder.AlwaysUseShortTypeNames = true; break; } dt = dt.DeclaringTypeDefinition; } } return(builder); }
internal static bool IsEqualResolverState(CSharpResolver r1, CSharpResolver r2) { if (r1.CheckForOverflow != r2.CheckForOverflow) { return(false); } if (r1.Compilation != r2.Compilation) { return(false); } if (!object.Equals(r1.CurrentMember, r2.CurrentMember)) { return(false); } if (!object.Equals(r1.CurrentObjectInitializerType, r2.CurrentObjectInitializerType)) { return(false); } if (!object.Equals(r1.CurrentTypeDefinition, r2.CurrentTypeDefinition)) { return(false); } if (!object.Equals(r1.CurrentUsingScope, r2.CurrentUsingScope)) { return(false); } if (r1.IsWithinLambdaExpression != r2.IsWithinLambdaExpression) { return(false); } if (r1.LocalVariables.Count() != r2.LocalVariables.Count()) { return(false); } return(r1.LocalVariables.Zip(r2.LocalVariables, IsEqualVariable).All(_ => _)); }
/// <summary> /// Initializes a new instance of the <see cref="CSharpCompletionContext"/> class. /// </summary> /// <param name="document">The document, make sure the FileName property is set on the document.</param> /// <param name="offset">The offset.</param> /// <param name="projectContent">Content of the project.</param> /// <param name="usings">The usings.</param> public CSharpCompletionContext(IDocument document, int offset, IProjectContent projectContent, string usings = null) { OriginalDocument = document; OriginalOffset = offset; //if the document is a c# script we have to soround the document with some code. Document = PrepareCompletionDocument(document, ref offset, usings); Offset = offset; var syntaxTree = new CSharpParser().Parse(Document, Document.FileName); syntaxTree.Freeze(); var unresolvedFile = syntaxTree.ToTypeSystem(); ProjectContent = projectContent.AddOrUpdateFiles(unresolvedFile); //note: it's important that the project content is used that is returned after adding the unresolved file Compilation = ProjectContent.CreateCompilation(); var location = Document.GetLocation(Offset); Resolver = unresolvedFile.GetResolver(Compilation, location); TypeResolveContextAtCaret = unresolvedFile.GetTypeResolveContext(Compilation, location); CompletionContextProvider = new DefaultCompletionContextProvider(Document, unresolvedFile); }
static TypeSystemAstBuilder CreateBuilder(MonoDevelop.Ide.Gui.Document doc, int offset, ICompilation compilation) { var ctx = doc.ParsedDocument.ParsedFile.GetTypeResolveContext(doc.Compilation, doc.Editor.Caret.Location) as CSharpTypeResolveContext; var state = new CSharpResolver(ctx); var builder = new TypeSystemAstBuilder(state); builder.AddAnnotations = true; var dt = state.CurrentTypeDefinition; var declaring = ctx.CurrentTypeDefinition != null ? ctx.CurrentTypeDefinition.DeclaringTypeDefinition : null; if (declaring != null) { while (dt != null) { if (dt.Equals(declaring)) { builder.AlwaysUseShortTypeNames = true; break; } dt = dt.DeclaringTypeDefinition; } } return(builder); }
public override IEntity ResolveCref(string cref) { if (cref.Length > 2 && cref[1] == ':') { // resolve ID string return(base.ResolveCref(cref)); } var documentationReference = new CSharpParser().ParseDocumentationReference(cref); var csharpContext = context as CSharpTypeResolveContext; CSharpResolver resolver; if (csharpContext != null) { resolver = new CSharpResolver(csharpContext); } else { resolver = new CSharpResolver(context.Compilation); } var astResolver = new CSharpAstResolver(resolver, documentationReference); var rr = astResolver.Resolve(documentationReference); MemberResolveResult mrr = rr as MemberResolveResult; if (mrr != null) { return(mrr.Member); } TypeResolveResult trr = rr as TypeResolveResult; if (trr != null) { return(trr.Type.GetDefinition()); } return(null); }
Value VisitConditionalOperator(OperatorResolveResult result, BinaryOperatorType bitwiseOperatorType) { Debug.Assert(result.Operands.Count == 2); var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread); CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem); Value condVal; if (bitwiseOperatorType == BinaryOperatorType.BitwiseAnd) { condVal = Convert(resolver.ResolveConditionFalse(lhs.ToResolveResult(context))); } else { condVal = Convert(resolver.ResolveCondition(lhs.ToResolveResult(context))); } if ((bool)condVal.PrimitiveValue) { return(lhs); } var rhs = Convert(result.Operands[1]); var val = resolver.ResolveBinaryOperator(bitwiseOperatorType, lhs.ToResolveResult(context), rhs.ToResolveResult(context)); return(Convert(val)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return resolver.ResolveDefaultValue(type.Resolve(resolver.Context)); }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult rr; if (targetType != null) rr = new TypeResolveResult(targetType.Resolve(resolver.Context)); else rr = targetExpression.Resolve(resolver); return resolver.ResolveMemberAccess(rr, memberName, ConstantIdentifierReference.ResolveTypes(resolver, typeArguments)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return resolver.ResolveSimpleName(identifier, ResolveTypes(resolver, typeArguments)); }
public override ResolveResult Resolve(CSharpResolver resolver) { object val = value; if (val is ITypeReference) val = ((ITypeReference)val).Resolve(resolver.Context); return new ConstantResolveResult(type.Resolve(resolver.Context), val); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveAlias(identifier)); }
/// <summary> /// Resolves the reference and returns the ResolveResult. /// </summary> public abstract ResolveResult Resolve(CSharpResolver resolver);
public ExpressionResolveResult(ResolveResult item1, CSharpResolver item2, CSharpAstResolver item3) { this.Result = item1; this.Resolver = item2; this.AstResolver = item3; }
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult lhs = left.Resolve(resolver); ResolveResult rhs = right.Resolve(resolver); return resolver.ResolveBinaryOperator(operatorType, lhs, rhs); }
/// <summary> /// Returns the type that is referenced; or an <c>UnknownType</c> if the type isn't found. /// </summary> public abstract IType ResolveType(CSharpResolver resolver);
public override ResolveResult Resolve(CSharpResolver resolver) { ResolveResult[] elements = new ResolveResult[arrayElements.Count]; for (int i = 0; i < elements.Length; i++) { elements[i] = arrayElements[i].Resolve(resolver); } if (elementType != null) { return resolver.ResolveArrayCreation(elementType.Resolve(resolver.Context), 1, null, elements); } else { return resolver.ResolveArrayCreation(null, 1, null, elements); } }
Value VisitBinaryOperator(OperatorResolveResult result, BinaryOperatorType operatorType, bool checkForOverflow = false) { Debug.Assert(result.Operands.Count == 2); Debug.Assert(operatorType != BinaryOperatorType.ConditionalAnd && operatorType != BinaryOperatorType.ConditionalOr && operatorType != BinaryOperatorType.NullCoalescing); var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread); var rhs = Convert(result.Operands[1]).GetPermanentReference(evalThread); if (result.UserDefinedOperatorMethod != null) { return(InvokeMethod(null, result.UserDefinedOperatorMethod, lhs, rhs)); } var lhsRR = lhs.ToResolveResult(context); var rhsRR = rhs.ToResolveResult(context); CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem).WithCheckForOverflow(checkForOverflow); var val = resolver.ResolveBinaryOperator(operatorType, lhsRR, rhsRR); if (val.IsCompileTimeConstant) { return(Convert(val)); } switch (operatorType) { case BinaryOperatorType.Equality: case BinaryOperatorType.InEquality: bool equality = (operatorType == BinaryOperatorType.Equality); if (lhsRR.Type.IsKnownType(KnownTypeCode.String) && rhsRR.Type.IsKnownType(KnownTypeCode.String)) { if (lhs.IsNull || rhs.IsNull) { bool bothNull = lhs.IsNull && rhs.IsNull; return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull)); } else { bool equal = (string)lhs.PrimitiveValue == (string)rhs.PrimitiveValue; return(Eval.CreateValue(evalThread, equality ? equal : !equal)); } } if (lhsRR.Type.IsReferenceType != false && rhsRR.Type.IsReferenceType != false) { // Reference comparison if (lhs.IsNull || rhs.IsNull) { bool bothNull = lhs.IsNull && rhs.IsNull; return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull)); } else { bool equal = lhs.Address == rhs.Address; return(Eval.CreateValue(evalThread, equality ? equal : !equal)); } } goto default; case BinaryOperatorType.Add: if (lhsRR.Type.IsKnownType(KnownTypeCode.String) || rhsRR.Type.IsKnownType(KnownTypeCode.String)) { var method = debuggerTypeSystem.FindType(KnownTypeCode.String) .GetMethods(m => m.Name == "Concat" && m.Parameters.Count == 2) .Single(m => m.Parameters.All(p => p.Type.IsKnownType(KnownTypeCode.Object))); return(InvokeMethod(null, method, lhs, rhs)); } goto default; default: throw new GetValueException("Operator {0} is not supported for {1} and {2}!", operatorType, new CSharpAmbience().ConvertType(lhsRR.Type), new CSharpAmbience().ConvertType(rhsRR.Type)); } }
/// <summary> /// Returns the type that is referenced; or <see cref="SpecialType.UnknownType"/> if the type isn't found. /// </summary> public IType ResolveType(CSharpResolver resolver) { TypeResolveResult trr = Resolve(resolver) as TypeResolveResult; return(trr != null ? trr.Type : SpecialType.UnknownType); }
public OverrideEqualsGetHashCodeCompletionData(int declarationBegin, IMember m, CSharpResolver contextAtCaret) : base(declarationBegin, m, contextAtCaret) { }
public override ResolveResult Resolve(CSharpResolver resolver) { var typeArgs = typeArguments.Resolve(resolver.CurrentTypeResolveContext); return(resolver.LookupSimpleNameOrTypeName(identifier, typeArgs, lookupMode)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveSizeOf(type.Resolve(resolver.CurrentTypeResolveContext))); }
public abstract ResolveResult Resolve(CSharpResolver resolver);
public EventCreationCompletionData(string handlerName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType, CSharpResolver contextAtCaret) { if (string.IsNullOrEmpty(handlerName)) { handlerName = (evt != null ? evt.Name : "Handle"); } this.handlerName = handlerName; this.DisplayText = StringParser.Parse("${res:CSharpBinding.Refactoring.EventCreation.EventHandlerText}", new[] { new StringTagPair("HandlerName", handlerName) }); this.delegateTypeReference = delegateType.ToTypeReference(); this.isStatic = callingMember != null && callingMember.IsStatic; }
public override ResolveResult Resolve(CSharpResolver resolver) { return resolver.ResolveCast(targetType.Resolve(resolver.Context), expression.Resolve(resolver)); }
public virtual object Invoke(CSharpResolver resolver, object lhs, object rhs) { throw new NotSupportedException(); }
internal static IList<IType> ResolveTypes(CSharpResolver resolver, IList<ITypeReference> typeArguments) { if (typeArguments == null) return EmptyList<IType>.Instance; IType[] types = new IType[typeArguments.Count]; for (int i = 0; i < types.Length; i++) { types[i] = typeArguments[i].Resolve(resolver.Context); } return types; }
public override object Invoke(CSharpResolver resolver, object lhs, object rhs) { return(string.Concat(lhs, rhs)); }
public override ResolveResult Resolve(CSharpResolver resolver) { bool oldCheckForOverflow = resolver.CheckForOverflow; try { resolver.CheckForOverflow = this.checkForOverflow; return expression.Resolve(resolver); } finally { resolver.CheckForOverflow = oldCheckForOverflow; } }
public override object Invoke(CSharpResolver resolver, object lhs, object rhs) { return(baseMethod.Invoke(resolver, lhs, rhs)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return resolver.ResolveUnaryOperator(operatorType, expression.Resolve(resolver)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(new ConstantResolveResult(type.Resolve(resolver.CurrentTypeResolveContext), value)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return resolver.ResolveConditional( condition.Resolve(resolver), trueExpr.Resolve(resolver), falseExpr.Resolve(resolver) ); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveCast(targetType.Resolve(resolver.CurrentTypeResolveContext), expression.Resolve(resolver))); }
static IEnumerable <PossibleNamespace> GetPossibleNamespaces(Document doc, AstNode node, ResolveResult resolveResult, DocumentLocation location) { var unit = doc.ParsedDocument.GetAst <SyntaxTree> (); if (unit == null) { yield break; } var project = doc.Project; if (project == null) { yield break; } int tc = GetTypeParameterCount(node); var attribute = unit.GetNodeAt <ICSharpCode.NRefactory.CSharp.Attribute> (location); bool isInsideAttributeType = attribute != null && attribute.Type.Contains(location); var compilations = new List <Tuple <ICompilation, MonoDevelop.Projects.ProjectReference> > (); compilations.Add(Tuple.Create(doc.Compilation, (MonoDevelop.Projects.ProjectReference)null)); var referencedItems = IdeApp.Workspace != null?project.GetReferencedItems(IdeApp.Workspace.ActiveConfiguration).ToList() : (IEnumerable <SolutionItem>) new SolutionItem[0]; var solution = project != null ? project.ParentSolution : null; if (solution != null) { foreach (var curProject in solution.GetAllProjects()) { if (curProject == project || referencedItems.Contains(curProject)) { continue; } var comp = TypeSystemService.GetCompilation(curProject); if (comp == null) { continue; } compilations.Add(Tuple.Create(comp, new MonoDevelop.Projects.ProjectReference(curProject))); } } var netProject = project as DotNetProject; if (netProject == null) { yield break; } var frameworkLookup = TypeSystemService.GetFrameworkLookup(netProject); if (resolveResult is UnknownMemberResolveResult) { var umResult = (UnknownMemberResolveResult)resolveResult; foreach (var r in frameworkLookup.LookupExtensionMethod(umResult.MemberName)) { var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName(r.FullName, r.Package, netProject.TargetFramework); if (systemAssembly == null) { continue; } compilations.Add(Tuple.Create(TypeSystemService.GetCompilation(systemAssembly, doc.Compilation), new MonoDevelop.Projects.ProjectReference(systemAssembly))); } } bool foundIdentifier = false; var lookup = new MemberLookup(null, doc.Compilation.MainAssembly); foreach (var comp in compilations) { var compilation = comp.Item1; var requiredReference = comp.Item2; if (resolveResult is AmbiguousTypeResolveResult) { if (compilation != doc.Compilation) { continue; } var aResult = resolveResult as AmbiguousTypeResolveResult; var file = doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile; var scope = file.GetUsingScope(location).Resolve(compilation); while (scope != null) { foreach (var u in scope.Usings) { foreach (var typeDefinition in u.Types) { if (typeDefinition.Name == aResult.Type.Name && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible(typeDefinition, false)) { yield return(new PossibleNamespace(typeDefinition.Namespace, true, requiredReference)); } } } scope = scope.Parent; } } var allTypes = compilation == doc.Compilation ? compilation.GetAllTypeDefinitions() : compilation.MainAssembly.GetAllTypeDefinitions(); if (resolveResult is UnknownIdentifierResolveResult) { var uiResult = resolveResult as UnknownIdentifierResolveResult; string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier; foreach (var typeDefinition in allTypes) { if (typeDefinition.Name == possibleAttributeName && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible(typeDefinition, false)) { if (typeDefinition.DeclaringTypeDefinition != null) { var builder = new TypeSystemAstBuilder(new CSharpResolver(doc.Compilation)); foundIdentifier = true; yield return(new PossibleNamespace(builder.ConvertType(typeDefinition.DeclaringTypeDefinition).ToString(), false, requiredReference)); } else { foundIdentifier = true; yield return(new PossibleNamespace(typeDefinition.Namespace, true, requiredReference)); } } } } if (resolveResult is UnknownMemberResolveResult) { var umResult = (UnknownMemberResolveResult)resolveResult; string possibleAttributeName = isInsideAttributeType ? umResult.MemberName + "Attribute" : umResult.MemberName; foreach (var typeDefinition in allTypes.Where(t => t.HasExtensionMethods)) { foreach (var method in typeDefinition.Methods.Where(m => m.IsExtensionMethod && m.Name == possibleAttributeName)) { IType[] inferredTypes; if (CSharpResolver.IsEligibleExtensionMethod( compilation.Import(umResult.TargetType), method, true, out inferredTypes )) { yield return(new PossibleNamespace(typeDefinition.Namespace, true, requiredReference)); goto skipType; } } skipType: ; } } if (resolveResult is ErrorResolveResult) { var identifier = unit != null?unit.GetNodeAt <Identifier> (location) : null; if (identifier != null) { var uiResult = resolveResult as UnknownIdentifierResolveResult; if (uiResult != null) { string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier; foreach (var typeDefinition in allTypes) { if ((identifier.Name == possibleAttributeName) && typeDefinition.TypeParameterCount == tc && lookup.IsAccessible(typeDefinition, false)) { yield return(new PossibleNamespace(typeDefinition.Namespace, true, requiredReference)); } } } } } } // Try to search framework types if (!foundIdentifier && resolveResult is UnknownIdentifierResolveResult) { var uiResult = resolveResult as UnknownIdentifierResolveResult; string possibleAttributeName = isInsideAttributeType ? uiResult.Identifier + "Attribute" : uiResult.Identifier; foreach (var r in frameworkLookup.LookupIdentifier(possibleAttributeName, tc)) { var systemAssembly = netProject.AssemblyContext.GetAssemblyFromFullName(r.FullName, r.Package, netProject.TargetFramework); if (systemAssembly == null) { continue; } yield return(new PossibleNamespace(r.Namespace, true, new MonoDevelop.Projects.ProjectReference(systemAssembly))); } } }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveSimpleName(identifier, typeArguments.Resolve(resolver.CurrentTypeResolveContext))); }
/// <summary> /// Returns the namespace that is referenced; or null if no such namespace is found. /// </summary> public INamespace ResolveNamespace(CSharpResolver resolver) { NamespaceResolveResult nrr = Resolve(resolver) as NamespaceResolveResult; return(nrr != null ? nrr.Namespace : null); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(expression.Resolve(resolver.WithCheckForOverflow(checkForOverflow))); }
public CSharpAstResolver GetResolver(CSharpResolver resolver, AstNode rootNode) { return(new CSharpAstResolver(resolver, rootNode, unresolvedFile)); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveDefaultValue(type.Resolve(resolver.CurrentTypeResolveContext))); }
public override IType ResolveType(CSharpResolver resolver) { // alias cannot refer to types return(SpecialType.NoType); }
public override ResolveResult Resolve(CSharpResolver resolver) { return(resolver.ResolveUnaryOperator(operatorType, expression.Resolve(resolver))); }
public override IType ResolveType(CSharpResolver resolver) { TypeResolveResult trr = Resolve(resolver) as TypeResolveResult; return(trr != null ? trr.Type : new UnknownType(null, identifier, typeArguments.Count)); }
public override ResolveResult Resolve(CSharpResolver resolver) { throw new NotImplementedException(); }