From a7c22bd901e7c40ce9da0bb56604b2491e6e4f75 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 29 Nov 2013 13:43:48 +0100 Subject: [PATCH] WI-21234 (NPE fixed, method argument annotated) --- .../actions/GotoBreakContinueHandler.java | 6 +++--- .../actions/GotoLambdaParameterHandler.java | 4 ++-- .../actions/GotoDeclarationAction.java | 2 +- .../actions/GotoDeclarationHandler.java | 17 ++++++++--------- .../actions/GotoDeclarationHandlerBase.java | 8 ++++---- .../I18nMessageGotoDeclarationHandler.java | 5 ++--- .../com/jetbrains/rest/RestGotoProvider.java | 8 +++++--- .../PyBreakContinueGotoProvider.java | 9 +++++---- 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoBreakContinueHandler.java b/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoBreakContinueHandler.java index 90e1720f1dda..b20c81707621 100644 --- a/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoBreakContinueHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoBreakContinueHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,11 @@ import org.jetbrains.annotations.Nullable; * @author yole */ public class GotoBreakContinueHandler extends GotoDeclarationHandlerBase { - private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.navigation.actions.GotoBreakContinueHandler"); + private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.navigation.actions.GotoBreakContinueHandler"); @Override @Nullable - public PsiElement getGotoDeclarationTarget(final PsiElement elementAt, Editor editor) { + public PsiElement getGotoDeclarationTarget(@Nullable PsiElement elementAt, Editor editor) { if (elementAt instanceof PsiKeyword) { IElementType type = ((PsiKeyword)elementAt).getTokenType(); if (type == JavaTokenType.CONTINUE_KEYWORD) { diff --git a/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoLambdaParameterHandler.java b/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoLambdaParameterHandler.java index 183bcbe14f6d..7585b2028f85 100644 --- a/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoLambdaParameterHandler.java +++ b/java/java-impl/src/com/intellij/codeInsight/navigation/actions/GotoLambdaParameterHandler.java @@ -20,10 +20,9 @@ import com.intellij.psi.*; import org.jetbrains.annotations.Nullable; public class GotoLambdaParameterHandler extends GotoDeclarationHandlerBase { - @Override @Nullable - public PsiElement getGotoDeclarationTarget(final PsiElement elementAt, Editor editor) { + public PsiElement getGotoDeclarationTarget(@Nullable PsiElement elementAt, Editor editor) { if (elementAt instanceof PsiIdentifier) { PsiElement parent = elementAt.getParent(); if (parent instanceof PsiParameter && ((PsiParameter)parent).getTypeElement() == null) { @@ -33,6 +32,7 @@ public class GotoLambdaParameterHandler extends GotoDeclarationHandlerBase { } } } + return null; } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java index 0a25d16fdba2..05ab47990ae9 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationAction.java @@ -199,8 +199,8 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code if (file == null) { return null; } - PsiElement elementAt = file.findElementAt(TargetElementUtilBase.adjustOffset(file, document, offset)); + PsiElement elementAt = file.findElementAt(TargetElementUtilBase.adjustOffset(file, document, offset)); for (GotoDeclarationHandler handler : Extensions.getExtensions(GotoDeclarationHandler.EP_NAME)) { try { PsiElement[] result = handler.getGotoDeclarationTargets(elementAt, offset, editor); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandler.java index aaadb906e529..9a616bddf0a7 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.codeInsight.navigation.actions; import com.intellij.openapi.actionSystem.DataContext; @@ -31,18 +30,18 @@ public interface GotoDeclarationHandler { /** * Provides an array of target declarations for given {@code sourceElement}. * - * - * @param sourceElement input psiElement - * @param offset offset in the file - *@param editor @return all target declarations as an array of {@code PsiElement} or null if none was found + * @param sourceElement input PSI element + * @param offset offset in the file + * @param editor @return all target declarations as an array of {@code PsiElement} or null if none was found */ @Nullable - PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor); + PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor); /** - * Provides the custom action text - * @return the custom text or null to use the default text + * Provides the custom action text. + * * @param context the action data context + * @return the custom text or null to use the default text */ @Nullable String getActionText(DataContext context); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandlerBase.java b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandlerBase.java index 0fdff17b339e..038bd715d947 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandlerBase.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/navigation/actions/GotoDeclarationHandlerBase.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,13 +26,13 @@ import org.jetbrains.annotations.Nullable; public abstract class GotoDeclarationHandlerBase implements GotoDeclarationHandler { @Nullable @Override - public PsiElement[] getGotoDeclarationTargets(PsiElement sourceElement, int offset, Editor editor) { + public PsiElement[] getGotoDeclarationTargets(@Nullable PsiElement sourceElement, int offset, Editor editor) { final PsiElement target = getGotoDeclarationTarget(sourceElement, editor); - return target != null ? new PsiElement[] {target} : null; + return target != null ? new PsiElement[]{target} : null; } @Nullable - public abstract PsiElement getGotoDeclarationTarget(PsiElement sourceElement, Editor editor); + public abstract PsiElement getGotoDeclarationTarget(@Nullable PsiElement sourceElement, Editor editor); @Override public String getActionText(DataContext context) { diff --git a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/I18nMessageGotoDeclarationHandler.java b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/I18nMessageGotoDeclarationHandler.java index b70466396284..592bfbc6051f 100644 --- a/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/I18nMessageGotoDeclarationHandler.java +++ b/plugins/java-i18n/src/com/intellij/codeInspection/i18n/folding/I18nMessageGotoDeclarationHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2013 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,6 @@ import com.intellij.lang.folding.CompositeFoldingBuilder; import com.intellij.lang.folding.FoldingBuilder; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.FoldRegion; -import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.util.Key; import com.intellij.psi.*; import org.jetbrains.annotations.Nullable; @@ -34,7 +33,7 @@ public class I18nMessageGotoDeclarationHandler extends GotoDeclarationHandlerBas private static final Key KEY = CompositeFoldingBuilder.FOLDING_BUILDER; @Override - public PsiElement getGotoDeclarationTarget(PsiElement element, Editor editor) { + public PsiElement getGotoDeclarationTarget(@Nullable PsiElement element, Editor editor) { if (!(element instanceof PsiJavaToken)) return null; int i = 4; //some street magic diff --git a/python/rest/src/com/jetbrains/rest/RestGotoProvider.java b/python/rest/src/com/jetbrains/rest/RestGotoProvider.java index 652620228941..f032851afeb6 100644 --- a/python/rest/src/com/jetbrains/rest/RestGotoProvider.java +++ b/python/rest/src/com/jetbrains/rest/RestGotoProvider.java @@ -20,19 +20,21 @@ import com.intellij.openapi.editor.Editor; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.rest.psi.RestReference; +import org.jetbrains.annotations.Nullable; /** - * User : catherine + * @author catherine */ public class RestGotoProvider extends GotoDeclarationHandlerBase { - - public PsiElement getGotoDeclarationTarget(PsiElement source, Editor editor) { + @Override + public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) { if (source != null && source.getLanguage() instanceof RestLanguage) { RestReference ref = PsiTreeUtil.getParentOfType(source, RestReference.class); if (ref != null) { return ref.resolve(); } } + return null; } } diff --git a/python/src/com/jetbrains/python/codeInsight/PyBreakContinueGotoProvider.java b/python/src/com/jetbrains/python/codeInsight/PyBreakContinueGotoProvider.java index 51ff238e0f66..778999a15c61 100644 --- a/python/src/com/jetbrains/python/codeInsight/PyBreakContinueGotoProvider.java +++ b/python/src/com/jetbrains/python/codeInsight/PyBreakContinueGotoProvider.java @@ -26,15 +26,15 @@ import com.intellij.psi.util.PsiTreeUtil; import com.jetbrains.python.PyTokenTypes; import com.jetbrains.python.PythonLanguage; import com.jetbrains.python.psi.*; +import org.jetbrains.annotations.Nullable; /** * Provides reaction on ctrl+click for {@code break} and {@code continue} statements. - * User: dcheryasov - * Date: Nov 5, 2009 4:58:54 AM + * @author dcheryasov */ public class PyBreakContinueGotoProvider extends GotoDeclarationHandlerBase { - - public PsiElement getGotoDeclarationTarget(PsiElement source, Editor editor) { + @Override + public PsiElement getGotoDeclarationTarget(@Nullable PsiElement source, Editor editor) { if (source != null && source.getLanguage() instanceof PythonLanguage) { final PyLoopStatement loop = PsiTreeUtil.getParentOfType(source, PyLoopStatement.class, false, PyFunction.class, PyClass.class); if (loop != null) { @@ -66,6 +66,7 @@ public class PyBreakContinueGotoProvider extends GotoDeclarationHandlerBase { } } } + return null; } }