Added container accessor to Castle.Core
[castle.git] / AspectSharp / AspectSharp.Lang / Steps / Types / PruneTypesStep.cs
blob66934fd9b1f73e3990774bf47ea790e6ae834da7
1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace AspectSharp.Lang.Steps.Types
17 using System;
19 using AopAlliance.Intercept;
21 using AspectSharp.Lang.AST;
23 /// <summary>
24 /// Summary description for PruneTypesStep.
25 /// </summary>
26 public class PruneTypesStep : AbstractVisitorStep
28 private static readonly String MIXIN_CANT_BE_INTERFACE = "The specified type for a mixin is an interface which is invalid";
29 private static readonly String INVALID_INTERCEPTOR = "The specified type for an interceptor doesn't implement the interceptor interface";
31 public override void Process(Context context, EngineConfiguration conf)
33 Init(context);
34 Visit(conf);
36 if (!context.HasErrors)
38 base.Process(context, conf);
42 #region AbstractVisitorStep overrides
44 public override void OnTargetTypeDefinition(TargetTypeDefinition targetType)
46 if (targetType.TargetStrategy == TargetStrategyEnum.SingleType)
48 AssertNotInterface(
49 targetType.LexicalInfo, targetType.SingleType.ResolvedType,
50 MIXIN_CANT_BE_INTERFACE);
52 else if (targetType.TargetStrategy == TargetStrategyEnum.Namespace)
55 else if (targetType.TargetStrategy == TargetStrategyEnum.Assignable)
58 else if (targetType.TargetStrategy == TargetStrategyEnum.Custom)
60 // TODO: Move IClassMatcher and etc to another assembly
61 // to prevent cyclic references.
62 // AssertAssignableFrom(
63 // targetType.LexicalInfo, typeof(IClassMatcher),
64 // targetType.SingleType.ResolvedType, MIXIN_CANT_BE_INTERFACE);
68 public override void OnMixinDefinition(MixinDefinition mixin)
70 AssertNotInterface(mixin.LexicalInfo, mixin.TypeReference.ResolvedType, MIXIN_CANT_BE_INTERFACE);
73 public override void OnInterceptorDefinition(InterceptorDefinition interceptor)
75 AssertIsInterceptor(interceptor.LexicalInfo, interceptor.TypeReference.ResolvedType, INVALID_INTERCEPTOR);
78 public override void OnMixinEntryDefinition(MixinEntryDefinition mixin)
80 AssertNotInterface(mixin.LexicalInfo, mixin.TypeReference.ResolvedType, MIXIN_CANT_BE_INTERFACE);
83 public override void OnInterceptorEntryDefinition(InterceptorEntryDefinition interceptor)
85 AssertIsInterceptor(interceptor.LexicalInfo, interceptor.TypeReference.ResolvedType, INVALID_INTERCEPTOR);
88 #endregion
90 private void AssertNotInterface(LexicalInfo info, Type type, String message)
92 if (type.IsInterface)
94 Context.RaiseErrorEvent(info, message);
98 private void AssertIsInterceptor(LexicalInfo info, Type type, String message)
100 if (!typeof (IInterceptor).IsAssignableFrom(type))
102 Context.RaiseErrorEvent(info, message);