add lint pass to check whether types with ISync actually have any [Sync] members
This commit is contained in:
@@ -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; } }
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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 )
|
||||
{
|
||||
|
||||
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>());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user