Skip to content

Commit

Permalink
refactor: Apply the @Nullable annotation to spoon.support (#5456)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenax66 authored Sep 26, 2023
1 parent 3baf672 commit e311c3d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/spoon/support/modelobs/ChangeCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Map;
import java.util.Set;

import org.jspecify.annotations.Nullable;
import spoon.compiler.Environment;
import spoon.reflect.CtModel;
import spoon.reflect.declaration.CtElement;
Expand All @@ -35,7 +36,7 @@ public class ChangeCollector {
* @param env to be checked {@link Environment}
* @return {@link ChangeCollector} attached to the `env` or null if there is none
*/
public static ChangeCollector getChangeCollector(Environment env) {
public static @Nullable ChangeCollector getChangeCollector(Environment env) {
FineModelChangeListener mcl = env.getModelChangeListener();
if (mcl instanceof ChangeListener) {
return ((ChangeListener) mcl).getChangeCollector();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package spoon.support.sniper.internal;

import org.jspecify.annotations.Nullable;
import spoon.reflect.cu.SourcePositionHolder;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.path.CtRole;
Expand All @@ -29,7 +30,7 @@ public CtRole getRole() {
}

@Override
public SourcePositionHolder getElement() {
public @Nullable SourcePositionHolder getElement() {
return element;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package spoon.support.sniper.internal;


import org.jspecify.annotations.Nullable;
import spoon.SpoonException;
import spoon.reflect.code.CtComment;
import spoon.reflect.code.CtLiteral;
Expand Down Expand Up @@ -235,7 +236,7 @@ protected void exit(CtElement e) {
* @param otherElement {@link SourcePositionHolder} whose {@link ElementSourceFragment} has to be added to `parentFragment`
* @return new {@link ElementSourceFragment} created for `otherElement` or null if `otherElement` cannot be included
*/
private ElementSourceFragment addChild(CtRole roleInParent, SourcePositionHolder otherElement) {
private @Nullable ElementSourceFragment addChild(CtRole roleInParent, SourcePositionHolder otherElement) {
SourcePosition otherSourcePosition = otherElement.getPosition();
if (otherSourcePosition instanceof SourcePositionImpl && !(otherSourcePosition.getCompilationUnit() instanceof NoSourcePosition.NullCompilationUnit)
// method imports have child type references from other files, see https://github.com/INRIA/spoon/issues/3743
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package spoon.support.sniper.internal;

import org.jspecify.annotations.Nullable;
import spoon.reflect.cu.SourcePositionHolder;
import spoon.reflect.path.CtRole;

Expand All @@ -31,6 +32,6 @@ public interface PrinterEvent {
/**
* @return printed element or null if printing a primitive token
*/
SourcePositionHolder getElement();
@Nullable SourcePositionHolder getElement();

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.HashSet;
import java.util.Set;

import org.jspecify.annotations.Nullable;
import spoon.reflect.code.CtComment;
import spoon.reflect.cu.SourcePositionHolder;
import spoon.reflect.path.CtRole;
Expand Down Expand Up @@ -41,12 +42,12 @@ public CtRole getRole() {
}

@Override
public SourcePositionHolder getElement() {
public @Nullable SourcePositionHolder getElement() {
return comment;
}

/** @return printed token or null if printing complex element or comment */
public String getToken() {
public @Nullable String getToken() {
return token;
}

Expand Down

0 comments on commit e311c3d

Please sign in to comment.