Skip to content

Commit

Permalink
#171: Ignore bridge methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyakharlamov committed Oct 25, 2018
1 parent 48fcf32 commit 1392392
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
23 changes: 16 additions & 7 deletions src/main/java/org/jpeek/skeleton/XmlClass.java
Expand Up @@ -161,9 +161,21 @@ public FieldVisitor visitField(final int access,
public MethodVisitor visitMethod(final int access,
final String mtd, final String desc,
final String signature, final String[] exceptions) {
final Directives dirs = new Directives();
this.methods.add(dirs);
dirs.add("method")
final MethodVisitor visitMethod = super.visitMethod(access, mtd, desc, signature, exceptions);
if ( (access & Opcodes.ACC_SYNTHETIC) == Opcodes.ACC_SYNTHETIC) {
return visitMethod;
} else {
final Directives dirs = directives(access, mtd, desc);
this.methods.add(dirs);
return new OpsOf(
dirs, visitMethod
);
}
}

private Directives directives(final int access, final String mtd, final String desc) {
return new Directives()
.add("method")
.attr("name", mtd)
.attr("desc", desc)
.attr(
Expand All @@ -187,9 +199,6 @@ public MethodVisitor visitMethod(final int access,
(access & Opcodes.ACC_BRIDGE) == Opcodes.ACC_BRIDGE
)
.append(new TypesOf(desc));
return new OpsOf(
dirs, super.visitMethod(access, mtd, desc, signature, exceptions)
);
}
}

}
4 changes: 2 additions & 2 deletions src/test/java/org/jpeek/MetricsTest.java
Expand Up @@ -101,7 +101,7 @@ public static Collection<Object[]> targets() {
new Object[] {"OverloadMethods", "LCOM", 0.0d},
new Object[] {"TwoCommonAttributes", "LCOM", 6.0d},
new Object[] {"WithoutAttributes", "LCOM", 1.0d},
new Object[] {"OneMethodCreatesLambda", "LCOM", 3.0d},
new Object[] {"OneMethodCreatesLambda", "LCOM", 1.0d},
new Object[] {"Bar", "CAMC", 0.4d},
new Object[] {"Foo", "CAMC", 0.6667d},
new Object[] {"Bar", "MMAC", 0.1d},
Expand All @@ -121,7 +121,7 @@ public static Collection<Object[]> targets() {
new Object[] {"NoMethods", "LCOM5", Double.NaN},
new Object[] {"WithoutAttributes", "LCOM5", Double.NaN},
new Object[] {"OneVoidMethodWithoutParams", "LCOM5", 1.0d},
new Object[] {"OneMethodCreatesLambda", "LCOM5", 1.5d},
new Object[] {"OneMethodCreatesLambda", "LCOM5", 2.0d},
new Object[] {"Bar", "NHD", 0.4d},
new Object[] {"Foo", "NHD", 0.3333d},
new Object[] {"MethodsWithDiffParamTypes", "NHD", 0.7143d},
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/jpeek/skeleton/SkeletonTest.java
Expand Up @@ -108,6 +108,21 @@ public void findsMethodCalls() throws IOException {
);
}


@Test
public void createsOnlyOneMethodIgnoresSynthetic() {
MatcherAssert.assertThat(
XhtmlMatchers.xhtml(
new Skeleton(
new FakeBase("OneMethodCreatesLambda")
).xml().toString()
),
XhtmlMatchers.hasXPaths(
"//class[@id='OneMethodCreatesLambda' and count(methods/method[contains(@name,'doSomething')])=1]"
)
);
}

@Test
@Ignore
public void findFieldWithQualifiedName() {
Expand Down

0 comments on commit 1392392

Please sign in to comment.