////
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
////

Before looking at providing runtime configuration based on conventions you first need to understand how to evaluate those conventions from a plugin. Every plugin has an implicit `application` variable which is an instance of the link:{api}grails/core/GrailsApplication.html[GrailsApplication] interface.

The `GrailsApplication` interface provides methods to evaluate the conventions within the project and internally stores references to all artifact classes within your application.

Artifacts implement the link:{api}grails/core/GrailsClass.html[GrailsClass] interface, which represents a Grails resource such as a controller or a tag library. For example to get all `GrailsClass` instances you can do:

[source,groovy]
----
for (grailsClass in application.allClasses) {
    println grailsClass.name
}
----

`GrailsApplication` has a few "magic" properties to narrow the type of artefact you are interested in. For example to access controllers you can use:

[source,groovy]
----
for (controllerClass in application.controllerClasses) {
    println controllerClass.name
}
----

The dynamic method conventions are as follows:

* `*Classes` - Retrieves all the classes for a particular artefact name. For example `application.controllerClasses`.
* `get*Class` - Retrieves a named class for a particular artefact. For example `application.getControllerClass("PersonController")`
* `is*Class` - Returns `true` if the given class is of the given artefact type. For example `application.isControllerClass(PersonController)`

The `GrailsClass` interface has a number of useful methods that let you further evaluate and work with the conventions. These include:

* `getPropertyValue` - Gets the initial value of the given property on the class
* `hasProperty` - Returns `true` if the class has the specified property
* `newInstance` - Creates a new instance of this class.
* `getName` -  Returns the logical name of the class in the application without the trailing convention part if applicable
* `getShortName` - Returns the short name of the class without package prefix
* `getFullName` - Returns the full name of the class in the application with the trailing convention part and with the package name
* `getPropertyName` - Returns the name of the class as a property name
* `getLogicalPropertyName` - Returns the logical property name of the class in the application without the trailing convention part if applicable
* `getNaturalName` - Returns the name of the property in natural terms (e.g. 'lastName' becomes 'Last Name')
* `getPackageName` - Returns the package name

For a full reference refer to the link:{api}grails/core/GrailsClass.html[javadoc API].
