Added support for declaring exceptions on shadow interface methods.

This commit is contained in:
jfrijters 2011-06-27 13:15:17 +00:00
Родитель 9b9f9943bf
Коммит c742dbb2d9
4 изменённых файлов: 46 добавлений и 13 удалений

Просмотреть файл

@ -1181,11 +1181,6 @@ namespace IKVM.Internal
{
throw new InvalidOperationException(typeWrapper.Name + "." + m.Name + m.Sig);
}
if(m.throws != null)
{
// TODO we need a place to stick the declared exceptions
throw new NotImplementedException();
}
// if any of the remapped types has a body for this interface method, we need a helper method
// to special invocation through this interface for that type
List<IKVM.Internal.MapXml.Class> specialCases = null;
@ -1207,7 +1202,20 @@ namespace IKVM.Internal
}
}
}
AttributeHelper.SetRemappedInterfaceMethod(typeWrapper.typeBuilder, m.Name, m.@override.Name);
string[] throws;
if (m.throws == null)
{
throws = new string[0];
}
else
{
throws = new string[m.throws.Length];
for (int i = 0; i < throws.Length; i++)
{
throws[i] = m.throws[i].Class;
}
}
AttributeHelper.SetRemappedInterfaceMethod(typeWrapper.typeBuilder, m.Name, m.@override.Name, throws);
MethodBuilder helper = null;
if(specialCases != null)
{

Просмотреть файл

@ -400,7 +400,20 @@ static class NetExp
if (mb != null)
{
ThrowsAttribute throws = AttributeHelper.GetThrows(mb);
if (throws != null)
if (throws == null)
{
string[] throwsArray = mw.GetDeclaredExceptions();
if (throwsArray != null && throwsArray.Length > 0)
{
IKVM.StubGen.ExceptionsAttribute attrib = new IKVM.StubGen.ExceptionsAttribute(writer);
foreach (string ex in throwsArray)
{
attrib.Add(ex.Replace('.', '/'));
}
m.AddAttribute(attrib);
}
}
else
{
IKVM.StubGen.ExceptionsAttribute attrib = new IKVM.StubGen.ExceptionsAttribute(writer);
if (throws.classes != null)

Просмотреть файл

@ -1085,7 +1085,7 @@ namespace IKVM.Internal
foreach(CustomAttributeData cad in CustomAttributeData.__GetCustomAttributes(type, typeofRemappedInterfaceMethodAttribute, false))
{
IList<CustomAttributeTypedArgument> args = cad.ConstructorArguments;
attrs.Add(new RemappedInterfaceMethodAttribute((string)args[0].Value, (string)args[1].Value));
attrs.Add(new RemappedInterfaceMethodAttribute((string)args[0].Value, (string)args[1].Value, DecodeArray<string>(args[2])));
}
return attrs.ToArray();
#endif
@ -1225,9 +1225,9 @@ namespace IKVM.Internal
typeBuilder.SetCustomAttribute(new CustomAttributeBuilder(remappedTypeAttribute, new object[] { shadowType }));
}
internal static void SetRemappedInterfaceMethod(TypeBuilder typeBuilder, string name, string mappedTo)
internal static void SetRemappedInterfaceMethod(TypeBuilder typeBuilder, string name, string mappedTo, string[] throws)
{
CustomAttributeBuilder cab = new CustomAttributeBuilder(typeofRemappedInterfaceMethodAttribute.GetConstructor(new Type[] { Types.String, Types.String }), new object[] { name, mappedTo });
CustomAttributeBuilder cab = new CustomAttributeBuilder(typeofRemappedInterfaceMethodAttribute.GetConstructor(new Type[] { Types.String, Types.String, Types.String.MakeArrayType() }), new object[] { name, mappedTo, throws });
typeBuilder.SetCustomAttribute(cab);
}
@ -3353,7 +3353,9 @@ namespace IKVM.Internal
mbHelper = method;
}
}
list.Add(new CompiledRemappedMethodWrapper(this, m.Name, sig, method, retType, paramTypes, modifiers, false, mbHelper, null));
MethodWrapper mw = new CompiledRemappedMethodWrapper(this, m.Name, sig, method, retType, paramTypes, modifiers, false, mbHelper, null);
mw.SetDeclaredExceptions(m.Throws);
list.Add(mw);
}
}
SetMethods(list.ToArray());

Просмотреть файл

@ -277,16 +277,18 @@ namespace IKVM.Attributes
{
}
[AttributeUsage(AttributeTargets.Method)]
[AttributeUsage(AttributeTargets.Interface)]
public sealed class RemappedInterfaceMethodAttribute : Attribute
{
private string name;
private string mappedTo;
private string[] throws;
public RemappedInterfaceMethodAttribute(string name, string mappedTo)
public RemappedInterfaceMethodAttribute(string name, string mappedTo, string[] throws)
{
this.name = name;
this.mappedTo = mappedTo;
this.throws = throws;
}
public string Name
@ -304,6 +306,14 @@ namespace IKVM.Attributes
return mappedTo;
}
}
public string[] Throws
{
get
{
return throws;
}
}
}
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]