add lint pass to check whether types with ISync actually have any [Sync] members
This commit is contained in:
42
OpenRA.Mods.RA/Lint/CheckSyncAnnotations.cs
Normal file
42
OpenRA.Mods.RA/Lint/CheckSyncAnnotations.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA
|
||||
{
|
||||
class CheckSyncAnnotations : ILintPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning)
|
||||
{
|
||||
/* first, check all the types implementing ISync */
|
||||
foreach (var t in Game.modData.ObjectCreator.GetTypesImplementing<ISync>())
|
||||
if (!HasAnySyncFields(t))
|
||||
emitWarning("{0} has ISync but nothing marked with [Sync]".F(t.Name));
|
||||
}
|
||||
|
||||
bool HasAnySyncFields(Type t)
|
||||
{
|
||||
var flags = BindingFlags.Public | BindingFlags.NonPublic
|
||||
| BindingFlags.Instance | BindingFlags.FlattenHierarchy;
|
||||
|
||||
var fs = t.GetFields(flags);
|
||||
var ps = t.GetProperties(flags);
|
||||
return fs.Any(f => f.HasAttribute<SyncAttribute>()) ||
|
||||
ps.Any(p => p.HasAttribute<SyncAttribute>());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user