mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
inline: replace type elements in order (IDEA-88882)
This commit is contained in:
@@ -31,10 +31,7 @@ import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
@@ -296,10 +293,11 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
public static void substituteTypeParams(PsiElement scope, final PsiSubstitutor substitutor, final PsiElementFactory factory) {
|
||||
final Map<PsiElement, PsiElement> replacement = new HashMap<PsiElement, PsiElement>();
|
||||
scope.accept(new JavaRecursiveElementVisitor() {
|
||||
@Override public void visitTypeElement(PsiTypeElement typeElement) {
|
||||
super.visitTypeElement(typeElement);
|
||||
PsiType type = typeElement.getType();
|
||||
|
||||
if (type instanceof PsiClassType) {
|
||||
JavaResolveResult resolveResult = ((PsiClassType)type).resolveGenerics();
|
||||
PsiElement resolved = resolveResult.getElement();
|
||||
@@ -309,17 +307,20 @@ public class InlineUtil {
|
||||
newType = PsiType.getJavaLangObject(resolved.getManager(), resolved.getResolveScope());
|
||||
}
|
||||
try {
|
||||
typeElement.replace(factory.createTypeElement(newType));
|
||||
return;
|
||||
replacement.put(typeElement, factory.createTypeElement(newType));
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
super.visitTypeElement(typeElement);
|
||||
}
|
||||
});
|
||||
for (PsiElement element : replacement.keySet()) {
|
||||
if (element.isValid()) {
|
||||
element.replace(replacement.get(element));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static PsiElement replaceDiamondWithInferredTypesIfNeeded(PsiExpression initializer, PsiElement ref) {
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
class Foo {
|
||||
public static <T, Loc> WeighingComparable<T, Loc> we<caret>igh(final Key<? extends Weigher<T, Loc>> key,
|
||||
final Computable<T> element,
|
||||
final Loc location) {
|
||||
return new WeighingComparable<T, Loc>(element, location, new Weigher[0]);
|
||||
}
|
||||
|
||||
|
||||
public WeighingComparable<String, ProximityLocation> method(boolean b,
|
||||
final Computable<String> elementComputable,
|
||||
Object processingContext) {
|
||||
return weigh(WEIGHER_KEY, elementComputable, new ProximityLocation());
|
||||
}
|
||||
|
||||
public static final Key<ProximityWeigher> WEIGHER_KEY = null;
|
||||
}
|
||||
|
||||
abstract class ProximityWeigher extends Weigher<String, ProximityLocation> {
|
||||
|
||||
}
|
||||
|
||||
class ProximityLocation {
|
||||
}
|
||||
|
||||
class Key<P> {
|
||||
}
|
||||
|
||||
class Weigher<A, B> {
|
||||
}
|
||||
|
||||
class Computable<O> {}
|
||||
|
||||
class WeighingComparable<T, Loc> implements Comparable<WeighingComparable<T, Loc>> {
|
||||
|
||||
public WeighingComparable(final Computable<T> element, final Loc location, final Weigher[] weighers) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public int compareTo(@NotNull final WeighingComparable<T, Loc> comparable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Comparable getWeight(final int index) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
class Foo {
|
||||
|
||||
|
||||
public WeighingComparable<String, ProximityLocation> method(boolean b,
|
||||
final Computable<String> elementComputable,
|
||||
Object processingContext) {
|
||||
return new WeighingComparable<String, ProximityLocation>(elementComputable, new ProximityLocation(), new Weigher[0]);
|
||||
}
|
||||
|
||||
public static final Key<ProximityWeigher> WEIGHER_KEY = null;
|
||||
}
|
||||
|
||||
abstract class ProximityWeigher extends Weigher<String, ProximityLocation> {
|
||||
|
||||
}
|
||||
|
||||
class ProximityLocation {
|
||||
}
|
||||
|
||||
class Key<P> {
|
||||
}
|
||||
|
||||
class Weigher<A, B> {
|
||||
}
|
||||
|
||||
class Computable<O> {}
|
||||
|
||||
class WeighingComparable<T, Loc> implements Comparable<WeighingComparable<T, Loc>> {
|
||||
|
||||
public WeighingComparable(final Computable<T> element, final Loc location, final Weigher[] weighers) {
|
||||
//To change body of created methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public int compareTo(@NotNull final WeighingComparable<T, Loc> comparable) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Comparable getWeight(final int index) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -159,6 +159,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
|
||||
public void testRawSubstitution() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testSubstitution() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testParamNameConflictsWithLocalVar() throws Exception {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user