-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new Java metrics to count lambdas, anonymous classes and null checks
- Loading branch information
1 parent
33a4a2a
commit 849b5a0
Showing
11 changed files
with
393 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
stockmetrics/metricsDescriptions/metricsDescriptions/NumAnonymousClassesPackage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- | ||
~ Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<html> | ||
<body> | ||
<table><tr><td valign="top" height="150"> | ||
<font face="verdana" size="-1"> | ||
Calculates the number of anonymous classes in each package. | ||
</font> | ||
</td></tr> | ||
<tr><td height="50"><font face="verdana" size="-1">Abbreviation: <b>AnoC</b></font></td></tr> | ||
<tr><td height="20"><font face="verdana" size="-2">Powered by MetricsReloaded</font></td></tr> | ||
</table> | ||
</body> | ||
</html> |
28 changes: 28 additions & 0 deletions
28
stockmetrics/metricsDescriptions/metricsDescriptions/NumLambdasPackage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- | ||
~ Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<html> | ||
<body> | ||
<table><tr><td valign="top" height="150"> | ||
<font face="verdana" size="-1"> | ||
Calculates the number of lambda expressions in each <b>package</b>. | ||
</font> | ||
</td></tr> | ||
<tr><td height="50"><font face="verdana" size="-1">Abbreviation: <b>LAMBDA</b></font></td></tr> | ||
<tr><td height="20"><font face="verdana" size="-2">Powered by MetricsReloaded</font></td></tr> | ||
</table> | ||
</body> | ||
</html> |
28 changes: 28 additions & 0 deletions
28
stockmetrics/metricsDescriptions/metricsDescriptions/NumNullChecks.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<!-- | ||
~ Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
~ | ||
~ 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. | ||
--> | ||
|
||
<html> | ||
<body> | ||
<table><tr><td valign="top" height="150"> | ||
<font face="verdana" size="-1"> | ||
Calculates the number of comparisons with <code>null</code> in each <b>method</b>. | ||
</font> | ||
</td></tr> | ||
<tr><td height="50"><font face="verdana" size="-1">Abbreviation: <b>NULL</b></font></td></tr> | ||
<tr><td height="20"><font face="verdana" size="-2">Powered by MetricsReloaded</font></td></tr> | ||
</table> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
stockmetrics/src/com/sixrr/stockmetrics/methodCalculators/NumNullChecksCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
* | ||
* 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.sixrr.stockmetrics.methodCalculators; | ||
|
||
import com.intellij.psi.*; | ||
import com.intellij.psi.tree.IElementType; | ||
import com.sixrr.metrics.utils.MethodUtils; | ||
|
||
/** | ||
* @author Bas Leijdekkers | ||
*/ | ||
public class NumNullChecksCalculator extends MethodCalculator { | ||
private int methodNestingDepth = 0; | ||
private int elementCount = 0; | ||
|
||
@Override | ||
protected PsiElementVisitor createVisitor() { | ||
return new Visitor(); | ||
} | ||
|
||
private class Visitor extends JavaRecursiveElementVisitor { | ||
|
||
@Override | ||
public void visitMethod(PsiMethod method) { | ||
if (methodNestingDepth == 0) { | ||
elementCount = 0; | ||
} | ||
methodNestingDepth++; | ||
super.visitMethod(method); | ||
methodNestingDepth--; | ||
if (methodNestingDepth == 0 && !MethodUtils.isAbstract(method)) { | ||
postMetric(method, elementCount); | ||
} | ||
} | ||
|
||
@Override | ||
public void visitPolyadicExpression(PsiPolyadicExpression expression) { | ||
super.visitPolyadicExpression(expression); | ||
final IElementType tokenType = expression.getOperationTokenType(); | ||
if (!JavaTokenType.EQEQ.equals(tokenType) && !JavaTokenType.NE.equals(tokenType)) { | ||
return; | ||
} | ||
for (PsiExpression operand : expression.getOperands()) { | ||
if (operand instanceof PsiLiteralExpression && PsiType.NULL.equals(operand.getType())) { | ||
elementCount++; | ||
} | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
stockmetrics/src/com/sixrr/stockmetrics/methodMetrics/NumNullChecksMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
* | ||
* 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.sixrr.stockmetrics.methodMetrics; | ||
|
||
import com.sixrr.metrics.MetricCalculator; | ||
import com.sixrr.metrics.MetricType; | ||
import com.sixrr.stockmetrics.i18n.StockMetricsBundle; | ||
import com.sixrr.stockmetrics.methodCalculators.NumControlStatementsCalculator; | ||
import com.sixrr.stockmetrics.methodCalculators.NumNullChecksCalculator; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Bas Leijdekkers | ||
*/ | ||
public class NumNullChecksMetric extends MethodMetric { | ||
|
||
@NotNull | ||
@Override | ||
public String getDisplayName() { | ||
return StockMetricsBundle.message("number.of.null.checks.display.name"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getAbbreviation() { | ||
return StockMetricsBundle.message("number.of.null.checks.abbreviation"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public MetricType getType() { | ||
return MetricType.Count; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public MetricCalculator createCalculator() { | ||
return new NumNullChecksCalculator(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...s/src/com/sixrr/stockmetrics/packageCalculators/NumAnonymousClassesPackageCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
* | ||
* 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.sixrr.stockmetrics.packageCalculators; | ||
|
||
import com.intellij.psi.PsiAnonymousClass; | ||
import com.intellij.psi.PsiClass; | ||
|
||
/** | ||
* @author Bas Leijdekkers | ||
*/ | ||
public class NumAnonymousClassesPackageCalculator extends ClassCountingPackageCalculator { | ||
|
||
@Override | ||
public boolean satisfies(PsiClass aClass) { | ||
return aClass instanceof PsiAnonymousClass; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
stockmetrics/src/com/sixrr/stockmetrics/packageCalculators/NumLambdasPackageCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
* | ||
* 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.sixrr.stockmetrics.packageCalculators; | ||
|
||
import com.intellij.psi.*; | ||
|
||
/** | ||
* @author Bas Leijdekkers | ||
*/ | ||
public class NumLambdasPackageCalculator extends ElementCountPackageCalculator { | ||
|
||
@Override | ||
protected PsiElementVisitor createVisitor() { | ||
return new Visitor(); | ||
} | ||
|
||
private class Visitor extends JavaRecursiveElementVisitor { | ||
|
||
@Override | ||
public void visitJavaFile(PsiJavaFile file) { | ||
super.visitJavaFile(file); | ||
createCount(file); | ||
} | ||
|
||
@Override | ||
public void visitLambdaExpression(PsiLambdaExpression expression) { | ||
super.visitLambdaExpression(expression); | ||
incrementCount(expression, 1); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
stockmetrics/src/com/sixrr/stockmetrics/packageMetrics/NumAnonymousClassesPackageMetric.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright 2005-2016 Sixth and Red River Software, Bas Leijdekkers | ||
* | ||
* 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.sixrr.stockmetrics.packageMetrics; | ||
|
||
import com.sixrr.metrics.MetricCalculator; | ||
import com.sixrr.metrics.MetricType; | ||
import com.sixrr.stockmetrics.i18n.StockMetricsBundle; | ||
import com.sixrr.stockmetrics.packageCalculators.NumAnonymousClassesPackageCalculator; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* @author Bas Leijdekkers | ||
*/ | ||
public class NumAnonymousClassesPackageMetric extends PackageMetric { | ||
|
||
@NotNull | ||
@Override | ||
public String getDisplayName() { | ||
return StockMetricsBundle.message("number.of.anonymous.classes.display.name"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getAbbreviation() { | ||
return StockMetricsBundle.message("number.of.anonymous.classes.abbreviation"); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public MetricType getType() { | ||
return MetricType.Count; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public MetricCalculator createCalculator() { | ||
return new NumAnonymousClassesPackageCalculator(); | ||
} | ||
} |
Oops, something went wrong.