mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-103174 (type annotations in change signature)
This commit is contained in:
@@ -17,9 +17,11 @@ package com.intellij.refactoring.changeSignature;
|
||||
|
||||
import com.intellij.lang.LanguageRefactoringSupport;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.psi.JavaTokenType;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiType;
|
||||
import com.intellij.psi.impl.source.tree.Factory;
|
||||
import com.intellij.psi.impl.source.tree.SharedImplUtil;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
@@ -113,4 +115,10 @@ public class ChangeSignatureUtil {
|
||||
handler.invoke(project, new PsiElement[]{method}, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean deepTypeEqual(PsiType type1, PsiType type2) {
|
||||
if (type1 == type2) return true;
|
||||
if (type1 == null || !type1.equals(type2)) return false;
|
||||
return Comparing.equal(type1.getCanonicalText(true), type2.getCanonicalText(true));
|
||||
}
|
||||
}
|
||||
|
||||
+12
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -33,6 +33,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.intellij.refactoring.changeSignature.ChangeSignatureUtil.deepTypeEqual;
|
||||
|
||||
class JavaChangeInfoImpl implements JavaChangeInfo {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.changeSignature.JavaChangeInfoImpl");
|
||||
|
||||
@@ -195,22 +197,22 @@ class JavaChangeInfoImpl implements JavaChangeInfo {
|
||||
if (isNameChanged) {
|
||||
newNameIdentifier = factory.createIdentifier(newName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void fillOldParams(PsiMethod method) {
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
oldParameterNames = new String[parameters.length];
|
||||
oldParameterTypes = new String[parameters.length];
|
||||
for(int i = 0; i < parameters.length; i++){
|
||||
|
||||
PsiElementFactory factory = JavaPsiFacade.getInstance(method.getProject()).getElementFactory();
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiParameter parameter = parameters[i];
|
||||
oldParameterNames[i] = parameter.getName();
|
||||
oldParameterTypes[i] =
|
||||
JavaPsiFacade.getInstance(parameter.getProject()).getElementFactory().createTypeElement(parameter.getType()).getText();
|
||||
oldParameterTypes[i] = factory.createTypeElement(parameter.getType()).getText();
|
||||
}
|
||||
if (!method.isConstructor()){
|
||||
try {
|
||||
isReturnTypeChanged = !newReturnType.getType(this.method, method.getManager()).equals(this.method.getReturnType());
|
||||
isReturnTypeChanged = !deepTypeEqual(newReturnType.getType(this.method, method.getManager()), this.method.getReturnType());
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
isReturnTypeChanged = true;
|
||||
@@ -233,7 +235,9 @@ class JavaChangeInfoImpl implements JavaChangeInfo {
|
||||
}
|
||||
|
||||
private void setupExceptions(ThrownExceptionInfo[] newExceptions, final PsiMethod method) {
|
||||
if (newExceptions == null) newExceptions = JavaThrownExceptionInfo.extractExceptions(method);
|
||||
if (newExceptions == null) {
|
||||
newExceptions = JavaThrownExceptionInfo.extractExceptions(method);
|
||||
}
|
||||
|
||||
this.newExceptions = newExceptions;
|
||||
|
||||
@@ -242,7 +246,7 @@ class JavaChangeInfoImpl implements JavaChangeInfo {
|
||||
if (!isExceptionSetChanged) {
|
||||
for (int i = 0; i < newExceptions.length; i++) {
|
||||
try {
|
||||
if (newExceptions[i].getOldIndex() < 0 || !types[i].equals(newExceptions[i].createType(method, method.getManager()))) {
|
||||
if (newExceptions[i].getOldIndex() < 0 || !deepTypeEqual(types[i], newExceptions[i].createType(method, method.getManager()))) {
|
||||
isExceptionSetChanged = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2014 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.
|
||||
@@ -15,18 +15,16 @@
|
||||
*/
|
||||
package com.intellij.refactoring.util;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -34,61 +32,72 @@ import java.util.Map;
|
||||
* @author dsl
|
||||
*/
|
||||
public class CanonicalTypes {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.util.CanonicalTypes");
|
||||
|
||||
private CanonicalTypes() { }
|
||||
|
||||
public abstract static class Type {
|
||||
@NotNull
|
||||
public abstract PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException;
|
||||
public abstract PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException;
|
||||
|
||||
@NonNls
|
||||
public abstract String getTypeText();
|
||||
|
||||
public abstract void addImportsTo(final JavaCodeFragment codeFragment);
|
||||
public void addImportsTo(JavaCodeFragment fragment) { }
|
||||
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Primitive extends Type {
|
||||
private abstract static class AnnotatedType extends Type {
|
||||
protected final PsiAnnotation[] myAnnotations;
|
||||
|
||||
protected AnnotatedType(PsiAnnotation[] annotations) {
|
||||
myAnnotations = annotations;
|
||||
}
|
||||
}
|
||||
|
||||
private static class Primitive extends AnnotatedType {
|
||||
private final PsiPrimitiveType myType;
|
||||
|
||||
private Primitive(PsiPrimitiveType type) {
|
||||
super(type.getAnnotations());
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) {
|
||||
return myType;
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) {
|
||||
return myAnnotations.length == 0 ? myType : new PsiPrimitiveType(myType.getCanonicalText(false), myAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
return myType.getPresentableText();
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {}
|
||||
}
|
||||
|
||||
private static class Array extends Type {
|
||||
private final Type myComponentType;
|
||||
private static class Array extends AnnotatedType {
|
||||
protected final Type myComponentType;
|
||||
|
||||
private Array(Type componentType) {
|
||||
private Array(PsiType original, Type componentType) {
|
||||
super(original.getAnnotations());
|
||||
myComponentType = componentType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
return myComponentType.getType(context, manager).createArrayType();
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException {
|
||||
return myComponentType.getType(context, manager).createArrayType(myAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
return myComponentType.getTypeText() + "[]";
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {
|
||||
myComponentType.addImportsTo(codeFragment);
|
||||
@Override
|
||||
public void addImportsTo(JavaCodeFragment fragment) {
|
||||
myComponentType.addImportsTo(fragment);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,59 +106,64 @@ public class CanonicalTypes {
|
||||
}
|
||||
}
|
||||
|
||||
private static class Ellipsis extends Type {
|
||||
private final Type myComponentType;
|
||||
|
||||
private Ellipsis(Type componentType) {
|
||||
myComponentType = componentType;
|
||||
private static class Ellipsis extends Array {
|
||||
private Ellipsis(PsiType original, Type componentType) {
|
||||
super(original, componentType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
return new PsiEllipsisType(myComponentType.getType(context, manager));
|
||||
}
|
||||
|
||||
public String getTypeText() {
|
||||
return myComponentType.getTypeText() + "...";
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {
|
||||
myComponentType.addImportsTo(codeFragment);
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException {
|
||||
return new PsiEllipsisType(myComponentType.getType(context, manager), myAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return myComponentType.isValid();
|
||||
public String getTypeText() {
|
||||
return myComponentType.getTypeText() + "...";
|
||||
}
|
||||
}
|
||||
|
||||
private static class WildcardType extends Type {
|
||||
private static class WildcardType extends AnnotatedType {
|
||||
private final boolean myIsExtending;
|
||||
private final Type myBound;
|
||||
|
||||
private WildcardType(boolean isExtending, Type bound) {
|
||||
private WildcardType(PsiType original, boolean isExtending, Type bound) {
|
||||
super(original.getAnnotations());
|
||||
myIsExtending = isExtending;
|
||||
myBound = bound;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
if(myBound == null) return PsiWildcardType.createUnbounded(context.getManager());
|
||||
if (myIsExtending) {
|
||||
return PsiWildcardType.createExtends(context.getManager(), myBound.getType(context, manager));
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException {
|
||||
PsiWildcardType type;
|
||||
if (myBound == null) {
|
||||
type = PsiWildcardType.createUnbounded(manager);
|
||||
}
|
||||
else if (myIsExtending) {
|
||||
type = PsiWildcardType.createExtends(manager, myBound.getType(context, manager));
|
||||
}
|
||||
else {
|
||||
return PsiWildcardType.createSuper(context.getManager(), myBound.getType(context, manager));
|
||||
type = PsiWildcardType.createSuper(manager, myBound.getType(context, manager));
|
||||
}
|
||||
return type.annotate(myAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
if (myBound == null) {
|
||||
return "?";
|
||||
}
|
||||
else {
|
||||
return "? " + (myIsExtending ? "extends " : "super ") + myBound.getTypeText();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTypeText() {
|
||||
if (myBound == null) return "?";
|
||||
return "? " + (myIsExtending ? "extends " : "super ") + myBound.getTypeText();
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {
|
||||
if (myBound != null) myBound.addImportsTo(codeFragment);
|
||||
@Override
|
||||
public void addImportsTo(JavaCodeFragment fragment) {
|
||||
if (myBound != null) {
|
||||
myBound.addImportsTo(fragment);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -158,73 +172,74 @@ public class CanonicalTypes {
|
||||
}
|
||||
}
|
||||
|
||||
private static class WrongType extends Type {
|
||||
private final String myText;
|
||||
private static class UnresolvedType extends Type {
|
||||
private final String myPresentableText;
|
||||
private final String myCanonicalText;
|
||||
|
||||
private WrongType(String text) {
|
||||
myText = text;
|
||||
private UnresolvedType(PsiType original) {
|
||||
myPresentableText = original.getPresentableText();
|
||||
myCanonicalText = original.getCanonicalText(true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
return JavaPsiFacade.getInstance(context.getProject()).getElementFactory().createTypeFromText(myText, context);
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException {
|
||||
return JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeFromText(myCanonicalText, context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
return myText;
|
||||
return myPresentableText;
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static class ClassType extends Type {
|
||||
private final String myOriginalText;
|
||||
private static class ClassType extends AnnotatedType {
|
||||
private final String myPresentableText;
|
||||
private final String myClassQName;
|
||||
private final Map<String,Type> mySubstitutor;
|
||||
private final Map<String, Type> mySubstitutor;
|
||||
|
||||
private ClassType(String originalText, String classQName, Map<String, Type> substitutor) {
|
||||
myOriginalText = originalText;
|
||||
private ClassType(PsiType original, String classQName, Map<String, Type> substitutor) {
|
||||
super(original.getAnnotations());
|
||||
myPresentableText = original.getPresentableText();
|
||||
myClassQName = classQName;
|
||||
mySubstitutor = substitutor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public PsiType getType(PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
|
||||
final PsiElementFactory factory = facade.getElementFactory();
|
||||
final PsiResolveHelper resolveHelper = facade.getResolveHelper();
|
||||
final PsiClass aClass = resolveHelper.resolveReferencedClass(myClassQName, context);
|
||||
@Override
|
||||
public PsiType getType(PsiElement context, PsiManager manager) throws IncorrectOperationException {
|
||||
JavaPsiFacade facade = JavaPsiFacade.getInstance(manager.getProject());
|
||||
PsiElementFactory factory = facade.getElementFactory();
|
||||
|
||||
PsiClass aClass = facade.getResolveHelper().resolveReferencedClass(myClassQName, context);
|
||||
if (aClass == null) {
|
||||
return factory.createTypeFromText(myClassQName, context);
|
||||
}
|
||||
Map<PsiTypeParameter, PsiType> substitutionMap = new HashMap<PsiTypeParameter,PsiType>();
|
||||
|
||||
Map<PsiTypeParameter, PsiType> substitutionMap = ContainerUtil.newHashMap();
|
||||
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) {
|
||||
final String name = typeParameter.getName();
|
||||
final Type type = mySubstitutor.get(name);
|
||||
if (type != null) {
|
||||
substitutionMap.put(typeParameter, type.getType(context, manager));
|
||||
} else {
|
||||
substitutionMap.put(typeParameter, null);
|
||||
}
|
||||
Type substitute = mySubstitutor.get(typeParameter.getName());
|
||||
substitutionMap.put(typeParameter, substitute != null ? substitute.getType(context, manager) : null);
|
||||
}
|
||||
return factory.createType(aClass, factory.createSubstitutor(substitutionMap));
|
||||
return factory.createType(aClass, factory.createSubstitutor(substitutionMap), null, myAnnotations);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
return myOriginalText;
|
||||
return myPresentableText;
|
||||
}
|
||||
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {
|
||||
codeFragment.addImportsFromString(myClassQName);
|
||||
final Collection<Type> types = mySubstitutor.values();
|
||||
for (Type type : types) {
|
||||
@Override
|
||||
public void addImportsTo(JavaCodeFragment fragment) {
|
||||
fragment.addImportsFromString(myClassQName);
|
||||
for (Type type : mySubstitutor.values()) {
|
||||
if (type != null) {
|
||||
type.addImportsTo(codeFragment);
|
||||
type.addImportsTo(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,15 +248,18 @@ public class CanonicalTypes {
|
||||
private static class DisjunctionType extends Type {
|
||||
private final List<Type> myTypes;
|
||||
|
||||
private DisjunctionType(final List<Type> types) {
|
||||
private DisjunctionType(List<Type> types) {
|
||||
myTypes = types;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public PsiType getType(final PsiElement context, final PsiManager manager) throws IncorrectOperationException {
|
||||
final List<PsiType> types = ContainerUtil.map(myTypes, new Function<Type, PsiType>() {
|
||||
@Override public PsiType fun(Type type) { return type.getType(context, manager); }
|
||||
List<PsiType> types = ContainerUtil.map(myTypes, new Function<Type, PsiType>() {
|
||||
@Override
|
||||
public PsiType fun(Type type) {
|
||||
return type.getType(context, manager);
|
||||
}
|
||||
});
|
||||
return new PsiDisjunctionType(types, manager);
|
||||
}
|
||||
@@ -249,14 +267,17 @@ public class CanonicalTypes {
|
||||
@Override
|
||||
public String getTypeText() {
|
||||
return StringUtil.join(myTypes, new Function<Type, String>() {
|
||||
@Override public String fun(Type type) { return type.getTypeText(); }
|
||||
@Override
|
||||
public String fun(Type type) {
|
||||
return type.getTypeText();
|
||||
}
|
||||
}, "|");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addImportsTo(final JavaCodeFragment codeFragment) {
|
||||
public void addImportsTo(JavaCodeFragment fragment) {
|
||||
for (Type type : myTypes) {
|
||||
type.addImportsTo(codeFragment);
|
||||
type.addImportsTo(fragment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -265,65 +286,61 @@ public class CanonicalTypes {
|
||||
public static final Creator INSTANCE = new Creator();
|
||||
|
||||
@Override
|
||||
public Type visitPrimitiveType(final PsiPrimitiveType primitiveType) {
|
||||
return new Primitive(primitiveType);
|
||||
public Type visitPrimitiveType(PsiPrimitiveType type) {
|
||||
return new Primitive(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitEllipsisType(final PsiEllipsisType ellipsisType) {
|
||||
return new Ellipsis(ellipsisType.getComponentType().accept(this));
|
||||
public Type visitEllipsisType(PsiEllipsisType type) {
|
||||
return new Ellipsis(type, type.getComponentType().accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitArrayType(final PsiArrayType arrayType) {
|
||||
return new Array(arrayType.getComponentType().accept(this));
|
||||
public Type visitArrayType(PsiArrayType type) {
|
||||
return new Array(type, type.getComponentType().accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitWildcardType(final PsiWildcardType wildcardType) {
|
||||
final PsiType wildcardBound = wildcardType.getBound();
|
||||
final Type bound = wildcardBound == null ? null : wildcardBound.accept(this);
|
||||
return new WildcardType(wildcardType.isExtends(), bound);
|
||||
public Type visitWildcardType(PsiWildcardType type) {
|
||||
PsiType bound = type.getBound();
|
||||
return new WildcardType(type, type.isExtends(), bound == null ? null : bound.accept(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitClassType(final PsiClassType classType) {
|
||||
final PsiClassType.ClassResolveResult resolveResult = classType.resolveGenerics();
|
||||
final PsiClass aClass = resolveResult.getElement();
|
||||
public Type visitClassType(PsiClassType type) {
|
||||
PsiClassType.ClassResolveResult resolveResult = type.resolveGenerics();
|
||||
PsiClass aClass = resolveResult.getElement();
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
return visitClassType(((PsiAnonymousClass)aClass).getBaseClassType());
|
||||
}
|
||||
final String originalText = classType.getPresentableText();
|
||||
if (aClass == null) {
|
||||
return new WrongType(originalText);
|
||||
} else {
|
||||
final Map<String,Type> substitutionMap = new HashMap<String,Type>();
|
||||
final PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
else if (aClass == null) {
|
||||
return new UnresolvedType(type);
|
||||
}
|
||||
else {
|
||||
Map<String, Type> substitutionMap = ContainerUtil.newHashMap();
|
||||
PsiSubstitutor substitutor = resolveResult.getSubstitutor();
|
||||
for (PsiTypeParameter typeParameter : PsiUtil.typeParametersIterable(aClass)) {
|
||||
final PsiType type = substitutor.substitute(typeParameter);
|
||||
final String name = typeParameter.getName();
|
||||
if (type == null) {
|
||||
substitutionMap.put(name, null);
|
||||
} else {
|
||||
substitutionMap.put(name, type.accept(this));
|
||||
}
|
||||
PsiType substitute = substitutor.substitute(typeParameter);
|
||||
substitutionMap.put(typeParameter.getName(), substitute != null ? substitute.accept(this) : null);
|
||||
}
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
LOG.assertTrue(aClass.getName() != null);
|
||||
return new ClassType(originalText, qualifiedName != null ? qualifiedName : aClass.getName(), substitutionMap);
|
||||
String qualifiedName = ObjectUtils.notNull(aClass.getQualifiedName(), aClass.getName());
|
||||
return new ClassType(type, qualifiedName, substitutionMap);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type visitDisjunctionType(final PsiDisjunctionType disjunctionType) {
|
||||
final List<Type> types = ContainerUtil.map(disjunctionType.getDisjunctions(), new Function<PsiType, Type>() {
|
||||
@Override public Type fun(PsiType type) { return createTypeWrapper(type); }
|
||||
public Type visitDisjunctionType(PsiDisjunctionType type) {
|
||||
List<Type> types = ContainerUtil.map(type.getDisjunctions(), new Function<PsiType, Type>() {
|
||||
@Override
|
||||
public Type fun(PsiType type) {
|
||||
return type.accept(Creator.this);
|
||||
}
|
||||
});
|
||||
return new DisjunctionType(types);
|
||||
}
|
||||
}
|
||||
|
||||
public static Type createTypeWrapper(@NotNull final PsiType type) {
|
||||
public static Type createTypeWrapper(@NotNull PsiType type) {
|
||||
return type.accept(Creator.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.lang.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface TA { int value() default 0; }
|
||||
|
||||
class C {
|
||||
class Inner { }
|
||||
|
||||
//public @TA(0) List<@TA(1) C.@TA(1) Inner> m(@TA(2) int @TA(3) [] p1, @TA(4) List<@TA(5) Class<@TA(6) ?>> p2, @TA(7) String @TA(8) ... p3) throws @TA(42) IllegalArgumentException, @TA(43) IllegalStateException {
|
||||
public List<Inner> m<caret>() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import java.lang.annotation.*;
|
||||
import java.util.List;
|
||||
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface TA { int value() default 0; }
|
||||
|
||||
class C {
|
||||
class Inner { }
|
||||
|
||||
//public @TA(0) List<@TA(1) C.@TA(1) Inner> m(@TA(2) int @TA(3) [] p1, @TA(4) List<@TA(5) Class<@TA(6) ?>> p2, @TA(7) String @TA(8) ... p3) throws @TA(42) IllegalArgumentException, @TA(43) IllegalStateException {
|
||||
public @TA(0) List<@TA(1) Inner> m(@TA(2) int @TA(3) [] p1, @TA(4) List<@TA(5) Class<@TA(6) ?>> p2, @TA(7) String @TA(8) ... p3) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -36,6 +36,13 @@ import java.util.HashSet;
|
||||
public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
private PsiElementFactory myFactory;
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
myFactory = JavaPsiFacade.getInstance(getProject()).getElementFactory();
|
||||
@@ -413,8 +420,45 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
checkResultByFile(basePath + "_after.java");
|
||||
}
|
||||
|
||||
public void testTypeAnnotationsAllAround() {
|
||||
//String[] ps = {"@TA(1) int @TA(2) []", "java.util.@TA(4) List<@TA(5) Class<@TA(6) ?>>", "@TA(7) String @TA(8) ..."};
|
||||
//String[] ex = {"@TA(42) IllegalArgumentException", "java.lang.@TA(43) IllegalStateException"};
|
||||
//doTest("java.util.@TA(0) List<@TA(1) C.@TA(1) Inner>", ps, ex, false);
|
||||
String[] ps = {"@TA(2) int @TA(3) []", "@TA(4) List<@TA(5) Class<@TA(6) ?>>", "@TA(7) String @TA(8) ..."};
|
||||
String[] ex = {};
|
||||
doTest("@TA(0) List<@TA(1) Inner>", ps, ex, false);
|
||||
}
|
||||
|
||||
/* workers */
|
||||
|
||||
private void doTest(@Nullable String returnType, @Nullable final String[] parameters, @Nullable final String[] exceptions, boolean delegate) {
|
||||
GenParams genParams = parameters == null ? new SimpleParameterGen() : new GenParams() {
|
||||
@Override
|
||||
public ParameterInfoImpl[] genParams(PsiMethod method) throws IncorrectOperationException {
|
||||
ParameterInfoImpl[] parameterInfos = new ParameterInfoImpl[parameters.length];
|
||||
for (int i = 0; i < parameters.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(parameters[i], method);
|
||||
parameterInfos[i] = new ParameterInfoImpl(-1, "p" + (i + 1), type);
|
||||
}
|
||||
return parameterInfos;
|
||||
}
|
||||
};
|
||||
|
||||
GenExceptions genExceptions = exceptions == null ? new SimpleExceptionsGen() : new GenExceptions() {
|
||||
@Override
|
||||
public ThrownExceptionInfo[] genExceptions(PsiMethod method) throws IncorrectOperationException {
|
||||
ThrownExceptionInfo[] exceptionInfos = new ThrownExceptionInfo[exceptions.length];
|
||||
for (int i = 0; i < exceptions.length; i++) {
|
||||
PsiType type = myFactory.createTypeFromText(exceptions[i], method);
|
||||
exceptionInfos[i] = new JavaThrownExceptionInfo(-1, (PsiClassType)type);
|
||||
}
|
||||
return exceptionInfos;
|
||||
}
|
||||
};
|
||||
|
||||
doTest(null, null, returnType, genParams, genExceptions, delegate);
|
||||
}
|
||||
|
||||
private void doTest(@Nullable String newReturnType, ParameterInfoImpl[] parameterInfos, boolean generateDelegate) {
|
||||
doTest(null, null, newReturnType, parameterInfos, new ThrownExceptionInfo[0], generateDelegate);
|
||||
}
|
||||
@@ -425,15 +469,17 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
ParameterInfoImpl[] parameterInfo,
|
||||
ThrownExceptionInfo[] exceptionInfo,
|
||||
boolean generateDelegate) {
|
||||
doTest(newVisibility, newName, newReturnType, new SimpleParameterGen(parameterInfo), new SimpleExceptionsGen(exceptionInfo), generateDelegate);
|
||||
SimpleParameterGen params = new SimpleParameterGen(parameterInfo);
|
||||
SimpleExceptionsGen exceptions = new SimpleExceptionsGen(exceptionInfo);
|
||||
doTest(newVisibility, newName, newReturnType, params, exceptions, generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@Nullable String newName,
|
||||
@Nullable @NonNls String newReturnType,
|
||||
GenParams gen,
|
||||
GenParams genParams,
|
||||
boolean generateDelegate) {
|
||||
doTest(newVisibility, newName, newReturnType, gen, new SimpleExceptionsGen(), generateDelegate);
|
||||
doTest(newVisibility, newName, newReturnType, genParams, new SimpleExceptionsGen(), generateDelegate);
|
||||
}
|
||||
|
||||
private void doTest(@PsiModifier.ModifierConstant @Nullable String newVisibility,
|
||||
@@ -461,9 +507,9 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
private static class SimpleParameterGen implements GenParams {
|
||||
private ParameterInfoImpl[] myInfos;
|
||||
|
||||
private SimpleParameterGen() { }
|
||||
public SimpleParameterGen() { }
|
||||
|
||||
private SimpleParameterGen(ParameterInfoImpl[] infos) {
|
||||
public SimpleParameterGen(ParameterInfoImpl[] infos) {
|
||||
myInfos = infos;
|
||||
}
|
||||
|
||||
@@ -493,7 +539,7 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
myInfos = new ThrownExceptionInfo[0];
|
||||
}
|
||||
|
||||
private SimpleExceptionsGen(ThrownExceptionInfo[] infos) {
|
||||
public SimpleExceptionsGen(ThrownExceptionInfo[] infos) {
|
||||
myInfos = infos;
|
||||
}
|
||||
|
||||
@@ -505,10 +551,4 @@ public class ChangeSignatureTest extends LightRefactoringTestCase {
|
||||
return myInfos;
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user