mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
(no message)
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
class ChangeSignatureTest {
|
||||
void <caret>foo() {
|
||||
}
|
||||
|
||||
void bar() {
|
||||
foo();
|
||||
}
|
||||
|
||||
{
|
||||
bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class ChangeSignatureTest {
|
||||
void foo() throws Exception {
|
||||
}
|
||||
|
||||
void bar() throws Exception {
|
||||
foo();
|
||||
}
|
||||
|
||||
{
|
||||
try {
|
||||
bar();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
class ChangeSignatureTest {
|
||||
void <caret>foo() {
|
||||
}
|
||||
|
||||
void bar() {
|
||||
foo();
|
||||
}
|
||||
|
||||
{
|
||||
bar();
|
||||
}
|
||||
}
|
||||
|
||||
class Derived extends ChangeSignatureTest {
|
||||
void bar () {
|
||||
super.bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
class ChangeSignatureTest {
|
||||
void foo() throws Exception {
|
||||
}
|
||||
|
||||
void bar() throws Exception {
|
||||
foo();
|
||||
}
|
||||
|
||||
{
|
||||
try {
|
||||
bar();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Derived extends ChangeSignatureTest {
|
||||
void bar () throws Exception {
|
||||
super.bar();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class ChangeSignatureTest {
|
||||
public <caret>ChangeSignatureTest() {
|
||||
}
|
||||
|
||||
void foo() {
|
||||
new ChangeSignatureTest();
|
||||
}
|
||||
|
||||
{
|
||||
foo();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
class ChangeSignatureTest {
|
||||
public ChangeSignatureTest(Class clazz) {
|
||||
}
|
||||
|
||||
void foo(Class clazz) {
|
||||
new ChangeSignatureTest(clazz);
|
||||
}
|
||||
|
||||
{
|
||||
foo(null);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
class ChangeSignatureTest {
|
||||
public <caret>ChangeSignatureTest() {
|
||||
}
|
||||
|
||||
void foo() {
|
||||
new ChangeSignatureTest();
|
||||
}
|
||||
|
||||
{
|
||||
foo();
|
||||
}
|
||||
}
|
||||
|
||||
class Derived extends ChangeSignatureTest {
|
||||
void foo () {}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
class ChangeSignatureTest {
|
||||
public ChangeSignatureTest(Class clazz) {
|
||||
}
|
||||
|
||||
void foo(Class clazz) {
|
||||
new ChangeSignatureTest(clazz);
|
||||
}
|
||||
|
||||
{
|
||||
foo(null);
|
||||
}
|
||||
}
|
||||
|
||||
class Derived extends ChangeSignatureTest {
|
||||
Derived() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
void foo(Class clazz) {}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.changeSignature.ChangeSignatureProcessor;
|
||||
import com.intellij.refactoring.changeSignature.ParameterInfo;
|
||||
import com.intellij.refactoring.changeSignature.ThrownExceptionInfo;
|
||||
import com.intellij.refactoring.util.CanonicalTypes;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class ChangeSignaturePropagationTest extends CodeInsightTestCase {
|
||||
public void testParamSimple() throws Exception {
|
||||
parameterPropagationTest();
|
||||
}
|
||||
|
||||
public void testParamWithOverriding() throws Exception {
|
||||
parameterPropagationTest();
|
||||
}
|
||||
|
||||
public void testExceptionSimple() throws Exception {
|
||||
exceptionPropagationTest();
|
||||
}
|
||||
|
||||
public void testExceptionWithOverriding() throws Exception {
|
||||
exceptionPropagationTest();
|
||||
}
|
||||
|
||||
private void parameterPropagationTest() throws Exception {
|
||||
PsiMethod method = getPrimaryMethod();
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
PsiType newParamType = myPsiManager.getElementFactory().createTypeByFQClassName("java.lang.Class", GlobalSearchScope.allScope(myProject));
|
||||
final ParameterInfo[] newParameters = new ParameterInfo[]{new ParameterInfo(-1, "clazz", newParamType, "null")};
|
||||
final Set<PsiMethod> methodsToPropagateParameters = new HashSet<PsiMethod>(Arrays.asList(aClass.getMethods()));
|
||||
doTest(newParameters, new ThrownExceptionInfo[0], methodsToPropagateParameters, null, method);
|
||||
}
|
||||
|
||||
private void exceptionPropagationTest() throws Exception {
|
||||
PsiMethod method = getPrimaryMethod();
|
||||
PsiClass aClass = method.getContainingClass();
|
||||
PsiClassType newExceptionType = myPsiManager.getElementFactory().createTypeByFQClassName("java.lang.Exception", GlobalSearchScope.allScope(myProject));
|
||||
final ThrownExceptionInfo[] newExceptions = new ThrownExceptionInfo[]{new ThrownExceptionInfo(-1, newExceptionType)};
|
||||
final Set<PsiMethod> methodsToPropagateExceptions = new HashSet<PsiMethod>(Arrays.asList(aClass.getMethods()));
|
||||
doTest(new ParameterInfo[0], newExceptions, null, methodsToPropagateExceptions, method);
|
||||
}
|
||||
|
||||
private void doTest(ParameterInfo[] newParameters,
|
||||
final ThrownExceptionInfo[] newExceptions,
|
||||
Set<PsiMethod> methodsToPropagateParameterChanges,
|
||||
Set<PsiMethod> methodsToPropagateExceptionChanges,
|
||||
PsiMethod primaryMethod) throws Exception {
|
||||
final String filePath = getBasePath() + getTestName(false) + ".java";
|
||||
final PsiType returnType = primaryMethod.getReturnType();
|
||||
final CanonicalTypes.Type type = returnType == null ? null : CanonicalTypes.createTypeWrapper(returnType);
|
||||
new ChangeSignatureProcessor(myProject, primaryMethod, false, null,
|
||||
primaryMethod.getName(),
|
||||
type,
|
||||
generateParameterInfos(primaryMethod, newParameters),
|
||||
generateExceptionInfos(primaryMethod, newExceptions),
|
||||
methodsToPropagateParameterChanges,
|
||||
methodsToPropagateExceptionChanges).testRun();
|
||||
checkResultByFile(filePath + ".after");
|
||||
}
|
||||
|
||||
private PsiMethod getPrimaryMethod() throws Exception {
|
||||
final String filePath = getBasePath() + getTestName(false) + ".java";
|
||||
configureByFile(filePath);
|
||||
final PsiElement targetElement = TargetElementUtil.findTargetElement(myEditor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue("<caret> is not on method name", targetElement instanceof PsiMethod);
|
||||
return (PsiMethod) targetElement;
|
||||
}
|
||||
|
||||
private String getBasePath() {
|
||||
return "/refactoring/changeSignaturePropagation/";
|
||||
}
|
||||
|
||||
private ParameterInfo[] generateParameterInfos (PsiMethod method, ParameterInfo[] newParameters) {
|
||||
final PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
ParameterInfo[] result = new ParameterInfo[parameters.length + newParameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
result[i] = new ParameterInfo(i);
|
||||
}
|
||||
System.arraycopy(newParameters, 0, result, parameters.length, newParameters.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
private ThrownExceptionInfo[] generateExceptionInfos (PsiMethod method, ThrownExceptionInfo[] newExceptions) {
|
||||
final PsiClassType[] exceptions = method.getThrowsList().getReferencedTypes();
|
||||
ThrownExceptionInfo[] result = new ThrownExceptionInfo[exceptions.length + newExceptions.length];
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
result[i] = new ThrownExceptionInfo(i);
|
||||
}
|
||||
System.arraycopy(newExceptions, 0, result, exceptions.length, newExceptions.length);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user