Skip to content

Commit

Permalink
feat: analyze bytecode of methods to determine return type nullability
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Oct 5, 2024
1 parent 7c45311 commit 47f40bc
Show file tree
Hide file tree
Showing 9 changed files with 946 additions and 104 deletions.
11 changes: 9 additions & 2 deletions eea-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ SPDX-FileContributor: Sebastian Thomschke (https://sebthom.de), Vegard IT GmbH (
SPDX-License-Identifier: EPL-2.0
SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/no-npe
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -53,7 +55,12 @@ SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/no-npe
<dependency>
<groupId>io.github.classgraph</groupId>
<artifactId>classgraph</artifactId>
<version>4.8.176</version>
<version>4.8.177</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm-util</artifactId>
<version>9.7</version>
</dependency>

<!-- test dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
import java.nio.file.StandardOpenOption;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jdt.internal.compiler.classfmt.ExternalAnnotationProvider;
Expand Down Expand Up @@ -107,19 +107,19 @@ public void applyAnnotationsAndCommentsFrom(final ClassMember applyFrom, final b
}

// apply name comment
if (overrideOnConflict || !name.hasComment()) {
if (overrideOnConflict && applyFrom.name.hasComment() || !name.hasComment()) {
name.comment = applyFrom.name.comment;
}

// apply original signature comment
if (overrideOnConflict || !originalSignature.hasComment()) {
if (overrideOnConflict && applyFrom.originalSignature.hasComment() || !originalSignature.hasComment()) {
originalSignature.comment = applyFrom.originalSignature.comment;
}

if (overrideOnConflict || !hasNullAnnotations()) {
if (applyFrom.hasNullAnnotations()) {
if (applyFrom.hasNullAnnotations() || applyFrom.annotatedSignature.comment.contains(MARKER_KEEP)) {
annotatedSignature = applyFrom.annotatedSignature.clone();
} else if (overrideOnConflict || !annotatedSignature.hasComment()) {
} else if (overrideOnConflict && applyFrom.annotatedSignature.hasComment() || !annotatedSignature.hasComment()) {
annotatedSignature.comment = applyFrom.annotatedSignature.comment;
}
}
Expand Down Expand Up @@ -195,6 +195,7 @@ public String toString(final boolean omitComment) {
public static final String MARKER_KEEP = "@Keep";
public static final String MARKER_OVERRIDES = "@Overrides";
public static final String MARKER_INHERITED = "@Inherited";
public static final String MARKER_POLY_NULL = "@PolyNull";

/**
* Used to match the 0/1 null annotation of types generic type variables, which is especially tricky
Expand Down Expand Up @@ -484,8 +485,8 @@ public boolean exists(final Path rootPath) {
return Files.exists(rootPath.resolve(relativePath));
}

public Collection<ClassMember> getClassMembers() {
return members;
public Stream<ClassMember> getClassMembers() {
return members.stream();
}

private void renderLine(final List<String> lines, final Object... newLineContent) {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 47f40bc

Please sign in to comment.