@Test public void testFindAncestorOfType() throws Exception { TeamAppsDtoModel model = createModel("interface I { subevent i(int i); }"); TeamAppsDtoParser.SubEventDeclarationContext subEvent = model.getSubEventDeclarations().get(0); TeamAppsDtoParser.InterfaceDeclarationContext result = model.findAncestorOfType(subEvent, TeamAppsDtoParser.InterfaceDeclarationContext.class); assertEquals("I", result.Identifier().getText()); }
public static <T extends RuleContext> T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType) { while (ruleContext != null) { ruleContext = ruleContext.getParent(); if (ancestorType.isInstance(ruleContext)) { return (T) ruleContext; } } return null; }
TeamAppsDtoModel { public static <T extends RuleContext> T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType) { while (ruleContext != null) { ruleContext = ruleContext.getParent(); if (ancestorType.isInstance(ruleContext)) { return (T) ruleContext; } } return null; } }
TeamAppsDtoModel { public static <T extends RuleContext> T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType) { while (ruleContext != null) { ruleContext = ruleContext.getParent(); if (ancestorType.isInstance(ruleContext)) { return (T) ruleContext; } } return null; } TeamAppsDtoModel(ClassCollectionContext classCollectionContext);  TeamAppsDtoModel(List<ClassCollectionContext> classCollectionContexts); }
TeamAppsDtoModel { public static <T extends RuleContext> T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType) { while (ruleContext != null) { ruleContext = ruleContext.getParent(); if (ancestorType.isInstance(ruleContext)) { return (T) ruleContext; } } return null; } TeamAppsDtoModel(ClassCollectionContext classCollectionContext);  TeamAppsDtoModel(List<ClassCollectionContext> classCollectionContexts); List<ClassDeclarationContext> getClassDeclarations(); List<InterfaceDeclarationContext> getInterfaceDeclarations(); List<EnumDeclarationContext> getEnumDeclarations(); List<EventDeclarationContext> getEventDeclarations(); List<CommandDeclarationContext> getCommandDeclarations(); List<SubEventDeclarationContext> getSubEventDeclarations(); List<SubCommandDeclarationContext> getSubCommandDeclarations(); List<ParserRuleContext> getClassesAndInterfacesReferencedForSubEvents(); ClassDeclarationContext findReferencedClass(TypeContext typeContext); InterfaceDeclarationContext findReferencedInterface(TypeContext typeContext); ClassDeclarationContext findClassByName(String className, boolean throwExceptionIfNotFound); EnumDeclarationContext findReferencedEnum(TypeContext typeContext); static T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType); List<ClassDeclarationContext> findAllSuperClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findSelfAndAllSuperClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findAllSubClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findAllSubClasses(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllSubInterfaces(InterfaceDeclarationContext interfaceContext); List<PropertyDeclarationContext> findAllProperties(ClassDeclarationContext clazzContext); List<PropertyDeclarationContext> findAllProperties(InterfaceDeclarationContext interfaceContext); Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor); List<PropertyDeclarationContext> filterRequiredProperties(List<PropertyDeclarationContext> propertyDeclarations, boolean required); ClassDeclarationContext findSuperClass(ClassDeclarationContext clazzContext); List<InterfaceDeclarationContext> findAllSuperInterfaces(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findSuperInterfaces(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllImplementedInterfaces(ClassDeclarationContext classContext); List<InterfaceDeclarationContext> getDirectlyImplementedInterfaces(ClassDeclarationContext classContext); InterfaceDeclarationContext findInterfaceByName(String name, boolean throwExceptionIfNotFound); List<ClassDeclarationContext> findAllImplementingClasses(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllSuperInterfacesAndSelf(InterfaceDeclarationContext interfaceContext); List<PropertyDeclarationContext> getSimplePropertiesSortedByRelevance(List<PropertyDeclarationContext> properties); List<PropertyDeclarationContext> findPropertiesNotImplementedBySuperClasses(ClassDeclarationContext classContext); List<ParserRuleContext> findSuperClassAndDirectlyImplementedInterfaces(ClassDeclarationContext classContext); List<CommandDeclarationContext> getAllCommands(ClassDeclarationContext classContext); List<CommandDeclarationContext> getAllCommands(InterfaceDeclarationContext interfaceContext); List<EventDeclarationContext> getAllEvents(ClassDeclarationContext classContext); List<EventDeclarationContext> getAllEvents(InterfaceDeclarationContext interfaceContext); List<SubCommandDeclarationContext> getAllSubCommands(ClassDeclarationContext classContext); List<SubCommandDeclarationContext> getAllSubCommands(InterfaceDeclarationContext interfaceContext); List<SubEventDeclarationContext> getAllSubEvents(ClassDeclarationContext classContext); List<SubEventDeclarationContext> getAllSubEvents(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithCommands(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithSubCommands(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithEvents(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithSubEvents(ClassDeclarationContext classContext); List<ParserRuleContext> getSuperInterfacesWithCommands(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithSubCommands(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithEvents(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithSubEvents(InterfaceDeclarationContext interfaceContext); boolean interfaceOrDescendantHasSubCommandDeclarations(InterfaceDeclarationContext interf); boolean classOrSubClassHasSubCommandDeclarations(ClassDeclarationContext classContext); boolean interfaceOrDescendantHasSubEventDeclarations(InterfaceDeclarationContext interf); boolean classOrSubClassHasSubEventDeclarations(ClassDeclarationContext classContext); List<SubEventDeclarationContext> findAllSubEventsInHierarchy(ClassDeclarationContext classContext); List<SubEventDeclarationContext> findAllSubEventsInHierarchy(InterfaceDeclarationContext classContext); boolean isDescendantOfClassOrInterfaceReferencedForSubEvents(ClassDeclarationContext classContext); boolean isDescendantOfClassOrInterfaceReferencedForSubEvents(InterfaceDeclarationContext interfaceContext); static ParserRuleContext getDeclaringClassOrInterface(ParserRuleContext element); static String getDeclaringClassOrInterfaceName(ParserRuleContext element); List<ParserRuleContext> getAllClassesAndInterfacesWithEvents(); List<ParserRuleContext> getAllClassesAndInterfacesWithSubEvents(); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(ClassDeclarationContext classContext); List<EnumDeclarationContext> findAllReferencedEnums(ClassDeclarationContext classContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(InterfaceDeclarationContext interfaceContext); List<EnumDeclarationContext> findAllReferencedEnums(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(EventDeclarationContext eventContext); List<EnumDeclarationContext> findAllReferencedEnums(EventDeclarationContext eventDeclarationContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(SubEventDeclarationContext eventContext); List<EnumDeclarationContext> findAllReferencedEnums(SubEventDeclarationContext eventDeclarationContext); List<ParserRuleContext> findAllClassesInterfacesAndEnumsReferencedByEvents(); List<ParserRuleContext> findAllClassesInterfacesAndEnumsReferencedBySubEvents(); List<PropertyDeclarationContext> findAllNotYetImplementedProperties(ClassDeclarationContext classContext); static boolean isReferenceType(TypeContext type); boolean isReferenceableClass(ClassDeclarationContext clazz); boolean isReferenceableBaseClass(ClassDeclarationContext clazz); ClassDeclarationContext findSelfNearestAncestorClassWithReferenceableAttribute(ClassDeclarationContext clazz); Object getReferenceableProperties(ClassDeclarationContext classContext); }
TeamAppsDtoModel { public static <T extends RuleContext> T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType) { while (ruleContext != null) { ruleContext = ruleContext.getParent(); if (ancestorType.isInstance(ruleContext)) { return (T) ruleContext; } } return null; } TeamAppsDtoModel(ClassCollectionContext classCollectionContext);  TeamAppsDtoModel(List<ClassCollectionContext> classCollectionContexts); List<ClassDeclarationContext> getClassDeclarations(); List<InterfaceDeclarationContext> getInterfaceDeclarations(); List<EnumDeclarationContext> getEnumDeclarations(); List<EventDeclarationContext> getEventDeclarations(); List<CommandDeclarationContext> getCommandDeclarations(); List<SubEventDeclarationContext> getSubEventDeclarations(); List<SubCommandDeclarationContext> getSubCommandDeclarations(); List<ParserRuleContext> getClassesAndInterfacesReferencedForSubEvents(); ClassDeclarationContext findReferencedClass(TypeContext typeContext); InterfaceDeclarationContext findReferencedInterface(TypeContext typeContext); ClassDeclarationContext findClassByName(String className, boolean throwExceptionIfNotFound); EnumDeclarationContext findReferencedEnum(TypeContext typeContext); static T findAncestorOfType(RuleContext ruleContext, Class<T> ancestorType); List<ClassDeclarationContext> findAllSuperClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findSelfAndAllSuperClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findAllSubClasses(ClassDeclarationContext clazzContext); List<ClassDeclarationContext> findAllSubClasses(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllSubInterfaces(InterfaceDeclarationContext interfaceContext); List<PropertyDeclarationContext> findAllProperties(ClassDeclarationContext clazzContext); List<PropertyDeclarationContext> findAllProperties(InterfaceDeclarationContext interfaceContext); Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor); List<PropertyDeclarationContext> filterRequiredProperties(List<PropertyDeclarationContext> propertyDeclarations, boolean required); ClassDeclarationContext findSuperClass(ClassDeclarationContext clazzContext); List<InterfaceDeclarationContext> findAllSuperInterfaces(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findSuperInterfaces(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllImplementedInterfaces(ClassDeclarationContext classContext); List<InterfaceDeclarationContext> getDirectlyImplementedInterfaces(ClassDeclarationContext classContext); InterfaceDeclarationContext findInterfaceByName(String name, boolean throwExceptionIfNotFound); List<ClassDeclarationContext> findAllImplementingClasses(InterfaceDeclarationContext interfaceContext); List<InterfaceDeclarationContext> findAllSuperInterfacesAndSelf(InterfaceDeclarationContext interfaceContext); List<PropertyDeclarationContext> getSimplePropertiesSortedByRelevance(List<PropertyDeclarationContext> properties); List<PropertyDeclarationContext> findPropertiesNotImplementedBySuperClasses(ClassDeclarationContext classContext); List<ParserRuleContext> findSuperClassAndDirectlyImplementedInterfaces(ClassDeclarationContext classContext); List<CommandDeclarationContext> getAllCommands(ClassDeclarationContext classContext); List<CommandDeclarationContext> getAllCommands(InterfaceDeclarationContext interfaceContext); List<EventDeclarationContext> getAllEvents(ClassDeclarationContext classContext); List<EventDeclarationContext> getAllEvents(InterfaceDeclarationContext interfaceContext); List<SubCommandDeclarationContext> getAllSubCommands(ClassDeclarationContext classContext); List<SubCommandDeclarationContext> getAllSubCommands(InterfaceDeclarationContext interfaceContext); List<SubEventDeclarationContext> getAllSubEvents(ClassDeclarationContext classContext); List<SubEventDeclarationContext> getAllSubEvents(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithCommands(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithSubCommands(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithEvents(ClassDeclarationContext classContext); List<ParserRuleContext> superClassAndDirectlyImplementedInterfacesWithSubEvents(ClassDeclarationContext classContext); List<ParserRuleContext> getSuperInterfacesWithCommands(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithSubCommands(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithEvents(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> getSuperInterfacesWithSubEvents(InterfaceDeclarationContext interfaceContext); boolean interfaceOrDescendantHasSubCommandDeclarations(InterfaceDeclarationContext interf); boolean classOrSubClassHasSubCommandDeclarations(ClassDeclarationContext classContext); boolean interfaceOrDescendantHasSubEventDeclarations(InterfaceDeclarationContext interf); boolean classOrSubClassHasSubEventDeclarations(ClassDeclarationContext classContext); List<SubEventDeclarationContext> findAllSubEventsInHierarchy(ClassDeclarationContext classContext); List<SubEventDeclarationContext> findAllSubEventsInHierarchy(InterfaceDeclarationContext classContext); boolean isDescendantOfClassOrInterfaceReferencedForSubEvents(ClassDeclarationContext classContext); boolean isDescendantOfClassOrInterfaceReferencedForSubEvents(InterfaceDeclarationContext interfaceContext); static ParserRuleContext getDeclaringClassOrInterface(ParserRuleContext element); static String getDeclaringClassOrInterfaceName(ParserRuleContext element); List<ParserRuleContext> getAllClassesAndInterfacesWithEvents(); List<ParserRuleContext> getAllClassesAndInterfacesWithSubEvents(); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(ClassDeclarationContext classContext); List<EnumDeclarationContext> findAllReferencedEnums(ClassDeclarationContext classContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(InterfaceDeclarationContext interfaceContext); List<EnumDeclarationContext> findAllReferencedEnums(InterfaceDeclarationContext interfaceContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(EventDeclarationContext eventContext); List<EnumDeclarationContext> findAllReferencedEnums(EventDeclarationContext eventDeclarationContext); List<ParserRuleContext> findAllReferencedClassesAndInterfaces(SubEventDeclarationContext eventContext); List<EnumDeclarationContext> findAllReferencedEnums(SubEventDeclarationContext eventDeclarationContext); List<ParserRuleContext> findAllClassesInterfacesAndEnumsReferencedByEvents(); List<ParserRuleContext> findAllClassesInterfacesAndEnumsReferencedBySubEvents(); List<PropertyDeclarationContext> findAllNotYetImplementedProperties(ClassDeclarationContext classContext); static boolean isReferenceType(TypeContext type); boolean isReferenceableClass(ClassDeclarationContext clazz); boolean isReferenceableBaseClass(ClassDeclarationContext clazz); ClassDeclarationContext findSelfNearestAncestorClassWithReferenceableAttribute(ClassDeclarationContext clazz); Object getReferenceableProperties(ClassDeclarationContext classContext);  }