com.societegenerale.commons.plugin.rules.FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arch-unit-build-plugin-core Show documentation
Show all versions of arch-unit-build-plugin-core Show documentation
The core logic for Maven or Gradle ArchUnit plugin
package com.societegenerale.commons.plugin.rules;
import java.util.Collection;
import com.societegenerale.commons.plugin.service.ScopePathProvider;
import com.societegenerale.commons.plugin.utils.ArchUtils;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.fields;
/**
*
* Final Non Static Fields have to be Static Final Fields
*
* @see why-should-data-fields-be-static-and-final
*
* @see Public
* constants and fields initialized at declaration should be "static final"
* rather than merely "final"
*/
public class FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTest implements ArchRuleTest {
public static final String FINAL_NON_STATIC_FIELDS_VIOLATION_MESSAGE = "you are duplicating its value for every instance of the class, uselessly increasing the amount of memory required to execute the application.";
@Override
public void execute(String packagePath, ScopePathProvider scopePathProvider, Collection excludedPaths) {
fields().that().areFinal().and().areNotStatic().should().beStatic().andShould().beFinal()
.because(FINAL_NON_STATIC_FIELDS_VIOLATION_MESSAGE).check(ArchUtils.importAllClassesInPackage(scopePathProvider.getMainClassesPath(),packagePath,
excludedPaths));
}
}