Add nullability annotations
This commit is contained in:
@@ -158,13 +158,14 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static FqName getFQName(JetFile file) {
|
@NotNull
|
||||||
|
public static FqName getFQName(@NotNull JetFile file) {
|
||||||
JetNamespaceHeader header = file.getNamespaceHeader();
|
JetNamespaceHeader header = file.getNamespaceHeader();
|
||||||
return header != null ? header.getFqName() : FqName.ROOT;
|
return header != null ? header.getFqName() : FqName.ROOT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static FqName getFQName(JetNamedDeclaration namedDeclaration) {
|
public static FqName getFQName(@NotNull JetNamedDeclaration namedDeclaration) {
|
||||||
if (namedDeclaration instanceof JetObjectDeclarationName) {
|
if (namedDeclaration instanceof JetObjectDeclarationName) {
|
||||||
JetNamedDeclaration objectDeclaration = PsiTreeUtil.getParentOfType(namedDeclaration, JetObjectDeclaration.class);
|
JetNamedDeclaration objectDeclaration = PsiTreeUtil.getParentOfType(namedDeclaration, JetObjectDeclaration.class);
|
||||||
if (objectDeclaration == null) {
|
if (objectDeclaration == null) {
|
||||||
@@ -233,7 +234,7 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static Name getShortName(JetAnnotationEntry annotation) {
|
public static Name getShortName(@NotNull JetAnnotationEntry annotation) {
|
||||||
JetTypeReference typeReference = annotation.getTypeReference();
|
JetTypeReference typeReference = annotation.getTypeReference();
|
||||||
assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
|
assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
|
||||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||||
@@ -247,7 +248,7 @@ public class JetPsiUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isDeprecated(JetModifierListOwner owner) {
|
public static boolean isDeprecated(@NotNull JetModifierListOwner owner) {
|
||||||
JetModifierList modifierList = owner.getModifierList();
|
JetModifierList modifierList = owner.getModifierList();
|
||||||
if (modifierList != null) {
|
if (modifierList != null) {
|
||||||
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||||
@@ -263,7 +264,7 @@ public class JetPsiUtil {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@IfNotParsed
|
@IfNotParsed
|
||||||
public static ImportPath getImportPath(JetImportDirective importDirective) {
|
public static ImportPath getImportPath(@NotNull JetImportDirective importDirective) {
|
||||||
if (PsiTreeUtil.hasErrorElements(importDirective)) {
|
if (PsiTreeUtil.hasErrorElements(importDirective)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -410,7 +411,7 @@ public class JetPsiUtil {
|
|||||||
return callOperationNode != null && callOperationNode.getElementType() == JetTokens.SAFE_ACCESS;
|
return callOperationNode != null && callOperationNode.getElementType() == JetTokens.SAFE_ACCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isFunctionLiteralWithoutDeclaredParameterTypes(JetExpression expression) {
|
public static boolean isFunctionLiteralWithoutDeclaredParameterTypes(@Nullable JetExpression expression) {
|
||||||
if (!(expression instanceof JetFunctionLiteralExpression)) return false;
|
if (!(expression instanceof JetFunctionLiteralExpression)) return false;
|
||||||
JetFunctionLiteralExpression functionLiteral = (JetFunctionLiteralExpression) expression;
|
JetFunctionLiteralExpression functionLiteral = (JetFunctionLiteralExpression) expression;
|
||||||
for (JetParameter parameter : functionLiteral.getValueParameters()) {
|
for (JetParameter parameter : functionLiteral.getValueParameters()) {
|
||||||
@@ -462,6 +463,7 @@ public class JetPsiUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) {
|
public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
return null;
|
return null;
|
||||||
@@ -568,6 +570,7 @@ public class JetPsiUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private static IElementType getOperation(@NotNull JetExpression expression) {
|
private static IElementType getOperation(@NotNull JetExpression expression) {
|
||||||
if (expression instanceof JetQualifiedExpression) {
|
if (expression instanceof JetQualifiedExpression) {
|
||||||
return ((JetQualifiedExpression) expression).getOperationSign();
|
return ((JetQualifiedExpression) expression).getOperationSign();
|
||||||
@@ -683,6 +686,7 @@ public class JetPsiUtil {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
public static <C extends Collection<JetVariableDeclaration>> C getBlockVariableDeclarations(@NotNull JetBlockExpression block, @NotNull C collection) {
|
public static <C extends Collection<JetVariableDeclaration>> C getBlockVariableDeclarations(@NotNull JetBlockExpression block, @NotNull C collection) {
|
||||||
for (JetElement element : block.getStatements()) {
|
for (JetElement element : block.getStatements()) {
|
||||||
if (element instanceof JetVariableDeclaration) {
|
if (element instanceof JetVariableDeclaration) {
|
||||||
@@ -693,7 +697,7 @@ public class JetPsiUtil {
|
|||||||
return collection;
|
return collection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean checkWhenExpressionHasSingleElse(JetWhenExpression whenExpression) {
|
public static boolean checkWhenExpressionHasSingleElse(@NotNull JetWhenExpression whenExpression) {
|
||||||
int elseCount = 0;
|
int elseCount = 0;
|
||||||
for (JetWhenEntry entry : whenExpression.getEntries()) {
|
for (JetWhenEntry entry : whenExpression.getEntries()) {
|
||||||
if (entry.isElse()) {
|
if (entry.isElse()) {
|
||||||
@@ -703,7 +707,8 @@ public class JetPsiUtil {
|
|||||||
return (elseCount == 1);
|
return (elseCount == 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static PsiElement skipTrailingWhitespacesAndComments(PsiElement element) {
|
@Nullable
|
||||||
|
public static PsiElement skipTrailingWhitespacesAndComments(@Nullable PsiElement element) {
|
||||||
return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class, PsiComment.class);
|
return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class, PsiComment.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user