package archmapper.stylespecific.spring.rules;
import java.util.List;
import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.IExtendedModifier;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Modifier;
import org.eclipse.tptp.platform.analysis.codereview.java.CodeReviewResource;
import org.eclipse.tptp.platform.analysis.core.history.AnalysisHistory;
import archmapper.main.conformance.rules.AbstractArchitectureConformanceRule;
public class NoStaticMethodsRule extends AbstractArchitectureConformanceRule {
@Override
public void analyze(AnalysisHistory history) {
CodeReviewResource res = getCurrentResource(history);
List<?> nodes = res.getTypedNodeList(res.getResourceCompUnit(), ASTNode.METHOD_DECLARATION, true);
for (Object obj : nodes) {
MethodDeclaration decl = (MethodDeclaration) obj;
for (Object modObj : decl.modifiers()) {
IExtendedModifier mod = (IExtendedModifier) modObj;
if (mod instanceof Modifier) {
if (((Modifier) mod).isStatic()) {
generateResultsForASTNode(history, decl, res,
"The method "+ decl.getName().getFullyQualifiedName() +
" may not be static. Use singletons declared in the "
+ "Spring configuration instead.");
}
}
}
}
}
}