#ref contains logic but is missing a 'return' statement
+overly.long.lambda.display.name=Overly long lambda expression
+overly.long.lambda.problem.descriptor=Lambda expression is too long (# Non-comment source statements = {0}) #loc
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspection.java
new file mode 100644
index 000000000000..67da5b40dd8d
--- /dev/null
+++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspection.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.siyeh.ig.methodmetrics;
+
+import com.intellij.psi.*;
+import com.siyeh.InspectionGadgetsBundle;
+import com.siyeh.ig.BaseInspectionVisitor;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * @author Bas Leijdekkers
+ */
+public class OverlyLongLambdaInspection extends MethodMetricInspection {
+
+ private static final int DEFAULT_LIMIT = 3;
+
+ @Override
+ @NotNull
+ public String getDisplayName() {
+ return InspectionGadgetsBundle.message("overly.long.lambda.display.name");
+ }
+
+ @Override
+ protected int getDefaultLimit() {
+ return DEFAULT_LIMIT;
+ }
+
+ @Override
+ protected String getConfigurationLabel() {
+ return InspectionGadgetsBundle.message("non.comment.source.statements.limit.option");
+ }
+
+ @Override
+ @NotNull
+ public String buildErrorString(Object... infos) {
+ final Integer statementCount = (Integer)infos[0];
+ return InspectionGadgetsBundle.message("overly.long.lambda.problem.descriptor", statementCount);
+ }
+
+ @Override
+ public BaseInspectionVisitor buildVisitor() {
+ return new OverlyLongLambdaVisitor();
+ }
+
+ private class OverlyLongLambdaVisitor extends BaseInspectionVisitor {
+
+ @Override
+ public void visitLambdaExpression(PsiLambdaExpression expression) {
+ final PsiElement body = expression.getBody();
+ if (!(body instanceof PsiCodeBlock)) {
+ return;
+ }
+ final PsiCodeBlock block = (PsiCodeBlock)body;
+ final PsiJavaToken brace = block.getLBrace();
+ if (brace == null) {
+ return;
+ }
+ final NCSSVisitor visitor = new NCSSVisitor();
+ block.accept(visitor);
+ final int count = visitor.getStatementCount();
+ if (count <= getLimit()) {
+ return;
+ }
+ registerErrorAtOffset(expression, 0, body.getStartOffsetInParent() + 1, Integer.valueOf(count));
+ }
+ }
+}
\ No newline at end of file
diff --git a/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyLongLambda.html b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyLongLambda.html
new file mode 100644
index 000000000000..970edba93a50
--- /dev/null
+++ b/plugins/InspectionGadgets/src/inspectionDescriptions/OverlyLongLambda.html
@@ -0,0 +1,12 @@
+
+
+Reports lambda expressions that are too long.
+Lambda expressions that are too long
+may be confusing, and it is often better to extract the statements into their own method.
+
++Use the field below to specify the maximum number of non-comment source statements a lambda expression is allowed to have. +
+New in 2016.3 + + \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspectionTest.java new file mode 100644 index 000000000000..13f47938d78f --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/methodmetrics/OverlyLongLambdaInspectionTest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.methodmetrics; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class OverlyLongLambdaInspectionTest extends LightInspectionTestCase { + + public void testSimple() { + doStatementTest("Runnable r = /*Lambda is too long (# Non-comment source statements = 4)*/() -> {/**/" + + " System.out.println();" + + " System.out.println();" + + " System.out.println();" + + " System.out.println();" + + "};"); + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new OverlyLongLambdaInspection(); + } +} \ No newline at end of file