Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public BeanEnvironment getEnvironment() {
@Override
public void close() throws Exception {
for (Object o : this.boundObjects.values()) {
if (o instanceof AutoCloseable) {
if (o instanceof AutoCloseable && o != this) {
try {
((AutoCloseable) o).close();
} catch (Exception e) {
Expand Down
2 changes: 1 addition & 1 deletion gestalt-inject-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
testImplementation "ch.qos.logback:logback-classic:$logback_version"
testImplementation "org.mockito:mockito-core:$mockito_version"

implementation 'com.squareup:javapoet:1.12.0'
implementation 'com.squareup:javapoet:1.13.0'
implementation group: 'javax.inject', name: 'javax.inject', version: '1'
implementation project(":gestalt-inject");
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,22 @@ public Object visitType(TypeElement e, String className) {
return super.visitType(e, className);
}

private Object getValue(Object target) {
private Object getValue(TypeMirror type, Object target) {
Object result;
if (target instanceof String) {
result = String.format("\"%s\"", target);
} else if (target instanceof List) {
if (((List<?>) target).isEmpty()) {
result = "new " + type + "{}";
} else {
result = target;
}
} else if (type.getKind() == TypeKind.DECLARED && ((DeclaredType) type).asElement().getKind() == ElementKind.ENUM) {
result = type + "." + target;
} else {
result = target;
}
return result;

}

private List<CodeBlock> buildAnnotationValues(List<? extends AnnotationMirror> mirrors) {
Expand All @@ -198,7 +205,7 @@ private List<CodeBlock> buildAnnotationValues(List<? extends AnnotationMirror> m
ExecutableElement executableElement = (ExecutableElement) element;
AnnotationValue value = executableElement.getDefaultValue();
if (value != null) {
defaults.add(CodeBlock.of("$S,$L", executableElement.getSimpleName(), getValue(value.getValue())));
defaults.add(CodeBlock.of("$S,$L", executableElement.getSimpleName(), getValue(executableElement.getReturnType(), value.getValue())));
}
}
}
Expand All @@ -207,7 +214,7 @@ private List<CodeBlock> buildAnnotationValues(List<? extends AnnotationMirror> m
ExecutableElement executableElement = entry.getKey();
AnnotationValue value = entry.getValue();
if (value != null) {
values.add(CodeBlock.of("$S,$L", executableElement.getSimpleName(), getValue(value.getValue())));
values.add(CodeBlock.of("$S,$L", executableElement.getSimpleName(), getValue(executableElement.asType(), value.getValue())));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public int getPatch() {
* @return Whether this version is a snapshot (work in progress)
*/
public boolean isSnapshot() {
return !semver.preReleaseVersion().isEmpty();
return semver.preReleaseVersion().isPresent();
}

public Version getSnapshot() {
Expand Down