void AddSenderAndEventArgsParameters(IMethod method)
		{
			DefaultReturnType returnType = new DefaultReturnType(method.DeclaringType);
			DomRegion region = new DomRegion();
			method.Parameters.Add(new DefaultParameter("sender", returnType, region));
			method.Parameters.Add(new DefaultParameter("e", returnType, region));
		}
Пример #2
0
		void CreateMethod(string fileName, DomRegion region, DomRegion bodyRegion)
		{
			methodHelper.CreateMethod("Class1.MyMethod");
			methodHelper.SetRegion(region);
			methodHelper.SetBodyRegion(bodyRegion);
			methodHelper.SetCompilationUnitFileName(fileName);
		}
Пример #3
0
		public DefaultComment(bool isBlockComment, string commentTag, string commentText, DomRegion region)
		{
			this.isBlockComment = isBlockComment;
			this.commentTag = commentTag;
			this.commentText = commentText;
			this.region = region;
		}
Пример #4
0
		public DefaultResolvedAccessor(Accessibility accessibility, DomRegion region = default(DomRegion), IList<IAttribute> attributes = null, IList<IAttribute> returnTypeAttributes = null)
		{
			this.accessibility = accessibility;
			this.region = region;
			this.attributes = attributes ?? EmptyList<IAttribute>.Instance;
			this.returnTypeAttributes = returnTypeAttributes ?? EmptyList<IAttribute>.Instance;
		}
		public MemberReference (object entity, DomRegion region, int offset, int length) : base (offset, length)
		{
			if (entity == null)
				throw new System.ArgumentNullException ("entity");
			EntityOrVariable = entity;
			Region = region;
		}
Пример #6
0
        static string GetNonBodyRegion
            (DomRegion region, IDocument document, DomRegion bodyRegion) {

            // Delegates have no body, so they will crash if we don't do this
            if (bodyRegion.BeginLine == 0
                && bodyRegion.EndLine == 0)
                bodyRegion = region;

            var begin     = document.GetOffset(region.Begin);
            var bodyStart = document.GetOffset(bodyRegion.Begin);

            // Some entities have no body. These include members in
            // interfaces.
            bool hasNoBody = bodyStart == begin;
            var typeSignatureLength = hasNoBody
				? document.GetOffset(region.End) - begin
				: bodyStart - begin;
            // Note: We remove extra spaces and newlines from the type
            // signature to make displaying it easier in Vim. Other
            // editors might not have a problem with displaying
            // results with multiple lines.
            var text = document.GetText
                ( offset: document.GetOffset(region.Begin)
                , length: typeSignatureLength)
                .MultipleWhitespaceCharsToSingleSpace();

            return text;
        }
Пример #7
0
 public DefaultField(IReturnType type, string name, ModifierEnum m, DomRegion region, IClass declaringType)
     : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region = region;
     this.Modifiers = m;
 }
Пример #8
0
		public DefaultParameter(IParameter p)
		{
			this.name = p.Name;
			this.region = p.Region;
			this.modifier = p.Modifiers;
			this.returnType = p.ReturnType;
		}
Пример #9
0
		/// <summary>
		/// Initializes a new instance of the <see cref="MonoDevelop.CodeIssues.CodeIssue"/> class.
		/// </summary>
		public CodeIssue (string description, DomRegion region, string inspectorIdString, IEnumerable<MonoDevelop.CodeActions.CodeAction>  actions = null)
		{
			Description = description;
			Region = region;
			Actions = actions;
			InspectorIdString = inspectorIdString;
		}
		public ExpressionResult(string expression, DomRegion region, ExpressionContext context, object tag)
		{
			this.Expression = expression;
			this.Region = region;
			this.Context = context;
			this.Tag = tag;
		}
Пример #11
0
		public MemberExistsException (string className, string memberName, MemberType existingMemberType, MemberType newMemberType, DomRegion errorLocation, string fileName)
			: base (errorLocation, fileName)
		{
			this.className = className;
			this.memberName = memberName;
			this.existingMemberType = existingMemberType;
			this.newMemberType = newMemberType;
		}
 public Message(MessageSeverity severity, int code, DomRegion region, string format, params object[] args)
 {
     Severity = severity;
     Code = code;
     Region = region;
     Format = format;
     Args = args;
 }
		public SimpleVariable(IType type, string name, DomRegion region) {
			Debug.Assert(type != null);
			Debug.Assert(name != null);
			Debug.Assert(region != null);
			this.type = type;
			this.name = name;
			this.region = region;
		}
Пример #14
0
		public Result (DomRegion region, string message, Severity level, IssueMarker inspectionMark, bool underline = true)
		{
			this.Region = region;
			this.Message = message;
			this.Level = level;
			this.InspectionMark = inspectionMark;
			this.Underline = underline;
		}
Пример #15
0
		public DefaultVariable(IType type, string name, DomRegion region = default(DomRegion),
		                       bool isConst = false, object constantValue = null)
			: this(type, name)
		{
			this.region = region;
			this.isConst = isConst;
			this.constantValue = constantValue;
		}
Пример #16
0
 public DefaultMethod(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType)
     : base(declaringType, name)
 {
     this.ReturnType = type;
     this.Region     = region;
     this.BodyRegion = bodyRegion;
     Modifiers = m;
 }
		public static WixDocumentLineSegment ConvertRegionToSegment(IDocument document, DomRegion region)
		{
			// Single line region
			if (IsSingleLineRegion(region)) {
				return ConvertRegionToSingleLineSegment(document, region);
			}
			return ConvertRegionToMultiLineSegment(document, region);
		}
		static string ExtractRegion(string text, DomRegion region)
		{
			if (region.IsEmpty)
				return null;
			int start = GetOffsetByPosition(text, region.BeginLine, region.BeginColumn);
			int end = GetOffsetByPosition(text, region.EndLine, region.EndColumn);
			return text.Substring(start, end - start);
		}
		public Message(MessageSeverity severity, int code, DomRegion region, string format, params object[] args) {
			Severity = severity;
			Code = code;
			Region = region;
			Format = format;
			Args = args;
			FormattedMessage = Args.Length > 0 ? string.Format(Format, Args) : Format;
		}
Пример #20
0
		public Result (DomRegion region, string message, QuickTaskSeverity level, ResultCertainty certainty, ResultImportance importance, bool underline = true)
		{
			this.Region = region;
			this.Message = message;
			this.Level = level;
			this.Certainty = certainty;
			this.Importance = importance;
			this.Underline = underline;
		}
		public void MethodBodyRegion()
		{
			int startLine = 2;
			int startColumn = 11; // IronRuby parser includes the as part of the method parameters
			int endLine = 4;
			int endColumn = 5;
			DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
			Assert.AreEqual(region.ToString(), method.BodyRegion.ToString());
		}
		public void MethodBodyRegion()
		{
			int startLine = 2;
			int startColumn = 18;
			int endLine = 4;
			int endColumn = 5;
			DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
			Assert.AreEqual(region.ToString(), method.BodyRegion.ToString());
		}
Пример #23
0
		public static void Write (BinaryWriter writer, INameEncoder nameTable, DomRegion region)
		{
			if (WriteNull (writer, region)) 
				return;
			writer.Write (region.Start.Line);
			writer.Write (region.Start.Column);
			writer.Write (region.End.Line);
			writer.Write (region.End.Column);
		}
		public void ClassBodyRegion()
		{
			int startLine = 1;
			int startColumn = 12;
			int endLine = 2;
			int endColumn = 6;
			DomRegion region = new DomRegion(startLine, startColumn, endLine, endColumn);
			Assert.AreEqual(region.ToString(), c.BodyRegion.ToString());
		}
Пример #25
0
		public Result (DomRegion region, string message, ResultLevel level,
			ResultCertainty certainty, ResultImportance importance)
		{
			this.Region = region;
			this.Message = message;
			this.Level = level;
			this.Certainty = certainty;
			this.Importance = importance;
		}
		public void GetMethodReplaceRegion()
		{
			MockMethod method = MockMethod.CreateMockMethodWithoutAnyAttributes();
			DomRegion bodyRegion = new DomRegion(0, 4, 1, 4);
			method.BodyRegion = bodyRegion;
			DomRegion expectedRegion = new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine, 1);
			DomRegion region = generator.GetBodyRegionInDocument(method);
			
			Assert.AreEqual(expectedRegion, region);
		}		
Пример #27
0
 /// <summary>
 /// Builds converter from <c>DomRegion</c> and <c>IDocument</c>.
 /// </summary>
 /// <param name="region">DomRegion</param>
 /// <param name="doc">Document</param>
 /// <returns>Convertor</returns>
 public static LineOffsetConverter BuildConverter(DomRegion region, IDocument doc)
 {
     LineOffsetConverter lineCon = new LineOffsetConverter();
     lineCon.startLine = region.BeginLine;
     int stOffset = doc.PositionToOffset(region.BeginLine,0);
     for(int i = region.BeginLine;i <= region.EndLine; i++){
         lineCon.lineOffsets.Add(doc.PositionToOffset(i,0) - stOffset);
     }
     return lineCon;
 }
Пример #28
0
		public void ThreeLineRegionWithoutCarriageReturnConvertedToSegment()
		{
			DomRegion region = new DomRegion(1, 3, 3, 2);
			document.Text = "1234567890\n1234567890\n1234567890";
			WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(2, 22);
			
			Assert.AreEqual(expectedSegment, segment);
		}
Пример #29
0
		public void TwoLineRegionConvertedToSegment()
		{
			DomRegion region = new DomRegion(1, 2, 2, 1);
			document.Text = "1234567890\r\n1234567890";
			WixDocumentLineSegment segment = WixDocumentLineSegment.ConvertRegionToSegment(document, region);
			
			WixDocumentLineSegment expectedSegment = new WixDocumentLineSegment(1, 12);
			
			Assert.AreEqual(expectedSegment, segment);
		}
Пример #30
0
		public DefaultEvent(string name, IReturnType type, ModifierEnum m, DomRegion region, DomRegion bodyRegion, IClass declaringType) : base(declaringType, name)
		{
			this.ReturnType = type;
			this.Region     = region;
			this.BodyRegion = bodyRegion;
			Modifiers       = (ModifierEnum)m;
			if (Modifiers == ModifierEnum.None) {
				Modifiers = ModifierEnum.Private;
			}
		}
Пример #31
0
 public static Location GetStart(this DomRegion region)
 {
     return(new Location(region.BeginColumn, region.BeginLine));
 }
 public CSharpMemberReference(Project project, AstNode astNode, SyntaxTree syntaxTree, object entity, DomRegion region, int offset, int length) : base(entity, region, offset, length)
 {
     this.Project    = project;
     this.AstNode    = astNode;
     this.SyntaxTree = syntaxTree;
 }
        public virtual void MergeFormChanges(CodeCompileUnit unit)
        {
            Reparse();

            // find InitializeComponent method and the class it is declared in
            CodeTypeDeclaration formClass           = null;
            CodeMemberMethod    initializeComponent = null;

            foreach (CodeNamespace n in unit.Namespaces)
            {
                foreach (CodeTypeDeclaration typeDecl in n.Types)
                {
                    foreach (CodeTypeMember m in typeDecl.Members)
                    {
                        if (m is CodeMemberMethod && m.Name == "InitializeComponent")
                        {
                            formClass           = typeDecl;
                            initializeComponent = (CodeMemberMethod)m;
                            break;
                        }
                    }
                }
            }

            if (formClass == null || initializeComponent == null)
            {
                throw new InvalidOperationException("InitializeComponent method not found in framework-generated CodeDom.");
            }
            if (this.formClass == null)
            {
                MessageService.ShowMessage("Cannot save form: InitializeComponent method does not exist anymore. You should not modify the Designer.cs file while editing a form.");
                return;
            }

            FixGeneratedCode(this.formClass, initializeComponent);

            // generate file and get initialize components string
            StringWriter     writer       = new StringWriter();
            CodeDOMGenerator domGenerator = new CodeDOMGenerator(this.CodeDomProvider, tabs + '\t');

            domGenerator.ConvertContentDefinition(initializeComponent, writer);

            string statements = writer.ToString();

            // initializeComponents.BodyRegion.BeginLine + 1
            DomRegion bodyRegion = GetReplaceRegion(this.ViewContent.DesignerCodeFileDocument, initializeComponents);

            if (bodyRegion.BeginColumn <= 0 || bodyRegion.EndColumn <= 0)
            {
                throw new InvalidOperationException("Column must be > 0");
            }
            int startOffset = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(bodyRegion.BeginLine, bodyRegion.BeginColumn);
            int endOffset   = this.ViewContent.DesignerCodeFileDocument.PositionToOffset(bodyRegion.EndLine, bodyRegion.EndColumn);

            this.ViewContent.DesignerCodeFileDocument.Replace(startOffset, endOffset - startOffset, statements);

            // apply changes the designer made to field declarations
            // first loop looks for added and changed fields
            foreach (CodeTypeMember m in formClass.Members)
            {
                if (m is CodeMemberField)
                {
                    CodeMemberField newField = (CodeMemberField)m;
                    IField          oldField = GetField(completeClass, newField.Name);
                    if (oldField == null || FieldChanged(oldField, newField))
                    {
                        AddOrReplaceField(domGenerator, newField);
                    }
                }
            }

            // second loop looks for removed fields
            List <string> removedFields = new List <string>();

            foreach (IField field in completeClass.Fields)
            {
                bool found = false;
                foreach (CodeTypeMember m in formClass.Members)
                {
                    if (m is CodeMemberField && m.Name == field.Name)
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    removedFields.Add(field.Name);
                }
            }
            // removing fields is done in two steps because
            // we must not modify the c.Fields collection while it is enumerated
            removedFields.ForEach(RemoveField);

            ParserService.BeginParse(this.ViewContent.DesignerCodeFile.FileName, this.ViewContent.DesignerCodeFileDocument);
        }
Пример #34
0
 static bool WriteNull(BinaryWriter writer, DomRegion region)
 {
     writer.Write(region == DomRegion.Empty);
     return(region == DomRegion.Empty);
 }
Пример #35
0
        public static void Format(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false)
        {
            if (data.ParsedDocument == null)
            {
                return;
            }
            var ext = data.GetContent <CSharpCompletionTextEditorExtension> ();

            if (ext == null)
            {
                return;
            }
            string    text;
            int       formatStartOffset, formatLength, realTextDelta;
            DomRegion formattingRegion = DomRegion.Empty;
            int       startDelta       = 1;

            if (exact)
            {
                text = data.Editor.Text;
                var seg  = ext.typeSystemSegmentTree.GetMemberSegmentAt(startOffset);
                var seg2 = ext.typeSystemSegmentTree.GetMemberSegmentAt(endOffset);
                if (seg != null && seg == seg2)
                {
                    var member = seg.Entity;
                    if (member == null || member.Region.IsEmpty || member.BodyRegion.End.IsEmpty)
                    {
                        return;
                    }

                    text             = BuildStub(data, seg, startOffset, endOffset, out formatStartOffset);
                    startDelta       = startOffset - seg.Offset;
                    formatLength     = endOffset - startOffset + startDelta;
                    realTextDelta    = seg.Offset - formatStartOffset;
                    formattingRegion = new DomRegion(data.Editor.OffsetToLocation(formatStartOffset), data.Editor.OffsetToLocation(endOffset));
                }
                else
                {
                    formatStartOffset = startOffset;
                    formatLength      = endOffset - startOffset;
                    realTextDelta     = 0;
                    formattingRegion  = new DomRegion(data.Editor.OffsetToLocation(startOffset), data.Editor.OffsetToLocation(endOffset));
                }
            }
            else
            {
                var seg = ext.typeSystemSegmentTree.GetMemberSegmentAt(startOffset - 1);
                if (seg == null)
                {
                    return;
                }
                var member = seg.Entity;
                if (member == null)
                {
                    return;
                }

                // Build stub
                text             = BuildStub(data, seg, startOffset, endOffset, out formatStartOffset);
                formattingRegion = new DomRegion(data.Editor.OffsetToLocation(formatStartOffset), data.Editor.OffsetToLocation(endOffset));

                formatLength  = endOffset - seg.Offset;
                realTextDelta = seg.Offset - formatStartOffset;
            }
            // Get changes from formatting visitor
            var changes = GetFormattingChanges(policyParent, mimeTypeChain, data, text, formattingRegion, ref formatStartOffset, ref formatLength, formatLastStatementOnly);

            if (changes == null)
            {
                return;
            }

            // Do the actual formatting
//			var originalVersion = data.Editor.Document.Version;

            using (var undo = data.Editor.OpenUndoGroup()) {
                try {
                    changes.ApplyChanges(formatStartOffset + startDelta, Math.Max(0, formatLength - startDelta - 1), delegate(int replaceOffset, int replaceLength, string insertText) {
                        int translatedOffset = realTextDelta + replaceOffset;
                        data.Editor.Document.CommitLineUpdate(data.Editor.OffsetToLineNumber(translatedOffset));
                        data.Editor.Replace(translatedOffset, replaceLength, insertText);
                    }, (replaceOffset, replaceLength, insertText) => {
                        int translatedOffset = realTextDelta + replaceOffset;
                        if (translatedOffset < 0 || translatedOffset + replaceLength > data.Editor.Length)
                        {
                            return(true);
                        }
                        return(data.Editor.GetTextAt(translatedOffset, replaceLength) == insertText);
                    });
                } catch (Exception e) {
                    LoggingService.LogError("Error in on the fly formatter", e);
                }

//				var currentVersion = data.Editor.Document.Version;
//				data.Editor.Caret.Offset = originalVersion.MoveOffsetTo (currentVersion, caretOffset, ICSharpCode.NRefactory.Editor.AnchorMovementType.Default);
            }
        }
 public FoldingRegion(string name, DomRegion region, bool isFoldedByDefault) : this(name, region)
 {
     this.IsFoldedByDefault = isFoldedByDefault;
 }
        public override object VisitTypeDeclaration(AST.TypeDeclaration typeDeclaration, object data)
        {
            DomRegion region     = GetRegion(typeDeclaration.StartLocation, typeDeclaration.EndLocation);
            DomRegion bodyRegion = GetRegion(typeDeclaration.BodyStartLocation, typeDeclaration.EndLocation);

            DefaultClass c = new DefaultClass(cu, TranslateClassType(typeDeclaration.Type), ConvertTypeModifier(typeDeclaration.Modifier), region, GetCurrentClass());

            if (c.IsStatic)
            {
                // static classes are also abstract and sealed at the same time
                c.Modifiers |= ModifierEnum.Abstract | ModifierEnum.Sealed;
            }
            c.BodyRegion = bodyRegion;
            ConvertAttributes(typeDeclaration, c);
            c.Documentation = GetDocumentation(region.BeginLine, typeDeclaration.Attributes);

            DefaultClass outerClass = GetCurrentClass();

            if (outerClass != null)
            {
                outerClass.InnerClasses.Add(c);
                c.FullyQualifiedName = outerClass.FullyQualifiedName + '.' + typeDeclaration.Name;
            }
            else
            {
                c.FullyQualifiedName = PrependCurrentNamespace(typeDeclaration.Name);
                cu.Classes.Add(c);
            }
            c.UsingScope = currentNamespace;
            currentClass.Push(c);

            ConvertTemplates(outerClass, typeDeclaration.Templates, c);             // resolve constrains in context of the class
            // templates must be converted before base types because base types may refer to generic types

            if (c.ClassType != ClassType.Enum && typeDeclaration.BaseTypes != null)
            {
                foreach (AST.TypeReference type in typeDeclaration.BaseTypes)
                {
                    IReturnType rt = CreateReturnType(type, null, TypeVisitor.ReturnTypeOptions.BaseTypeReference);
                    if (rt != null)
                    {
                        c.BaseTypes.Add(rt);
                    }
                }
            }

            object ret = typeDeclaration.AcceptChildren(this, data);

            currentClass.Pop();

            if (c.ClassType == ClassType.Module)
            {
                foreach (DefaultField f in c.Fields)
                {
                    f.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultMethod m in c.Methods)
                {
                    m.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultProperty p in c.Properties)
                {
                    p.Modifiers |= ModifierEnum.Static;
                }
                foreach (DefaultEvent e in c.Events)
                {
                    e.Modifiers |= ModifierEnum.Static;
                }
            }

            return(ret);
        }
 public FoldingRegion(DomRegion region) : this(null, region)
 {
 }
 public FoldingRegion(string name, DomRegion region)
 {
     this.Name   = name ?? defaultName;
     this.Region = region;
 }
Пример #40
0
 public FoldingRegion(string name, DomRegion region)
 {
     Region = region;
     Name   = name;
 }
Пример #41
0
 static bool IncompleteOrSingleLine(DomRegion region)
 {
     return(region.BeginLine <= 0 || region.EndLine <= region.BeginLine);
 }
Пример #42
0
 /// <summary>
 /// Gets the start offset of the region.
 /// </summary>
 static int GetStartOffset(IDocument document, DomRegion region)
 {
     return(document.PositionToOffset(new TextLocation(region.BeginColumn - 1, region.BeginLine - 1)));
 }
Пример #43
0
 public static Location GetEnd(this DomRegion region)
 {
     return(new Location(region.EndColumn, region.EndLine));
 }
Пример #44
0
        static void GenerateCU(XmlParsedDocument doc)
        {
            if (doc.XDocument == null || doc.XDocument.RootElement == null)
            {
                doc.Add(new Error(ErrorType.Error, 1, 1, "No root node found."));
                return;
            }

            XAttribute rootClass = doc.XDocument.RootElement.Attributes [new XName("x", "Class")];

            if (rootClass == null)
            {
                doc.Add(new Error(ErrorType.Error, 1, 1, "Root node does not contain an x:Class attribute."));
                return;
            }

            bool isApplication = doc.XDocument.RootElement.Name.Name == "Application";

            string rootNamespace, rootType, rootAssembly;

            XamlG.ParseXmlns(rootClass.Value, out rootType, out rootNamespace, out rootAssembly);

            CompilationUnit cu = new CompilationUnit(doc.FileName);

            doc.CompilationUnit = cu;

            DomRegion rootRegion = doc.XDocument.RootElement.Region;

            if (doc.XDocument.RootElement.IsClosed)
            {
                rootRegion.End = doc.XDocument.RootElement.ClosingTag.Region.End;
            }

            DomType declType = new DomType(cu, ClassType.Class, Modifiers.Partial | Modifiers.Public, rootType,
                                           doc.XDocument.RootElement.Region.Start, rootNamespace, rootRegion);

            cu.Add(declType);

            DomMethod initcomp = new DomMethod();

            initcomp.Name       = "InitializeComponent";
            initcomp.Modifiers  = Modifiers.Public;
            initcomp.ReturnType = DomReturnType.Void;
            declType.Add(initcomp);

            DomField _contentLoaded = new DomField("_contentLoaded");

            _contentLoaded.ReturnType = new DomReturnType("System.Boolean");

            if (isApplication)
            {
                return;
            }

            cu.Add(new DomUsing(DomRegion.Empty, "System"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Controls"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Documents"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Input"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Media"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Media.Animation"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Shapes"));
            cu.Add(new DomUsing(DomRegion.Empty, "System.Windows.Controls.Primitives"));

//			Dictionary<string,string> namespaceMap = new Dictionary<string, string> ();
//			namespaceMap["x"] = "http://schemas.microsoft.com/winfx/2006/xaml";

            XName nameAtt = new XName("x", "Name");

            foreach (XElement el in doc.XDocument.RootElement.AllDescendentElements)
            {
                XAttribute name = el.Attributes [nameAtt];
                if (name != null && name.IsComplete)
                {
                    string type = ResolveType(el);
                    if (type == null || type.Length == 0)
                    {
                        doc.Add(new Error(ErrorType.Error, el.Region.Start, "Could not find namespace for '" + el.Name.FullName + "'."));
                    }
                    else
                    {
                        declType.Add(new DomField(name.Value, Modifiers.Internal, el.Region.Start, new DomReturnType(type)));
                    }
                }
            }
        }
 static DomRegion GetRegion(RefParser.Location start, RefParser.Location end)
 {
     return(DomRegion.FromLocation(start, end));
 }
Пример #46
0
        public void ReplacingUnknownElementReturnsEmptyRegion()
        {
            DomRegion region = wixDocumentEditor.ReplaceElement("TARGETDIR", "unknown-element", "<test/>");

            Assert.IsTrue(region.IsEmpty);
        }
 public FoldingRegion(string name, DomRegion region, FoldType type) : this(name, region)
 {
     this.Type = type;
 }
 public bool AccessorDomRegionIsEmpty(DomRegion region)
 {
     return(region.EndLine == region.BeginLine &&
            region.EndColumn - region.BeginColumn == 4);
 }
Пример #49
0
 public DefaultParameter(IType type, string name, IParameterizedMember owner = null, DomRegion region = default(DomRegion), IList <IAttribute> attributes = null,
                         bool isRef = false, bool isOut = false, bool isParams = false, bool isOptional = false, object defaultValue = null)
 {
     if (type == null)
     {
         throw new ArgumentNullException("type");
     }
     if (name == null)
     {
         throw new ArgumentNullException("name");
     }
     this.type         = type;
     this.name         = name;
     this.owner        = owner;
     this.region       = region;
     this.attributes   = attributes;
     this.isRef        = isRef;
     this.isOut        = isOut;
     this.isParams     = isParams;
     this.isOptional   = isOptional;
     this.defaultValue = defaultValue;
 }
 public FoldingRegion(string name, DomRegion region, FoldType type, bool isFoldedByDefault) : this(name, region)
 {
     this.Type = type;
     this.IsFoldedByDefault = isFoldedByDefault;
 }
Пример #51
0
        static FormattingChanges GetFormattingChanges(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain, MonoDevelop.Ide.Gui.Document document, string input, DomRegion formattingRegion, ref int formatStartOffset, ref int formatLength, bool formatLastStatementOnly)
        {
            using (var stubData = TextEditorData.CreateImmutable(input)) {
                stubData.Document.FileName = document.FileName;
                var  parser          = document.HasProject ? new PlayScriptParser(TypeSystemParser.GetCompilerArguments(document.Project)) : new PlayScriptParser();
                var  compilationUnit = parser.Parse(stubData);
                bool hadErrors       = parser.HasErrors;
                if (hadErrors)
                {
                    using (var stubData2 = TextEditorData.CreateImmutable(input + "}")) {
                        compilationUnit = parser.Parse(stubData2);
                        hadErrors       = parser.HasErrors;
                    }
                }
                // try it out, if the behavior is better when working only with correct code.
                if (hadErrors)
                {
                    return(null);
                }

                var policy = policyParent.Get <PlayScriptFormattingPolicy> (mimeTypeChain);

                var formattingVisitor = new ICSharpCode.NRefactory.PlayScript.CSharpFormatter(policy.CreateOptions(), document.Editor.CreateNRefactoryTextEditorOptions());
                formattingVisitor.FormattingMode = FormattingMode.Intrusive;
                formattingVisitor.AddFormattingRegion(formattingRegion);


                var changes = formattingVisitor.AnalyzeFormatting(stubData.Document, compilationUnit);

                if (formatLastStatementOnly)
                {
                    AstNode node = compilationUnit.GetAdjacentNodeAt <Statement> (stubData.OffsetToLocation(formatStartOffset + formatLength - 1));
                    if (node != null)
                    {
                        while (node.Role == Roles.EmbeddedStatement || node.Role == IfElseStatement.TrueRole || node.Role == IfElseStatement.FalseRole)
                        {
                            node = node.Parent;
                        }
                        // include indentation if node starts in new line
                        var formatNode = node.GetPrevNode();
                        if (formatNode.Role != Roles.NewLine)
                        {
                            formatNode = node;
                        }
                        var start = stubData.LocationToOffset(formatNode.StartLocation);
                        if (start > formatStartOffset)
                        {
                            var end = stubData.LocationToOffset(node.EndLocation);
                            formatStartOffset = start;
                            formatLength      = end - start;
                        }
                    }
                }
                return(changes);
            }
        }
 public FixableResult(DomRegion region, string message, Severity level,
                      IssueMarker mark, params IAnalysisFix[] fixes)
     : base(region, message, level, mark)
 {
     this.Fixes = fixes;
 }
 public FoldingRegion(DomRegion region, FoldType type) : this(null, region, type)
 {
 }
        MemberReference GetReference(Project project, ResolveResult result, AstNode node, SyntaxTree syntaxTree, string fileName, Mono.TextEditor.TextEditorData editor)
        {
            AstNode originalNode = node;

            if (result == null)
            {
                return(null);
            }

            object valid = null;

            if (result is MethodGroupResolveResult)
            {
                valid = ((MethodGroupResolveResult)result).Methods.FirstOrDefault(
                    m => searchedMembers.Any(member => member is IMethod && ((IMethod)member).Region == m.Region));
            }
            else if (result is MemberResolveResult)
            {
                var foundMember = ((MemberResolveResult)result).Member;
                valid = searchedMembers.FirstOrDefault(
                    member => member is IMember && ((IMember)member).Region == foundMember.Region);
            }
            else if (result is NamespaceResolveResult)
            {
                var ns = ((NamespaceResolveResult)result).Namespace;
                valid = searchedMembers.FirstOrDefault(n => n is INamespace && ns.FullName.StartsWith(((INamespace)n).FullName, StringComparison.Ordinal));
            }
            else if (result is LocalResolveResult)
            {
                var ns = ((LocalResolveResult)result).Variable;
                valid = searchedMembers.FirstOrDefault(n => n is IVariable && ((IVariable)n).Region == ns.Region);
            }
            else if (result is TypeResolveResult)
            {
                valid = searchedMembers.FirstOrDefault(n => n is IType);
            }
            else
            {
                valid = searchedMembers.FirstOrDefault();
            }

            if (node is ConstructorInitializer)
            {
                return(null);
            }
            if (node is ObjectCreateExpression)
            {
                node = ((ObjectCreateExpression)node).Type;
            }

            if (node is InvocationExpression)
            {
                node = ((InvocationExpression)node).Target;
            }

            if (node is MemberReferenceExpression)
            {
                node = ((MemberReferenceExpression)node).MemberNameToken;
            }

            if (node is SimpleType)
            {
                node = ((SimpleType)node).IdentifierToken;
            }

            if (node is MemberType)
            {
                node = ((MemberType)node).MemberNameToken;
            }

            if (node is NamespaceDeclaration)
            {
                var nsd = ((NamespaceDeclaration)node);
                node = nsd.Identifiers.LastOrDefault(n => n.Name == memberName) ?? nsd.Identifiers.FirstOrDefault();
                if (node == null)
                {
                    return(null);
                }
            }

            if (node is TypeDeclaration && (searchedMembers.First() is IType))
            {
                node = ((TypeDeclaration)node).NameToken;
            }
            if (node is DelegateDeclaration)
            {
                node = ((DelegateDeclaration)node).NameToken;
            }

            if (node is EntityDeclaration && (searchedMembers.First() is IMember))
            {
                node = ((EntityDeclaration)node).NameToken;
            }

            if (node is ParameterDeclaration && (searchedMembers.First() is IParameter))
            {
                node = ((ParameterDeclaration)node).NameToken;
            }
            if (node is ConstructorDeclaration)
            {
                node = ((ConstructorDeclaration)node).NameToken;
            }
            if (node is DestructorDeclaration)
            {
                node = ((DestructorDeclaration)node).NameToken;
            }
            if (node is NamedArgumentExpression)
            {
                node = ((NamedArgumentExpression)node).NameToken;
            }
            if (node is NamedExpression)
            {
                node = ((NamedExpression)node).NameToken;
            }
            if (node is VariableInitializer)
            {
                node = ((VariableInitializer)node).NameToken;
            }

            if (node is IdentifierExpression)
            {
                node = ((IdentifierExpression)node).IdentifierToken;
            }

            var region = new DomRegion(fileName, node.StartLocation, node.EndLocation);

            var length = node is PrimitiveType ? keywordName.Length : node.EndLocation.Column - node.StartLocation.Column;

            return(new CSharpMemberReference(project, originalNode, syntaxTree, valid, region, editor.LocationToOffset(region.Begin), length));
        }
Пример #55
0
 public TypeNotFoundException(string className, DomRegion location, string fileName)
     : base(location, fileName)
 {
     this.ClassName = className;
 }
        static void AddTreeClassContents(TreeStore store, TreeIter parent, ParsedDocument parsedDocument, IType cls)
        {
            List <object> items = new List <object> ();

            foreach (object o in cls.Members)
            {
                items.Add(o);
            }

            items.Sort(ClassOutlineNodeComparer.CompareRegion);

            List <FoldingRegion> regions = new List <FoldingRegion> ();

            foreach (FoldingRegion fr in parsedDocument.UserRegions)
            {
                //check regions inside class
                if (cls.BodyRegion.Contains(fr.Region))
                {
                    regions.Add(fr);
                }
            }
            regions.Sort(delegate(FoldingRegion x, FoldingRegion y) { return(x.Region.CompareTo(y.Region)); });

            IEnumerator <FoldingRegion> regionEnumerator = regions.GetEnumerator();

            if (!regionEnumerator.MoveNext())
            {
                regionEnumerator = null;
            }

            FoldingRegion currentRegion = null;
            TreeIter      currentParent = parent;

            foreach (object item in items)
            {
                //no regions left; quick exit
                if (regionEnumerator != null)
                {
                    DomRegion itemRegion = ClassOutlineNodeComparer.GetRegion(item);

                    //advance to a region that could potentially contain this member
                    while (regionEnumerator != null && !OuterEndsAfterInner(regionEnumerator.Current.Region, itemRegion))
                    {
                        if (!regionEnumerator.MoveNext())
                        {
                            regionEnumerator = null;
                        }
                    }

                    //if member is within region, make sure it's the current parent.
                    //If not, move target iter back to class parent
                    if (regionEnumerator != null && regionEnumerator.Current.Region.Contains(itemRegion))
                    {
                        if (currentRegion != regionEnumerator.Current)
                        {
                            currentParent = store.AppendValues(parent, regionEnumerator.Current);
                            currentRegion = regionEnumerator.Current;
                        }
                    }
                    else
                    {
                        currentParent = parent;
                    }
                }


                TreeIter childIter = store.AppendValues(currentParent, item);
                if (item is IType)
                {
                    AddTreeClassContents(store, childIter, parsedDocument, (IType)item);
                }
            }
        }
 static bool OuterEndsAfterInner(DomRegion outer, DomRegion inner)
 {
     return((outer.End.Line > 1 && outer.End.Line > inner.End.Line) ||
            (outer.End.Line == inner.End.Line && outer.End.Column > inner.End.Column));
 }
Пример #58
0
 protected AbstractTypeParameter(ICompilation compilation, SymbolKind ownerType, int index, string name, VarianceModifier variance, IList <IAttribute> attributes, DomRegion region)
 {
     if (compilation == null)
     {
         throw new ArgumentNullException("compilation");
     }
     this.compilation = compilation;
     this.ownerType   = ownerType;
     this.index       = index;
     this.name        = name ?? ((this.OwnerType == SymbolKind.Method ? "!!" : "!") + index.ToString(CultureInfo.InvariantCulture));
     this.attributes  = attributes ?? EmptyList <IAttribute> .Instance;
     this.region      = region;
     this.variance    = variance;
 }
Пример #59
0
        /// <summary>
        /// Converts from the DOM region to a document region.
        /// </summary>
        public static DomRegion GetBodyRegionInDocument(IMethod method)
        {
            DomRegion bodyRegion = method.BodyRegion;

            return(new DomRegion(bodyRegion.BeginLine + 1, 1, bodyRegion.EndLine + 1, 1));
        }
Пример #60
0
 public override void InsertCodeAtEnd(DomRegion region, IDocument document, params AbstractNode[] nodes)
 {
     InsertCodeAfter(region.EndLine, document,
                     GetIndentation(document, region.BeginLine) + '\t', nodes);
 }