Skip to content

Commit

Permalink
0.4.0: refactoring, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jacek99 committed Jul 4, 2015
1 parent 065f40d commit db1670d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 46 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ The artifacts for this library are published to the popular Bintray JCenter Mave
jcenter()
}

compile "org.immutizer4j:immutizer4j:0.3.0"
compile "org.immutizer4j:immutizer4j:0.4.0"


## Maven
Expand All @@ -149,7 +149,7 @@ The artifacts for this library are published to the popular Bintray JCenter Mave
<dependency>
<groupId>org.immutizer4j</groupId>
<artifactId>immutizer4j</artifactId>
<version>0.3.0</version>
<version>0.4.0</version>
</dependency>
</dependencies>

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# speed up Gradle
org.gradle.daemon=true

version = 0.3.0
version = 0.4.0
group = org.immutizer4j
28 changes: 5 additions & 23 deletions src/main/java/org/immutizer4j/Immutizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,9 @@ private boolean isSafeType(Class<?> type) {
// standard handler for reporting errors, returns a new immutable ValidationResult instance
private ValidationResult addError(Field field, ViolationType violationType, ValidationResult result) {
// log it as long as it is not marked as @ImmutizerIgnore
if (field.getAnnotation(ImmutizerIgnore.class) == null) {
ValidationError error = new ValidationError(field.getDeclaringClass(), field.getName(), violationType);
log.error("Immutability violation: {}", error);
return result.addError(error);
} else {
log.debug("Skipping immutability violation for field {}.{} due to being marked as @ImmutizerIgnore",
field.getDeclaringClass().getSimpleName(),field.getName());
return result;
}
ValidationError error = new ValidationError(field.getDeclaringClass(), field.getName(), violationType);
log.error("Immutability violation: {}", error);
return result.addError(error);
}

/**
Expand All @@ -261,7 +255,8 @@ public ValidationResult validateIfGenericsReference(Field field, Class<?> actual

// try to extract actual class name via
String sig = (String) signatureField.get(field);
if (sig.startsWith("T") && sig.endsWith(";")) {
// T = var, [T = array of vars
if ((sig.startsWith("T") || sig.startsWith("[T")) && sig.endsWith(";")) {
// OK, reference to a generic type
// unfortunately there is no information on the package of the type so we cannot get to it
// need to flag this is a violation
Expand All @@ -272,17 +267,4 @@ public ValidationResult validateIfGenericsReference(Field field, Class<?> actual
return result;
}

// // figures out the standard JavaBean getter method name for a field
// private String getGetterName(Field field) {
// StringBuilder sb = ThreadLocals.STRINGBUILDER.get().append(ImmutizerConstants.GETTER_PREFIX);
//
// if (field.getName().length() == 1) {
// sb.append(field.getName().toUpperCase());
// } else {
// sb.append(field.getName().substring(0,1).toUpperCase())
// .append(field.getName().substring(1));
// }
// return sb.toString();
// }

}
1 change: 0 additions & 1 deletion src/main/java/org/immutizer4j/ImmutizerConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class ImmutizerConstants {
static final String NEWLINE = "\n ";

static final String SIGNATURE_FIELD = "signature";
static final String GETTER_PREFIX = "get";

/**
* Types the immutizer recognizes by default as immutable (if flagged as final)
Expand Down
14 changes: 0 additions & 14 deletions src/main/java/org/immutizer4j/ImmutizerIgnore.java

This file was deleted.

7 changes: 5 additions & 2 deletions src/test/java/org/immutizer4j/test/ArrayTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ public void testImmutableArrayUtilityClass() {
ValidationResult result = defaultImmutizer.getValidationResult(ImmutableArrayPojo.class);

assertEquals(false,result.isValid());
assertEquals(1, result.getErrors().size());
assertEquals("org.immutizer4j.ImmutableArray.array : MUTABLE_ARRAY",result.toString());
assertEquals(2, result.getErrors().size());

assertTrue(result.toString(), result.toString().contains("org.immutizer4j.test.sample.generics.ImmutableArray.array : MUTABLE_ARRAY"));
assertTrue(result.toString(), result.toString().contains("org.immutizer4j.test.sample.generics.ImmutableArray.array : UNABLE_TO_DETERMINE_TYPE_DUE_TO_GENERICS_TYPE_ERASURE"));

}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.immutizer4j.test.sample;

import lombok.Value;
import org.immutizer4j.ImmutableArray;
import org.immutizer4j.test.sample.generics.ImmutableArray;

/**
* A POJO that uses ImmutableArray to wrap both mutable and immutable object types
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.immutizer4j;
package org.immutizer4j.test.sample.generics;

import lombok.Value;
import org.immutizer4j.ImmutizerIgnore;

import java.util.Arrays;

Expand Down

0 comments on commit db1670d

Please sign in to comment.