2 * Copyright 2003-2005 Dave Griffith
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.siyeh
.ig
.methodmetrics
;
18 import com
.intellij
.psi
.*;
19 import org
.jetbrains
.annotations
.NotNull
;
21 class CyclomaticComplexityVisitor
extends JavaRecursiveElementVisitor
{
22 private int m_complexity
= 1;
24 @Override public void visitAnonymousClass(@NotNull PsiAnonymousClass aClass
) {
25 // to call to super, to keep this from drilling down
28 @Override public void visitForStatement(@NotNull PsiForStatement statement
) {
29 super.visitForStatement(statement
);
33 @Override public void visitForeachStatement(@NotNull PsiForeachStatement statement
) {
34 super.visitForeachStatement(statement
);
38 @Override public void visitIfStatement(@NotNull PsiIfStatement statement
) {
39 super.visitIfStatement(statement
);
43 @Override public void visitDoWhileStatement(@NotNull PsiDoWhileStatement statement
) {
44 super.visitDoWhileStatement(statement
);
48 @Override public void visitConditionalExpression(PsiConditionalExpression expression
) {
49 super.visitConditionalExpression(expression
);
53 @Override public void visitSwitchStatement(@NotNull PsiSwitchStatement statement
) {
54 super.visitSwitchStatement(statement
);
55 final PsiCodeBlock body
= statement
.getBody();
59 final PsiStatement
[] statements
= body
.getStatements();
60 boolean pendingLabel
= false;
61 for(final PsiStatement child
: statements
){
62 if(child
instanceof PsiSwitchLabelStatement
){
73 @Override public void visitWhileStatement(@NotNull PsiWhileStatement statement
) {
74 super.visitWhileStatement(statement
);
78 public int getComplexity() {