예제 #1
0
        public override bool Process <_T0>(HashSet <_T0> annotations, IRoundEnvironment roundEnv)
        {
            if (!CheckClassNameConstants())
            {
                return(true);
            }
            IList <Tuple <RuleDependency, IElement> > dependencies = GetDependencies(roundEnv);
            IDictionary <ITypeMirror, IList <Tuple <RuleDependency, IElement> > > recognizerDependencies = new Dictionary <ITypeMirror, IList <Tuple <RuleDependency, IElement> > >();

            foreach (Tuple <RuleDependency, IElement> dependency in dependencies)
            {
                ITypeMirror recognizerType = GetRecognizerType(dependency.Item1);
                IList <Tuple <RuleDependency, IElement> > list = recognizerDependencies.Get(recognizerType);
                if (list == null)
                {
                    list = new List <Tuple <RuleDependency, IElement> >();
                    recognizerDependencies.Put(recognizerType, list);
                }
                list.Add(dependency);
            }
            foreach (KeyValuePair <ITypeMirror, IList <Tuple <RuleDependency, IElement> > > entry in recognizerDependencies.EntrySet())
            {
                processingEnv.GetMessager().PrintMessage(Diagnostic.Kind.Note, string.Format("ANTLR 4: Validating {0} dependencies on rules in {1}.", entry.Value.Count, entry.Key.ToString()));
                CheckDependencies(entry.Value, entry.Key);
            }
            return(true);
        }
예제 #2
0
        public static IList <Tuple <RuleDependency, IElement> > GetDependencies(IRoundEnvironment roundEnv)
        {
            IList <Tuple <RuleDependency, IElement> > result = new List <Tuple <RuleDependency, IElement> >();
            HashSet <IElement> elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependency));

            foreach (IElement element in elements)
            {
                RuleDependency dependency = element.GetAnnotation <RuleDependency>();
                if (dependency == null)
                {
                    continue;
                }
                result.Add(Tuple.Create(dependency, element));
            }
            elements = roundEnv.GetElementsAnnotatedWith(typeof(RuleDependencies));
            foreach (IElement element_1 in elements)
            {
                RuleDependencies dependencies = element_1.GetAnnotation <RuleDependencies>();
                if (dependencies == null || dependencies.Value() == null)
                {
                    continue;
                }
                foreach (RuleDependency dependency in dependencies.Value())
                {
                    result.Add(Tuple.Create(dependency, element_1));
                }
            }
            return(result);
        }