Skip to content

Commit

Permalink
fix most nullness annotations and errors in VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakobeha committed Jan 26, 2024
1 parent 9cb2d11 commit 60a85a2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ target/
.classpath
.factorypath
.project
.settings
# We actually want to sync this to ensure NonNullByDefault
# .settings
.springBeans
.sts4-cache

Expand Down
11 changes: 11 additions & 0 deletions .settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=disabled
org.eclipse.jdt.core.compiler.annotation.nonnull=javax.annotation.Nonnull
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nullable=javax.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=warning
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=warning
org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
6 changes: 3 additions & 3 deletions src/main/java/org/prlprg/bc/ConstPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public <S extends SEXP> S get(TypedIdx<S> idx) {


/** If the SEXP is a constant, returns its index. Otherwise returns null. */
public <S extends SEXP> @Nullable TypedIdx<S> indexOf(S c) {
public @Nullable <S extends SEXP> TypedIdx<S> indexOf(S c) {
if (consts == null) {
throw new IllegalStateException("ConstPool is not yet built");
}
Expand Down Expand Up @@ -280,7 +280,7 @@ private <S extends SEXP> TypedIdx<S> of(int i, Class<S> sexpInterface) {
return idx;
}

private <S extends SEXP> @Nullable TypedIdx<S> tryOf(int i, Class<S> sexpInterface) {
private @Nullable <S extends SEXP> TypedIdx<S> tryOf(int i, Class<S> sexpInterface) {
var idx = new TypedIdx<>(pool, i, sexpInterface);
if (!idx.checkType()) {
return null;
Expand Down Expand Up @@ -316,7 +316,7 @@ public Builder() {
public <S extends SEXP> TypedIdx<S> add(S c) {
// This only works because TypedIdx is covariant the and generic gets erased.
// We actually cast TypedIdx<something more specific than S> into TypedIdx<S>.
@SuppressWarnings("unchecked") var idx = (TypedIdx<S>)consts.computeIfAbsent(c, (ignored) -> new TypedIdx<S>(pool, consts.size(), (Class<S>)c.getClass()));
@SuppressWarnings("unchecked") var idx = (TypedIdx<S>)consts.computeIfAbsent(c, (ignored) -> new TypedIdx<>(pool, consts.size(), (Class<S>)c.getClass()));
return idx;
}

Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/prlprg/sexp/SimpleScalarSXPImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,24 @@

/** Class for representing a scalar SEXP of a primitive type with no attributes. */
@Immutable
abstract non-sealed class SimpleScalarSXPImpl<T> implements VectorSXP<T> {
abstract class SimpleScalarSXPImpl<T> {
final T data;

protected SimpleScalarSXPImpl(T data) {
this.data = data;
}

@Override
public UnmodifiableIterator<T> iterator() {
return Iterators.forArray(data);
}

@Override
public T get(int i) {
if (i != 0) {
throw new IndexOutOfBoundsException();
}
return data;
}

@Override
public int size() {
return 1;
}
Expand All @@ -38,7 +35,6 @@ public String toString() {
return data.toString();
}

@Override
public Attributes attributes() {
return Attributes.NONE;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/prlprg/sexp/VectorSXP.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.stream.BaseStream;

public sealed interface VectorSXP<T> extends ListOrVectorSXP<T> permits ComplexSXP, ExprSXP, IntSXP, LglSXP, RealSXP, StrSXP, VecSXP, SimpleScalarSXPImpl, EmptyVectorSXPImpl {
public sealed interface VectorSXP<T> extends ListOrVectorSXP<T> permits ComplexSXP, ExprSXP, IntSXP, LglSXP, RealSXP, StrSXP, VecSXP, EmptyVectorSXPImpl {
@Override Attributes attributes();

@Override
Expand Down

0 comments on commit 60a85a2

Please sign in to comment.