All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.societegenerale.commons.plugin.rules.FinalNonStaticFieldsHaveToBeStaticFinalFieldsRuleTest Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
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));

	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy