WI-21234 (NPE fixed, method argument annotated)

This commit is contained in:
Roman Shevchenko
2013-11-29 13:45:01 +01:00
parent 8813143789
commit a7c22bd901
8 changed files with 30 additions and 29 deletions
@@ -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) {
@@ -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;
}
}
@@ -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);
@@ -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);
@@ -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) {
@@ -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<FoldingBuilder> 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
@@ -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;
}
}
@@ -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;
}
}