Package archmapper.stylespecific.spring.rules

Source Code of archmapper.stylespecific.spring.rules.NoStaticMethodsRule

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.");
          }
        }
      }
    }
  }

}
TOP

Related Classes of archmapper.stylespecific.spring.rules.NoStaticMethodsRule

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.