import org.jetbrains.annotations.NotNull;
import org.jetbrains.plugins.groovy.codeInspection.BaseInspectionVisitor;
+import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrOpenBlock;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
public class GroovyOverlyLongMethodInspection extends GroovyMethodMetricInspection {
}
private class Visitor extends BaseInspectionVisitor {
- public void visitMethod(GrMethod grMethod) {
- super.visitMethod(grMethod);
+ public void visitMethod(GrMethod method) {
+ super.visitMethod(method);
final int limit = getLimit();
final StatementCountVisitor visitor = new StatementCountVisitor();
- grMethod.accept(visitor);
+ final GrOpenBlock block = method.getBlock();
+ if (block == null) return;
+ block.accept(visitor);
final int statementCount = visitor.getStatementCount();
if (statementCount <= limit) {
return;
}
- registerMethodError(grMethod, statementCount, limit);
+ registerMethodError(method, statementCount, limit);
}
}
}
\ No newline at end of file
import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyUncheckedAssignmentOfMemberOfRawTypeInspection;
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection;
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection;
+import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection;
import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection;
import org.jetbrains.plugins.groovy.codeInspection.unassignedVariable.UnassignedVariableAccessInspection;
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUnresolvedAccessInspection;
public void testEverythingAssignableToString() throws Exception {doTest(new GroovyAssignabilityCheckInspection());}
public void testMethodCallWithDefaultParameters() throws Exception {doTest();}
+
+ public void testOverlyLongMethodInspection() throws Exception {
+ doTest(new GroovyOverlyLongMethodInspection());
+ }
}
\ No newline at end of file