Detecting view names with possible wrong capitalization

Unless we deal with abbreviations or names, we want to capitalize only the first word of titles in Glamorous Toolkit. Still, while using the environment, we noticed that there are a number of places that do not obide by this rule.

Of course, seeing some problems only shows us that there is a problem. But to address it we want to understand the magnitude. So, we write a script.

We start with detecting the view methods:

all := #gtView gtPragmas contents
  

From the methods, we want to extract the strings that come from a message like title: 'Something':

titleNodes := all
		collect: [ :pragma | 
			pragma method ast allChildren
				detect: [ :each | each isMessage and: [ each selector value = #title: ] ]
				ifFound: [ :each | each arguments anyOne gtWithAllChildren detect: #isLiteralNode ifNone: [ nil ] ]
				ifNone: [ nil ] ]
		thenReject: #isNil.
  

The result is a collection of abstract syntax tree nodes. From these, we can select those that have at least one word that is not the first and that is capitalized:

titleNodes
	select: [ :each | 
		tokens := each value findTokens: {Character space}.
		tokens size > 1
			and: [ tokens allButFirst anySatisfy: [ :token | token first isUppercase ] ] ]
  

This results in a list of abstract syntax tree nodes that can be browsed.