From b86ef7255e852d185db0e91948388e3df38d8dd3 Mon Sep 17 00:00:00 2001 From: Ryota Hiyoshi <115792382+tenax66@users.noreply.github.com> Date: Wed, 6 Sep 2023 02:08:36 +0900 Subject: [PATCH] refactor: adopt jspecify to `spoon.support.compiler` (#5422) --- src/main/java/spoon/support/compiler/SpoonPom.java | 3 ++- .../java/spoon/support/compiler/jdt/JDTCommentBuilder.java | 4 +++- src/main/java/spoon/support/compiler/jdt/ParentExiter.java | 3 ++- .../java/spoon/support/compiler/jdt/ReferenceBuilder.java | 4 ++-- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/spoon/support/compiler/SpoonPom.java b/src/main/java/spoon/support/compiler/SpoonPom.java index 38e8ade9036..d2fe5726535 100644 --- a/src/main/java/spoon/support/compiler/SpoonPom.java +++ b/src/main/java/spoon/support/compiler/SpoonPom.java @@ -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; @@ -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(); diff --git a/src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java index 5233dae4951..f331a2a1b3f 100644 --- a/src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/JDTCommentBuilder.java @@ -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; @@ -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(); } diff --git a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java index 69adb573c8d..989abef9761 100644 --- a/src/main/java/spoon/support/compiler/jdt/ParentExiter.java +++ b/src/main/java/spoon/support/compiler/jdt/ParentExiter.java @@ -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; @@ -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 catchers = tryBlock.getCatchers(); int nrCatchers = catchers.size(); if (nrCatchers > 0) { diff --git a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java index 38c3d1af23e..4452b296163 100644 --- a/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java +++ b/src/main/java/spoon/support/compiler/jdt/ReferenceBuilder.java @@ -309,7 +309,7 @@ CtTypeReference 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; @@ -887,7 +887,7 @@ CtTypeReference 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();