~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/mono-tools/gui-compare/CompareContext.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
using System;
27
27
using System.Collections.Generic;
28
28
using System.Threading;
 
29
using System.Linq;
29
30
 
30
31
namespace GuiCompare {
31
32
 
320
321
                        
321
322
                        List<CompNamed> reference_attrs = reference_container.GetAttributes ();
322
323
                        List<CompNamed> target_attrs = target_container.GetAttributes ();
323
 
                        
324
 
                        reference_attrs.Sort (CompNamed.Compare);
325
 
                        target_attrs.Sort (CompNamed.Compare);
 
324
 
 
325
                        Comparison<CompNamed> comp = (x, y) => {
 
326
                                var r = CompNamed.Compare (x, y);
 
327
                                if (r != 0)
 
328
                                        return r;
 
329
 
 
330
                                var xa = ((CompAttribute)x).Properties.Values.ToList ();
 
331
                                var ya = ((CompAttribute)y).Properties.Values.ToList ();
 
332
 
 
333
                                for (int i = 0; i < Math.Min (xa.Count, ya.Count); ++i) {
 
334
                                        r = xa[i].CompareTo (ya[i]);
 
335
                                        if (r != 0)
 
336
                                                return r;
 
337
                                }
 
338
 
 
339
                                return 0;
 
340
                        };
 
341
 
 
342
                        reference_attrs.Sort (comp);
 
343
                        target_attrs.Sort (comp);
326
344
                        
327
345
                        while (m < reference_attrs.Count || a < target_attrs.Count) {
328
346
                                if (m == reference_attrs.Count) {
329
347
                                        
330
 
                                        if (target_attrs[a].Name == "System.Diagnostics.DebuggerDisplayAttribute") {
331
 
                                                // Ignore additional debugging attributes in Mono source code
332
 
                                        } else {
 
348
                                        switch (target_attrs[a].Name) {
 
349
                                                case "System.Diagnostics.DebuggerDisplayAttribute":
 
350
                                                case "System.Runtime.CompilerServices.AsyncStateMachineAttribute":
 
351
                                                case "System.Runtime.CompilerServices.IteratorStateMachineAttribute":
 
352
                                                case "System.Diagnostics.DebuggerBrowsableAttribute":
 
353
                                                        // Ignore extra attributes in Mono source code
 
354
                                                break;
 
355
                                        default:
333
356
                                                AddExtra (parent, target_attrs[a]);
 
357
                                                break;
334
358
                                        }
335
359
                                        
336
360
                                        a++;
347
371
 
348
372
                                if (c == 0) {
349
373
                                        /* the names match, further investigation is required */
350
 
//                                      Console.WriteLine ("method {0} is in both, doing more comparisons", reference_list[m].Name);
351
374
                                        ComparisonNode comparison = target_attrs[a].GetComparisonNode();
352
375
                                        parent.AddChild (comparison);
353
 
                                        //CompareParameters (comparison, reference_list[m], target_namespace [target_list[a]]);
 
376
                                        CompareAttributeArguments (comparison, (CompAttribute)reference_attrs[m], (CompAttribute)target_attrs[a]);
354
377
                                        m++;
355
378
                                        a++;
356
379
                                }
366
389
                                }
367
390
                        }
368
391
                }
 
392
 
 
393
                void CompareAttributeArguments (ComparisonNode parent, CompAttribute referenceAttribute, CompAttribute actualAttribute)
 
394
                {
 
395
                        // Ignore all parameter differences for some attributes
 
396
                        switch (referenceAttribute.Name) {
 
397
                        case "System.Diagnostics.DebuggerDisplayAttribute":
 
398
                        case "System.Diagnostics.DebuggerTypeProxyAttribute":
 
399
                        case "System.Runtime.CompilerServices.CompilationRelaxationsAttribute":
 
400
                        case "System.Reflection.AssemblyFileVersionAttribute":
 
401
                        case "System.Reflection.AssemblyCompanyAttribute":
 
402
                        case "System.Reflection.AssemblyCopyrightAttribute":
 
403
                        case "System.Reflection.AssemblyProductAttribute":
 
404
                        case "System.Reflection.AssemblyTrademarkAttribute":
 
405
                        case "System.Reflection.AssemblyInformationalVersionAttribute":
 
406
                        case "System.Reflection.AssemblyKeyFileAttribute":
 
407
 
 
408
                        // Don't care about these for now
 
409
                        case "System.ComponentModel.EditorAttribute":
 
410
                        case "System.ComponentModel.DesignerAttribute":
 
411
                                return;
 
412
                        }
 
413
 
 
414
                        foreach (var entry in referenceAttribute.Properties) {
 
415
                                if (!actualAttribute.Properties.ContainsKey (entry.Key)) {
 
416
 
 
417
                                        //
 
418
                                        // Ignore missing value difference for default values
 
419
                                        //
 
420
                                        switch (referenceAttribute.Name) {
 
421
                                        case "System.AttributeUsageAttribute":
 
422
                                                // AllowMultiple defaults to false
 
423
                                                if (entry.Key == "AllowMultiple" && entry.Value == "False")
 
424
                                                        continue;
 
425
                                                // Inherited defaults to true
 
426
                                                if (entry.Key == "Inherited" && entry.Value == "True")
 
427
                                                        continue;
 
428
                                                break;
 
429
                                        case "System.ObsoleteAttribute":
 
430
                                                if (entry.Key == "IsError" && entry.Value == "False")
 
431
                                                        continue;
 
432
 
 
433
                                                if (entry.Key == "Message")
 
434
                                                        continue;
 
435
 
 
436
                                                break;
 
437
                                        }
 
438
 
 
439
                                        parent.AddError (String.Format ("Property `{0}' value is not set. Expected value: {1}", entry.Key, entry.Value));
 
440
                                        parent.Status = ComparisonStatus.Error;
 
441
                                        continue;
 
442
                                }
 
443
 
 
444
                                var target_value = actualAttribute.Properties[entry.Key];
 
445
 
 
446
                                switch (referenceAttribute.Name) {
 
447
                                case "System.Runtime.CompilerServices.TypeForwardedFromAttribute":
 
448
                                        if (entry.Key == "AssemblyFullName")
 
449
                                                target_value = target_value.Replace ("neutral", "Neutral");
 
450
                                        break;
 
451
                                case "System.Runtime.InteropServices.GuidAttribute":
 
452
                                        if (entry.Key == "Value")
 
453
                                                target_value = target_value.ToUpperInvariant ();
 
454
                                        break;
 
455
                                case "System.ObsoleteAttribute":
 
456
                                        if (entry.Key == "Message")
 
457
                                                continue;
 
458
 
 
459
                                        break;
 
460
                                }
 
461
 
 
462
                                if (target_value != entry.Value) {
 
463
                                        parent.AddError (String.Format ("Expected value `{0}' for attribute property `{1}' but found `{2}'", entry.Value, entry.Key, target_value));
 
464
                                        parent.Status = ComparisonStatus.Error;
 
465
                                }
 
466
                        }
 
467
 
 
468
                        
 
469
                        if (referenceAttribute.Properties.Count != actualAttribute.Properties.Count) {
 
470
                                foreach (var entry in actualAttribute.Properties) {
 
471
                                        if (!referenceAttribute.Properties.ContainsKey (entry.Key)) {
 
472
                                                parent.AddError (String.Format ("Property `{0}' should not be set", entry.Key));
 
473
                                                parent.Status = ComparisonStatus.Error;
 
474
                                                break;
 
475
                                        }
 
476
                                }
 
477
                        }
 
478
                        
 
479
 
 
480
                        return;
 
481
                }
369
482
                
370
483
                void CompareMembers (ComparisonNode parent,
371
484
                                     ICompMemberContainer reference_container, ICompMemberContainer target_container)
477
590
                                                                        break;
478
591
                                                                }
479
592
                                                        }
 
593
                                                        
 
594
                                                        if (m1[0].Name[0] == m2[0].Name[0]) {
 
595
                                                                CompareAttributes (comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[0]);
 
596
                                                                if (m1.Count > 1)
 
597
                                                                        CompareAttributes (comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[1]);
 
598
                                                        } else {
 
599
                                                                CompareAttributes (comparison, (ICompAttributeContainer)m1[0], (ICompAttributeContainer)m2[1]);
 
600
                                                                if (m1.Count > 1)
 
601
                                                                        CompareAttributes (comparison, (ICompAttributeContainer)m1[1], (ICompAttributeContainer)m2[0]);
 
602
                                                        }
480
603
                                                }
481
604
 
482
605
                                                // Compare indexer parameters