Fixed Trigger name is reported incorrectly

https://github.com/Up2Go/codeclimate-apexmetrics/issues/23
This commit is contained in:
David Renz
2016-06-14 11:54:13 +02:00
parent 3b2b813b44
commit ef78229374
2 changed files with 13 additions and 2 deletions

View File

@ -3,6 +3,9 @@
*/
package net.sourceforge.pmd.lang.apex.ast;
import java.lang.reflect.Field;
import apex.jorje.data.ast.Identifier;
import apex.jorje.semantic.ast.compilation.UserTrigger;
public class ASTUserTrigger extends ApexRootNode<UserTrigger> {
@ -17,6 +20,14 @@ public class ASTUserTrigger extends ApexRootNode<UserTrigger> {
@Override
public String getImage() {
return node.getClass().getName();
try {
Field field = node.getClass().getDeclaredField("name");
field.setAccessible(true);
Identifier name = (Identifier) field.get(node);
return name.value;
} catch (Exception e) {
e.printStackTrace();
}
return super.getImage();
}
}

View File

@ -109,7 +109,7 @@ public class StdCyclomaticComplexityRule extends AbstractApexRule {
if (showClassesComplexity) {
Entry classEntry = entryStack.pop();
if (classEntry.getComplexityAverage() >= reportLevel || classEntry.highestDecisionPoints >= reportLevel) {
addViolation(data, node, new String[] { "class", node.getImage(),
addViolation(data, node, new String[] { "trigger", node.getImage(),
classEntry.getComplexityAverage() + " (Highest = " + classEntry.highestDecisionPoints + ')' });
}
}