[java] NPE in MethodReturnTypeMacro (EA-118342)

This commit is contained in:
Roman Shevchenko
2018-03-20 14:41:03 +01:00
parent 4c267f29ba
commit 7c3225907a
@@ -1,23 +1,10 @@
/*
* Copyright 2000-2009 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight.template.macro;
import com.intellij.codeInsight.template.*;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import com.intellij.psi.PsiType;
import org.jetbrains.annotations.NotNull;
/**
@@ -41,14 +28,21 @@ public class MethodReturnTypeMacro extends Macro {
}
@Override
public Result calculateResult(@NotNull final Expression[] params, final ExpressionContext context) {
public Result calculateResult(@NotNull Expression[] params, ExpressionContext context) {
PsiElement place = context.getPsiElementAtStartOffset();
while(place != null){
if (place instanceof PsiMethod){
return new PsiTypeResult(((PsiMethod)place).getReturnType(), place.getProject());
while (place != null) {
if (place instanceof PsiMethod) {
PsiType returnType = ((PsiMethod)place).getReturnType();
if (returnType != null) {
return new PsiTypeResult(returnType, place.getProject());
}
else {
break;
}
}
place = place.getParent();
}
return null;
}
@@ -56,6 +50,4 @@ public class MethodReturnTypeMacro extends Macro {
public boolean isAcceptableInContext(TemplateContextType context) {
return context instanceof JavaCodeContextType;
}
}
}