Skip to content

Commit

Permalink
Fix to Issue #33 - Can Subclass checking...for inner class constructs...
Browse files Browse the repository at this point in the history
  • Loading branch information
neomatrix369 committed Dec 27, 2012
1 parent f97ef48 commit 9aef577
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
Expand Up @@ -22,6 +22,7 @@
import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;

/**
* Used to check for the existence of an access flag used in ASM visitors.
Expand Down Expand Up @@ -77,6 +78,15 @@ public boolean isFinal() {
public boolean isNotFinal() {
return !is(ACC_FINAL);
}

public boolean isSynthetic() {
return !is(ACC_SYNTHETIC);
}

public boolean isNotSynthetic() {
return !is(ACC_SYNTHETIC);
}


public boolean isAbstract() {
return is(ACC_ABSTRACT);
Expand Down
Expand Up @@ -39,7 +39,7 @@ public void visit(int version, int access, String name, String signature, String

@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (MethodIs.aConstructor(name) && method(access).isNotPrivate()) {
if (MethodIs.aConstructor(name) && (method(access).isNotPrivate()) && method(access).isNotSynthetic()) {
hasOnlyPrivateConstructors = false;
}
return super.visitMethod(access, name, desc, signature, exceptions);
Expand Down
@@ -0,0 +1,5 @@
package org.mutabilitydetector.benchmarks;

public class ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern {

}
Expand Up @@ -42,6 +42,7 @@
import org.mutabilitydetector.benchmarks.types.EnumType;
import org.mutabilitydetector.checkers.CanSubclassChecker;
import org.mutabilitydetector.locations.ClassLocation;
import org.mutabilitydetector.unittesting.MutabilityAssert;

@RunWith(Theories.class)
public class CanSubclassCheckerTest {
Expand All @@ -59,6 +60,7 @@ public void createChecker() {
AnalysisResultTheory.of(HasFinalFieldsAndADefaultConstructor.class, NOT_IMMUTABLE),
AnalysisResultTheory.of(IsFinalAndHasOnlyPrivateConstructors.class, IMMUTABLE),
AnalysisResultTheory.of(ImmutableByHavingOnlyPrivateConstructors.class, IMMUTABLE),
AnalysisResultTheory.of(ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern.class, IMMUTABLE),
};

@Theory
Expand Down Expand Up @@ -90,4 +92,8 @@ public void hasCodeLocationWithCorrectTypeName() throws Exception {
assertThat(location.typeName(), is(MutableByNotBeingFinalClass.class.getName()));
}

@Test
public void privateConstructorsUsingBuilderPatternAreImmutable() throws Exception {
MutabilityAssert.assertImmutable(ImmutableByHavingOnlyAPrivateConstructorUsingTheBuilderPattern.class);
}
}

0 comments on commit 9aef577

Please sign in to comment.