add lint pass to check whether types with ISync actually have any [Sync] members

This commit is contained in:
Chris Forbes
2011-07-11 10:08:07 +12:00
committed by Paul Chote
parent 513b852a67
commit 5633d84d21
8 changed files with 54 additions and 6 deletions

View File

@@ -217,7 +217,7 @@ namespace OpenRA.Traits
Stance oldStance, Stance newStance);
}
public interface ILintPass { void Run(Action<string> emitError); }
public interface ILintPass { void Run(Action<string> emitError, Action<string> emitWarning); }
public interface IObjectivesPanel { string ObjectivesPanel { get; } }
}

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Mods.RA
}
}
public abstract class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IOrderVoice, ISync
public abstract class AttackBase : IIssueOrder, IResolveOrder, ITick, IExplodeModifier, IOrderVoice
{
public bool IsAttacking { get; internal set; }

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
{
class CheckAutotargetWiring : ILintPass
{
public void Run(Action<string> emitError)
public void Run(Action<string> emitError, Action<string> emitWarning)
{
foreach( var i in Rules.Info )
{

View 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>());
}
}
}

View File

@@ -19,7 +19,7 @@ namespace OpenRA.Mods.RA
{
class LintBuildablePrerequisites : ILintPass
{
public void Run(Action<string> emitError)
public void Run(Action<string> emitError, Action<string> emitWarning)
{
var providedPrereqs = Rules.Info.Keys.Concat(
Rules.Info.SelectMany( a => a.Value.Traits

View File

@@ -71,6 +71,7 @@
<Compile Include="GivesBounty.cs" />
<Compile Include="Lint\LintBuildablePrerequisites.cs" />
<Compile Include="Lint\CheckAutotargetWiring.cs" />
<Compile Include="Lint\CheckSyncAnnotations.cs" />
<Compile Include="ProductionBar.cs" />
<Compile Include="Render\RenderEditorOnly.cs" />
<Compile Include="SmokeTrailWhenDamaged.cs" />

View File

@@ -84,7 +84,7 @@ namespace OpenRA.Mods.RA
public override object Create(ActorInitializer init) { return new GpsPower(init.self, this); }
}
class GpsPower : SupportPower, INotifyKilled, ISync, INotifyStanceChanged, INotifySold, INotifyCapture
class GpsPower : SupportPower, INotifyKilled, INotifyStanceChanged, INotifySold, INotifyCapture
{
GpsWatcher owner;

View File

@@ -28,6 +28,11 @@ namespace RALint
++errors;
}
static void EmitWarning(string e)
{
Console.WriteLine("RALint(1,1): Warning: {0}", e);
}
static int Main(string[] args)
{
try
@@ -52,7 +57,7 @@ namespace RALint
Console.WriteLine("CustomPass: {0}".F(customPassType.ToString()));
customPass.Run(EmitError);
customPass.Run(EmitError, EmitWarning);
}
if (errors > 0)