Skip to content

Commit

Permalink
refactor: adopt jspecify to spoon.support.compiler (#5422)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenax66 committed Sep 5, 2023
1 parent 75584ab commit b86ef72
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/main/java/spoon/support/compiler/SpoonPom.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.maven.shared.invoker.MavenInvocationException;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import spoon.Launcher;
import spoon.MavenLauncher;
Expand Down Expand Up @@ -332,7 +333,7 @@ private String extractVariable(String value) {
* @param key the key of the property
* @return the property value if key exists or null
*/
private String getProperty(String key) {
private @Nullable String getProperty(String key) {
if ("project.version".equals(key) || "pom.version".equals(key) || "version".equals(key)) {
if (model.getVersion() != null) {
return model.getVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.slf4j.LoggerFactory;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
import org.jspecify.annotations.Nullable;

import spoon.SpoonException;
import spoon.reflect.code.CtAbstractSwitch;
import spoon.reflect.code.CtBinaryOperator;
Expand Down Expand Up @@ -572,7 +574,7 @@ public void scan(CtElement element) {
* @param e
* @return body of element or null if this element has no body
*/
static CtElement getBody(CtElement e) {
static @Nullable CtElement getBody(CtElement e) {
if (e instanceof CtBodyHolder) {
return ((CtBodyHolder) e).getBody();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/spoon/support/compiler/jdt/ParentExiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
import org.eclipse.jdt.internal.compiler.ast.UnionTypeReference;
import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding;
import org.jspecify.annotations.Nullable;

import spoon.SpoonException;
import spoon.reflect.code.BinaryOperatorKind;
Expand Down Expand Up @@ -1041,7 +1042,7 @@ public void visitCtTry(CtTry tryBlock) {
* @param tryBlock
* @return last CtCatch of `tryBlock` or null
*/
private CtCatch getLastCatcher(CtTry tryBlock) {
private @Nullable CtCatch getLastCatcher(CtTry tryBlock) {
List<CtCatch> catchers = tryBlock.getCatchers();
int nrCatchers = catchers.size();
if (nrCatchers > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ <T> CtTypeReference<T> getQualifiedTypeReference(char[][] tokens, TypeBinding re
* @param expectedName Name expected in imports.
* @return CtReference which can be a CtTypeReference, a CtPackageReference or null.
*/
CtReference getDeclaringReferenceFromImports(char[] expectedName) {
@Nullable CtReference getDeclaringReferenceFromImports(char[] expectedName) {
CompilationUnitDeclaration cuDeclaration = this.jdtTreeBuilder.getContextBuilder().compilationunitdeclaration;
if (cuDeclaration == null) {
return null;
Expand Down Expand Up @@ -887,7 +887,7 @@ <T> CtTypeReference<T> getTypeReference(TypeBinding binding, boolean resolveGene
* @return a type reference or null if the binding has no closest match
*/
@SuppressWarnings("ReturnOfNull")
private CtTypeReference<?> getTypeReferenceFromUnresolvedReferenceBinding(UnresolvedReferenceBinding binding) {
private @Nullable CtTypeReference<?> getTypeReferenceFromUnresolvedReferenceBinding(UnresolvedReferenceBinding binding) {
TypeBinding closestMatch = binding.closestMatch();
if (closestMatch != null) {
CtTypeReference<?> ref = this.jdtTreeBuilder.getFactory().Core().createTypeReference();
Expand Down

0 comments on commit b86ef72

Please sign in to comment.