1 // Copyright 2004-2007 Castle Project - http://www.castleproject.org/
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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
19 using AopAlliance
.Intercept
;
21 using AspectSharp
.Lang
.AST
;
24 /// Summary description for PruneTypesStep.
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
)
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
)
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
);
90 private void AssertNotInterface(LexicalInfo info
, Type type
, String message
)
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
);