use of org.jetbrains.uast.UClass in project Conductor by bluelinelabs.
the class ControllerIssueDetector method createUastHandler.
@Override
public UElementHandler createUastHandler(final JavaContext context) {
final JavaEvaluator evaluator = context.getEvaluator();
return new UElementHandler() {
@Override
public void visitClass(UClass node) {
if (evaluator.isAbstract(node)) {
return;
}
boolean hasSuperType = false;
for (UTypeReferenceExpression superType : node.getUastSuperTypes()) {
if (CLASS_NAME.equals(superType.asRenderString())) {
hasSuperType = true;
break;
}
}
if (!hasSuperType) {
return;
}
if (!evaluator.isPublic(node)) {
String message = String.format("This Controller class should be public (%1$s)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
return;
}
if (node.getContainingClass() != null && !evaluator.isStatic(node)) {
String message = String.format("This Controller inner class should be static (%1$s)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
return;
}
boolean hasConstructor = false;
boolean hasDefaultConstructor = false;
boolean hasBundleConstructor = false;
for (UMethod method : node.getMethods()) {
if (method.isConstructor()) {
hasConstructor = true;
if (evaluator.isPublic(method)) {
List<UParameter> parameters = method.getUastParameters();
if (parameters.size() == 0) {
hasDefaultConstructor = true;
break;
} else if (parameters.size() == 1 && (parameters.get(0).getType().equalsToText(SdkConstants.CLASS_BUNDLE)) || parameters.get(0).getType().equalsToText("Bundle")) {
hasBundleConstructor = true;
}
}
}
}
if (hasConstructor && !hasDefaultConstructor && !hasBundleConstructor) {
String message = String.format("This Controller needs to have either a public default constructor or a" + " public single-argument constructor that takes a Bundle. (`%1$s`)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
}
}
};
}
use of org.jetbrains.uast.UClass in project Conductor by bluelinelabs.
the class ControllerChangeHandlerIssueDetector method createUastHandler.
@Override
public UElementHandler createUastHandler(final JavaContext context) {
final JavaEvaluator evaluator = context.getEvaluator();
return new UElementHandler() {
@Override
public void visitClass(UClass node) {
if (evaluator.isAbstract(node)) {
return;
}
boolean hasSuperType = false;
for (UTypeReferenceExpression superType : node.getUastSuperTypes()) {
if (CLASS_NAME.equals(superType.asRenderString())) {
hasSuperType = true;
break;
}
}
if (!hasSuperType) {
return;
}
if (!evaluator.isPublic(node)) {
String message = String.format("This ControllerChangeHandler class should be public (%1$s)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
return;
}
if (node.getContainingClass() != null && !evaluator.isStatic(node)) {
String message = String.format("This ControllerChangeHandler inner class should be static (%1$s)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
return;
}
boolean hasConstructor = false;
boolean hasDefaultConstructor = false;
for (UMethod method : node.getMethods()) {
if (method.isConstructor()) {
hasConstructor = true;
if (evaluator.isPublic(method) && method.getUastParameters().size() == 0) {
hasDefaultConstructor = true;
break;
}
}
}
if (hasConstructor && !hasDefaultConstructor) {
String message = String.format("This ControllerChangeHandler needs to have a public default constructor (`%1$s`)", node.getQualifiedName());
context.report(ISSUE, node, context.getLocation((UElement) node), message);
}
}
};
}
Aggregations