diff --git a/pom.xml b/pom.xml
index f12790b8..fdc49418 100644
--- a/pom.xml
+++ b/pom.xml
@@ -74,6 +74,30 @@
0.9.12
+
+ org.eclipse.platform
+ org.eclipse.core.runtime
+ 3.26.0
+
+
+
+ org.eclipse.platform
+ org.eclipse.core.jobs
+ 3.13.0
+
+
+
+ org.eclipse.platform
+ org.eclipse.core.contenttype
+ 3.8.0
+
+
+
+ org.eclipse.platform
+ org.eclipse.core.resources
+ 3.14.0
+
+
org.eclipse.jdt
org.eclipse.jdt.core
diff --git a/src/main/java/com/github/mauricioaniche/ck/CKVisitor.java b/src/main/java/com/github/mauricioaniche/ck/CKVisitor.java
index 0e53b66c..1a1ea332 100644
--- a/src/main/java/com/github/mauricioaniche/ck/CKVisitor.java
+++ b/src/main/java/com/github/mauricioaniche/ck/CKVisitor.java
@@ -163,12 +163,18 @@ public boolean visit(AnonymousClassDeclaration node) {
// there might be metrics that use it
// (even before an anonymous class is created)
+ String methodName = "";
classes.peek().classLevelMetrics.stream().map(metric -> (CKASTVisitor) metric).forEach(ast -> ast.visit(node));
- if(!classes.peek().methods.isEmpty())
+ if(!classes.peek().methods.isEmpty()) {
classes.peek().methods.peek().methodLevelMetrics.stream().map(metric -> (CKASTVisitor) metric).forEach(ast -> ast.visit(node));
+ methodName = '#' + classes.peek().methods.peek().result.getMethodName();
+ if (methodName.contains("/")) {
+ methodName = methodName.substring(0, methodName.indexOf('/'));
+ }
+ }
- // we give the anonymous class a 'class$AnonymousN' name
- String anonClassName = classes.peek().result.getClassName() + "$Anonymous" + ++anonymousNumber;
+ // we give the anonymous class a 'class#method$AnonymousN' name
+ String anonClassName = classes.peek().result.getClassName() + methodName + "$Anonymous" + ++anonymousNumber;
CKClassResult currentClass = new CKClassResult(sourceFilePath, anonClassName, "anonymous", -1);
currentClass.setLoc(calculate(node.toString()));
diff --git a/src/test/java/com/github/mauricioaniche/ck/ClassTypeTest.java b/src/test/java/com/github/mauricioaniche/ck/ClassTypeTest.java
index 56c426f1..da0863ec 100644
--- a/src/test/java/com/github/mauricioaniche/ck/ClassTypeTest.java
+++ b/src/test/java/com/github/mauricioaniche/ck/ClassTypeTest.java
@@ -34,10 +34,10 @@ public void identifyTypesCorrectly() {
CKClassResult mathOperation = report.get("classtypes.MathOperation");
Assertions.assertEquals("interface", mathOperation.getType());
- CKClassResult anon1 = report.get("classtypes.A$Anonymous1");
+ CKClassResult anon1 = report.get("classtypes.A#m2$Anonymous1");
Assertions.assertEquals("anonymous", anon1.getType());
- CKClassResult anon2 = report.get("classtypes.A$Anonymous2");
+ CKClassResult anon2 = report.get("classtypes.A#m3$Anonymous2");
Assertions.assertEquals("anonymous", anon2.getType());
diff --git a/src/test/java/com/github/mauricioaniche/ck/LOCTest.java b/src/test/java/com/github/mauricioaniche/ck/LOCTest.java
index 393ca77f..ed933c03 100644
--- a/src/test/java/com/github/mauricioaniche/ck/LOCTest.java
+++ b/src/test/java/com/github/mauricioaniche/ck/LOCTest.java
@@ -32,7 +32,7 @@ public void countLinesForInnerClasses() {
CKClassResult sc2 = report.get("innerclasses.MessyClass$InnerClass2");
Assertions.assertEquals(9, sc2.getLoc());
- CKClassResult an1 = report.get("innerclasses.MessyClass$Anonymous1");
+ CKClassResult an1 = report.get("innerclasses.MessyClass#m3$Anonymous1");
Assertions.assertEquals(5, an1.getLoc());
}
diff --git a/src/test/java/com/github/mauricioaniche/ck/MetricsPerClassesAndInnerClassesTest.java b/src/test/java/com/github/mauricioaniche/ck/MetricsPerClassesAndInnerClassesTest.java
index e4c70308..b90d9772 100644
--- a/src/test/java/com/github/mauricioaniche/ck/MetricsPerClassesAndInnerClassesTest.java
+++ b/src/test/java/com/github/mauricioaniche/ck/MetricsPerClassesAndInnerClassesTest.java
@@ -37,18 +37,18 @@ public void metricsPerClass() {
Assertions.assertEquals(1, sc3.getNumberOfMethods());
Assertions.assertEquals("innerclass", sc3.getType());
- CKClassResult an1 = report.get("innerclasses.MessyClass$Anonymous1");
+ CKClassResult an1 = report.get("innerclasses.MessyClass#m3$Anonymous1");
Assertions.assertEquals(1, an1.getNumberOfMethods());
Assertions.assertEquals("anonymous", an1.getType());
- CKClassResult an2 = report.get("innerclasses.MessyClass$Anonymous2");
+ CKClassResult an2 = report.get("innerclasses.MessyClass#m5$Anonymous2");
Assertions.assertEquals(2, an2.getNumberOfMethods());
Assertions.assertEquals("anonymous", an2.getType());
CKClassResult ysc2 = report.get("innerclasses.SC2");
Assertions.assertEquals("class", ysc2.getType());
- CKClassResult ysc2a = report.get("innerclasses.SC2$Anonymous1");
+ CKClassResult ysc2a = report.get("innerclasses.SC2#m1$Anonymous1");
Assertions.assertEquals("anonymous", ysc2a.getType());
CKClassResult ysc2x = report.get("innerclasses.SC2$1$1X");
Assertions.assertEquals("innerclass", ysc2x.getType());
diff --git a/src/test/java/com/github/mauricioaniche/ck/NumberOfInnerClassesLambdasAndAnonymousClassesTest.java b/src/test/java/com/github/mauricioaniche/ck/NumberOfInnerClassesLambdasAndAnonymousClassesTest.java
index 74afb82b..e44a8b6a 100644
--- a/src/test/java/com/github/mauricioaniche/ck/NumberOfInnerClassesLambdasAndAnonymousClassesTest.java
+++ b/src/test/java/com/github/mauricioaniche/ck/NumberOfInnerClassesLambdasAndAnonymousClassesTest.java
@@ -62,7 +62,7 @@ public void innerclassesInsideAnonymousClasses() {
Assertions.assertEquals(0, a.getMethod("m1/0").get().getInnerClassesQty());
Assertions.assertEquals(0, a.getMethod("m1/0").get().getLambdasQty());
- CKClassResult b = report.get("innerclasses.SC2$Anonymous1");
+ CKClassResult b = report.get("innerclasses.SC2#m1$Anonymous1");
Assertions.assertEquals(1, b.getMethod("toString/0").get().getInnerClassesQty());
Assertions.assertEquals(1, b.getInnerClassesQty());
Assertions.assertEquals(0, b.getLambdasQty());
diff --git a/src/test/java/com/github/mauricioaniche/ck/realworld/RealWorldClassesTest.java b/src/test/java/com/github/mauricioaniche/ck/realworld/RealWorldClassesTest.java
index bbe41f81..7aeec83e 100644
--- a/src/test/java/com/github/mauricioaniche/ck/realworld/RealWorldClassesTest.java
+++ b/src/test/java/com/github/mauricioaniche/ck/realworld/RealWorldClassesTest.java
@@ -205,11 +205,10 @@ public void asyncHttpClient_2() {
}
// illustrates the example of https://github.com/mauricioaniche/ck/issues/54
- // still to be implemented
@Test
public void hectorPolicyManager_betterNamesForAnonymousClasses() {
CKClassResult class1 = report.get("net.retakethe.policyauction.data.impl.HectorPolicyManagerImpl");
- CKClassResult anonymousClass = report.get("net.retakethe.policyauction.data.impl.HectorPolicyManagerImpl$Anonymous1");
+ CKClassResult anonymousClass = report.get("net.retakethe.policyauction.data.impl.HectorPolicyManagerImpl#getAllPolicies$Anonymous1");
Assertions.assertNotNull(class1);
Assertions.assertNotNull(anonymousClass);