Skip to content

Commit

Permalink
resolved code violations
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed Jul 23, 2021
1 parent e8293b3 commit c33383a
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ class IntegrationSpec extends Specification {
given:
File root = initRootDirectory()
when:
generator.generate(root)
int generated = generator.generate(root)
then:
noExceptionThrown()

generated == 1

new File(root, 'micronaut/grails/example/User.groovy').exists()
new File(root, 'micronaut/grails/example/UserRepository.groovy').exists()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.agorapulse.micronaut.grails.test;
package com.agorapulse.micronaut.grails.test

import org.codehaus.groovy.transform.GroovyASTTransformationClass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.ApplicationContext
import org.springframework.context.ApplicationContextAware
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.web.WebAppConfiguration

import java.lang.reflect.Modifier
/*
Expand Down Expand Up @@ -69,6 +68,35 @@ import java.lang.reflect.Modifier
*/
@CompileStatic
@GroovyASTTransformation(phase = CompilePhase.CANONICALIZATION)
@SuppressWarnings([
'AbcMetric',
'BlockEndsWithBlankLine',
'BlockStartsWithBlankLine',
'CatchException',
'ClassForName',
'ConsecutiveBlankLines',
'ConsecutiveBlankLines',
'DuplicateStringLiteral',
'EmptyCatchBlock',
'ExplicitCallToEqualsMethod',
'GStringExpressionWithinString',
'IfStatementBraces',
'Instanceof',
'LineLength',
'MissingBlankLineAfterImports',
'MissingBlankLineAfterPackage',
'NoDef',
'NoWildcardImports',
'SpaceAfterCatch',
'SpaceAfterIf',
'ThrowRuntimeException',
'UnnecessaryCast',
'UnnecessaryGString',
'UnnecessaryGetter',
'UnnecessaryPublicModifier',
'VariableName',
'VariableTypeRequired',
])
class MicronautGrailsIntegrationTestMixinTransformation implements ASTTransformation {

static final ClassNode MY_TYPE = new ClassNode(MicronautGrailsIntegration)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ import javax.persistence.PrePersist
import javax.persistence.PreRemove
import javax.persistence.PreUpdate

/**
* Experimental generator of JPA entities based on GORM entities.
*/
@CompileStatic
@SuppressWarnings(['MethodSize'])
@SuppressWarnings(['MethodSize', 'DuplicateStringLiteral'])
class MicronautJpaGenerator {

private static final Map<String, Class> GORM_HOOKS_TO_ANNOTATIONS = [
Expand All @@ -60,7 +63,8 @@ class MicronautJpaGenerator {
this.datastore = datastore
}

void generate(File root) {
@SuppressWarnings('NestedForLoop')
int generate(File root) {
Collection<PersistentEntity> entities = datastore.mappingContext.persistentEntities
entities.each { PersistentEntity entity ->
File packageDirectory = new File(root, (entity.javaClass.package.name).replace('.', File.separator))
Expand All @@ -82,15 +86,22 @@ class MicronautJpaGenerator {
}
}

requiredEnums.each {
copyEnum(root, it)
requiredEnums.each { Class enumType ->
copyEnum(root, enumType)
}


println "Generated files for ${entities.size()} entities in ${root.toURI().toURL().toString()}"
return entities.size()
}

@SuppressWarnings(['AbcMetric', 'UnnecessaryObjectReferences', 'ImplicitClosureParameter', 'Instanceof', 'LineLength', 'MethodSize'])
@SuppressWarnings([
'AbcMetric',
'UnnecessaryObjectReferences',
'ImplicitClosureParameter',
'Instanceof',
'LineLength',
'MethodSize',
'UnnecessaryCollectCall',
])
String generateEntity(PersistentEntity entity) {
List<UnifiedProperty> unifiedProperties = collectUnifiedProperties(entity)
Set<String> imports = new TreeSet<>(unifiedProperties.collect {
Expand Down Expand Up @@ -520,7 +531,6 @@ class MicronautJpaGenerator {
${enumValues.join(', ')};
}
""".stripIndent().trim()

}

@SuppressWarnings('ImplicitClosureParameter')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import org.grails.orm.hibernate.cfg.PropertyConfig
import javax.persistence.EnumType
import javax.persistence.FetchType

/**
* This class unifies access to PersistentProperty, ConstrainedProperty and Property objects which shares some common interactions.
*/
@CompileStatic
@SuppressWarnings('MethodCount')
class UnifiedProperty {
Expand Down Expand Up @@ -104,6 +107,7 @@ class UnifiedProperty {
return constrainedProperty.notEqual
}

@SuppressWarnings('LineLength')
Integer getMaxSize() {
return (mappingProperty.maxSize ?: constrainedProperty.maxSize ?: (persistentProperty.type == String && !sqlType?.contains('text') ? 255 : null)) as Integer
}
Expand Down Expand Up @@ -160,40 +164,45 @@ class UnifiedProperty {

EnumType getEnumType() {
if (!Enum.isAssignableFrom(persistentProperty.type)) {
return null;
return null
}

return mappingProperty.enumTypeObject ?: EnumType.STRING
}

@SuppressWarnings('Instanceof')
String getSqlType() {
if (mappingProperty instanceof PropertyConfig) {
return mappingProperty.sqlType ?: mappingProperty.type
}
return null
}

@SuppressWarnings('Instanceof')
String getSqlColumnName() {
if (mappingProperty instanceof PropertyConfig && mappingProperty.columns) {
return mappingProperty.columns.first().name
}
return null
}

@SuppressWarnings('Instanceof')
JoinTable getJoinTable() {
if (mappingProperty instanceof PropertyConfig && mappingProperty.joinTable) {
return mappingProperty.joinTable
}
return null
}

@SuppressWarnings('Instanceof')
String getSort() {
if (mappingProperty instanceof PropertyConfig && mappingProperty.sort) {
return mappingProperty.sort
}
return null
}

@SuppressWarnings('Instanceof')
String getOrder() {
if (mappingProperty instanceof PropertyConfig && mappingProperty.order) {
return mappingProperty.order
Expand Down

0 comments on commit c33383a

Please sign in to comment.