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

de.jball.sonar.hybris.java.checks.ModelConstructor Maven / Gradle / Ivy

There is a newer version: 0.7.0
Show newest version
package de.jball.sonar.hybris.java.checks;

import org.sonar.check.Rule;
import org.sonar.plugins.java.api.IssuableSubscriptionVisitor;
import org.sonar.plugins.java.api.semantic.Type;
import org.sonar.plugins.java.api.tree.NewClassTree;
import org.sonar.plugins.java.api.tree.Tree;

import java.util.Collections;
import java.util.List;

@Rule(key = "ModelConstructor")
public class ModelConstructor extends IssuableSubscriptionVisitor {
	private static final List NODES_TO_VISIT = Collections.singletonList(Tree.Kind.NEW_CLASS);

	@Override
	public List nodesToVisit() {
		return NODES_TO_VISIT;
	}

	@Override
	public void visitNode(final Tree tree) {
		NewClassTree newClassTree = (NewClassTree) tree;
		Type typeOfNewObject = newClassTree.symbolType();
		if (typeOfNewObject.is("de.hybris.platform.core.model.ItemModel") || typeOfNewObject.isSubtypeOf("de.hybris.platform.core.model.ItemModel")) {
			reportIssue(tree, "Use \"modelService.create()\" instead.");
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy