コード例 #1
1
		public GenerateNamespaceImport GetResult (ProjectDom dom, ICompilationUnit unit, IType type, TextEditorData data)
		{
			GenerateNamespaceImport result;
			if (cache.TryGetValue (type.Namespace, out result))
				return result;
			result = new GenerateNamespaceImport ();
			cache[type.Namespace] = result;
			
			result.InsertNamespace  = false;
			
			DomLocation location = new DomLocation (data.Caret.Line, data.Caret.Column);
			foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) {
				if (u.Namespaces.Any (ns => type.Namespace == ns)) {
					result.GenerateUsing = false;
					return result;
				}
			}
			result.GenerateUsing = true;
			string name = type.DecoratedFullName.Substring (type.Namespace.Length + 1);
			
			foreach (IUsing u in unit.Usings.Where (u => u.ValidRegion.Contains (location))) {
				foreach (string ns in u.Namespaces) {
					if (dom.SearchType (unit, unit.GetTypeAt (location), unit.GetMemberAt (location), ns + "." + name) != null) {
						result.GenerateUsing = false;
						result.InsertNamespace = true;
						return result;
					}
				}
			}
			return result;
		}
コード例 #2
0
		public InstantiatedParameterType (ProjectDom dom, ITypeParameterMember typeParameterMember, ITypeParameter tp)
		{
			IType outerType = typeParameterMember as IType ?? typeParameterMember.DeclaringType;
			typeparam = tp;
			compilationUnit = outerType.CompilationUnit;
			ClassType = ClassType.Class;
			Modifiers = Modifiers.Public;
			Name = tp.Name;
			Namespace = outerType.DecoratedFullName;
			Location = outerType.Location;
			DeclaringType = outerType;
			
			if (tp.Constraints.Count > 0)
				ClassType = ClassType.Interface;
			foreach (IReturnType rt in tp.Constraints) {
				if (FindCyclicReference (new HashSet<ITypeParameter> () { tp }, outerType, ((DomReturnType)rt).DecoratedFullName))
					continue;
				IType bt = dom.SearchType (typeParameterMember, rt);
				IReturnType resolvedType = rt;
				if (bt != null) {
					resolvedType = new DomReturnType (bt);
					if (bt.ClassType == ClassType.Interface || BaseType != null) {
						AddInterfaceImplementation (resolvedType);
					} else {
						ClassType = bt.ClassType;
						BaseType = resolvedType;
					}
				} else {
					AddInterfaceImplementation (resolvedType);
				}
			}
			if (BaseType == null)
				BaseType = DomReturnType.Object;
		}
コード例 #3
0
        public override INode Visit(IReturnType type, IType contextType)
        {
            if (type.GenericArguments.Count == 0 && unit != null)
            {
                foreach (IUsing u in unit.Usings)
                {
                    if (u.IsFromNamespace || u.Aliases.Count == 0 && contextType != null && u.Region.Contains(contextType.Location))
                    {
                        continue;
                    }
                    foreach (KeyValuePair <string, IReturnType> alias in u.Aliases)
                    {
                        if (alias.Key == type.FullName)
                        {
                            return(Visit(alias.Value, contextType));
                        }
                    }
                }
            }

            if (currentMethod != null)
            {
                IMethod method = null;
                if (currentMethod.IsOverride)
                {
                    foreach (IType curType2 in db.GetInheritanceTree(contextType))
                    {
                        foreach (IMethod curMethod in curType2.SearchMember(currentMethod.Name, true))
                        {
                            if (!curMethod.IsOverride && curMethod.Parameters.Count == currentMethod.Parameters.Count && curMethod.TypeParameters.Count == currentMethod.TypeParameters.Count)
                            {
                                method = curMethod;
                                break;
                            }
                        }
                        if (method != null)
                        {
                            break;
                        }
                    }
                }
                if (method == null)
                {
                    method = currentMethod;
                }
                int idx = currentMethod.GetTypeParameterIndex(type.Name);
                if (idx >= 0)
                {
                    ITypeParameter t = method.TypeParameters [idx];
                    DomReturnType  typeParameterReturnType = new DomReturnType(type.FullName);
                    DomType        constructedType         = new InstantiatedParameterType(db, method, t);

                    if (constructedType.BaseType == null)
                    {
                        constructedType.BaseType = DomReturnType.Object;
                    }

                    constructedType.SourceProjectDom = db;

                    typeParameterReturnType.Type                = constructedType;
                    typeParameterReturnType.ArrayDimensions     = type.ArrayDimensions;
                    typeParameterReturnType.PointerNestingLevel = type.PointerNestingLevel;
                    for (int i = 0; i < type.ArrayDimensions; i++)
                    {
                        typeParameterReturnType.SetDimension(i, type.GetDimension(i));
                    }
                    return(typeParameterReturnType);
                }
            }

            IType lookupType = db.SearchType(unit, contextType, resolvePosition, type);

            if (visitAttribute && lookupType == null && type.Parts.Count > 0)
            {
                string oldName = type.Parts [type.Parts.Count - 1].Name;
                type.Parts [type.Parts.Count - 1].Name += "Attribute";
                lookupType = db.SearchType(unit, contextType, resolvePosition, type);
                if (lookupType == null)
                {
                    type.Parts [type.Parts.Count - 1].Name = oldName;
                }
            }

            if (lookupType == null)
            {
                unresolvedCount++;
                return(type);
            }

            List <IReturnTypePart> parts = new List <IReturnTypePart> (type.Parts.Count);
            IType curType  = lookupType.DeclaringType;
            int   typePart = 0;

            while (curType != null)
            {
                ReturnTypePart newPart = new ReturnTypePart {
                    Name = curType.Name
                };
                newPart.IsGenerated = true;
                for (int n = curType.TypeParameters.Count - 1; n >= 0; n--)
                {
                    newPart.AddTypeParameter(new DomReturnType("?"));
                }

                if (typePart >= type.Parts.Count || (type.Parts [typePart].Name != newPart.Name || type.Parts [typePart].GenericArguments.Count != newPart.GenericArguments.Count))
                {
                    parts.Insert(0, newPart);
                    typePart++;
                }
                curType = curType.DeclaringType;
            }

            foreach (ReturnTypePart part in type.Parts)
            {
                ReturnTypePart newPart = new ReturnTypePart();
                newPart.Name = part.Name;
                foreach (IReturnType ga in part.GenericArguments)
                {
                    newPart.AddTypeParameter((IReturnType)ga.AcceptVisitor(this, contextType));
                }
                parts.Add(newPart);
            }

            DomReturnType rt = new DomReturnType(lookupType.Namespace, parts);

            // Make sure the whole type is resolved
            if (parts.Count > 1 && db.SearchType(unit, contextType, resolvePosition, rt) == null)
            {
                unresolvedCount++;
                return(type);
            }

            rt.PointerNestingLevel = type.PointerNestingLevel;
            rt.IsNullable          = type.IsNullable;
            rt.ArrayDimensions     = type.ArrayDimensions;
            for (int n = 0; n < type.ArrayDimensions; n++)
            {
                rt.SetDimension(n, type.GetDimension(n));
            }
            return(db.GetSharedReturnType(rt));
        }
コード例 #4
0
		public override IEnumerable<object> CreateResolveResult (ProjectDom dom, IMember callingMember)
		{
			List<object> result = new List<object> ();
			if (CallingMember != null && !CallingMember.IsStatic) {
				IType baseType = dom.SearchType (CallingType != null ? CallingType.CompilationUnit : null, CallingType, CallingMember.Location ,CallingType.BaseType ?? DomReturnType.Object);
				MemberResolveResult.AddType (dom, result, baseType, new BaseMemberDecorator (CallingMember, baseType), StaticResolve, m => m.IsAbstract);
			}
			return result;
		}
	//	string expression;
/*		IMember GetLanguageItem (Mono.TextEditor.Document document, LineSegment line, int offset, string expression)
		{
			string txt = document.Text;
			ExpressionResult expressionResult = new ExpressionResult (expression);
//			ExpressionResult expressionResult = expressionFinder.FindFullExpression (txt, offset);
			int lineNumber = document.OffsetToLineNumber (offset);
			expressionResult.Region = new DomRegion (lineNumber, offset - line.Offset, lineNumber, offset + expression.Length - line.Offset);
			expressionResult.ExpressionContext = ExpressionContext.IdentifierExpected;
			
			resolver = new NRefactoryResolver (ctx, doc.CompilationUnit, doc.TextEditor, document.FileName);
			ResolveResult result = resolver.Resolve (expressionResult, expressionResult.Region.Start);
			
			if (result is MemberResolveResult) 
				return ((MemberResolveResult)result).ResolvedMember;
			return null;
		}*/
		
		public override void Analyze (Mono.TextEditor.Document doc, LineSegment line, Chunk startChunk, int startOffset, int endOffset)
		{
			if (!MonoDevelop.Core.PropertyService.Get ("EnableSemanticHighlighting", false) || doc == null || line == null || startChunk == null)
				return;
			ctx = GetParserContext (doc);
			int lineNumber = doc.OffsetToLineNumber (line.Offset);
			ParsedDocument parsedDocument = ProjectDomService.GetParsedDocument (ctx, doc.FileName);
			ICompilationUnit unit = parsedDocument != null ? parsedDocument.CompilationUnit : null;
			if (unit == null)
				return;
			for (Chunk chunk = startChunk; chunk != null; chunk = chunk.Next) {
				if (chunk.Style != "text")
					continue;
				for (int i = chunk.Offset; i < chunk.EndOffset; i++) {
					char charBefore = i > 0 ? doc.GetCharAt (i - 1) : '}';
					if (Char.IsLetter (doc.GetCharAt (i)) && !Char.IsLetterOrDigit (charBefore)) {
					} else {
						continue;
					}
					
					int start = i;
					bool wasWhitespace = false;
					bool wasDot = false;
					int bracketCount = 0;
					while (start > 0) {
						char ch = doc.GetCharAt (start);
						if (ch == '\n' || ch == '\r')
							break;
						if (wasWhitespace && IsNamePart(ch)) {
							start++;
							if (start < chunk.Offset)
								start = Int32.MaxValue;
							break;
						}
						if (ch == '<') {
							bracketCount--;
							if (bracketCount < 0) {
								start++;
								break; 
							}
							start--;
							wasWhitespace = false;
							continue;
						}
						if (ch == '>') {
							if (wasWhitespace && !wasDot)
								break;
							bracketCount++;
							start--;
							wasWhitespace = false;
							continue;
						}
						if (!IsNamePart(ch) && !Char.IsWhiteSpace (ch) && ch != '.') {
							start++;
							break;
						}
						wasWhitespace = Char.IsWhiteSpace (ch);
						wasDot = ch == '.' || wasDot && wasWhitespace;
						start--;
					}
					
					int end = i;
					int genericCount = 0;
					wasWhitespace = false;
					List<Segment> nameSegments = new List<Segment> ();
					while (end < chunk.EndOffset) {
						char ch = doc.GetCharAt (end);
						if (wasWhitespace && IsNamePart(ch))
							break;
						if (ch == '<') {
							genericCount = 1;
							while (end < doc.Length) {
								ch = doc.GetCharAt (end);
								if (ch == ',')
									genericCount++;
								if (ch == '>') {
									nameSegments.Add (new Segment (end, 1));
									break;
								}
								end++;
							}
							break;
						}
						if (!IsNamePart(ch) && !Char.IsWhiteSpace (ch)) 
							break;
						wasWhitespace = Char.IsWhiteSpace (ch);
						end++;
					}
					if (start >= end) 
						continue;
					string typeString = doc.GetTextBetween (start, end);
					IReturnType returnType = NRefactoryResolver.ParseReturnType (new ExpressionResult (typeString));
						
					int nameEndOffset = start;
					for (; nameEndOffset < end; nameEndOffset++) {
						char ch = doc.GetCharAt (nameEndOffset);
						if (nameEndOffset >= i && ch == '<') {
							nameEndOffset++;
							break;
						}
					}
					nameSegments.Add (new Segment (i, nameEndOffset - i));

					int column = i - line.Offset;
					IType callingType = unit.GetTypeAt (lineNumber, column);
					List<IReturnType> genericParams = null;
					if (genericCount > 0) {
						genericParams = new List<IReturnType> ();
						for (int n = 0; n < genericCount; n++) 
							genericParams.Add (new DomReturnType ("A"));
					}
					
					IType type = null;
					if (ctx != null)
						type = ctx.SearchType ((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType);
					if (type == null && unit != null && returnType != null)
						type = unit.GetType (returnType.FullName, returnType.GenericArguments.Count);
					if (ctx != null && type == null && returnType != null) {
						returnType.Name += "Attribute";
						type = ctx.SearchType ((MonoDevelop.Projects.Dom.INode)callingType ?? unit, returnType);
					}
					if (type != null)
						nameSegments.ForEach (segment => HighlightSegment (startChunk, segment, "keyword.semantic.type"));
				}
			}
		}
コード例 #6
0
 public override IType SearchType(ICompilationUnit unit, IType callingClass, DomLocation lookupLocation, string decoratedFullName)
 {
     return(decorated.SearchType(unit, callingClass, lookupLocation, decoratedFullName));
 }
コード例 #7
0
 public override IType SearchType(ICompilationUnit unit, IType callingClass, IMember callingMember, string decoratedFullName)
 {
     return(decorated.SearchType(unit, callingClass, callingMember, decoratedFullName));
 }