summaryrefslogtreecommitdiff
path: root/java/java-impl/src/com/intellij/refactoring/typeCook
diff options
context:
space:
mode:
Diffstat (limited to 'java/java-impl/src/com/intellij/refactoring/typeCook')
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java11
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/Util.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java16
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java32
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java16
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java23
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java6
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java19
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java69
-rw-r--r--java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java9
10 files changed, 102 insertions, 105 deletions
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java b/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
index 08ad857fe766..4e4e681ea03b 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/TypeCookProcessor.java
@@ -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.
@@ -30,10 +30,7 @@ import com.intellij.usageView.UsageInfo;
import com.intellij.usageView.UsageViewDescriptor;
import org.jetbrains.annotations.NotNull;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
+import java.util.*;
public class TypeCookProcessor extends BaseRefactoringProcessor {
private PsiElement[] myElements;
@@ -75,7 +72,7 @@ public class TypeCookProcessor extends BaseRefactoringProcessor {
}
}
- final HashSet<PsiElement> changedItems = myResult.getCookedElements();
+ final Set<PsiElement> changedItems = myResult.getCookedElements();
final UsageInfo[] usages = new UsageInfo[changedItems.size()];
int i = 0;
@@ -100,7 +97,7 @@ public class TypeCookProcessor extends BaseRefactoringProcessor {
}
protected void performRefactoring(UsageInfo[] usages) {
- final HashSet<PsiElement> victims = new HashSet<PsiElement>();
+ final Set<PsiElement> victims = new HashSet<PsiElement>();
for (UsageInfo usage : usages) {
victims.add(usage.getElement());
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java b/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
index e33388e0e8b7..54149613704b 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/Util.java
@@ -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.
@@ -217,7 +217,7 @@ public class Util {
return subst;
}
- public static boolean bindsTypeParameters(PsiType t, HashSet<PsiTypeParameter> params) {
+ public static boolean bindsTypeParameters(PsiType t, Set<PsiTypeParameter> params) {
if (t instanceof PsiWildcardType) {
final PsiWildcardType wct = ((PsiWildcardType)t);
final PsiType bound = wct.getBound();
@@ -286,7 +286,7 @@ public class Util {
PsiSubstitutor theSubst = PsiSubstitutor.EMPTY;
- final HashSet<PsiTypeVariable> cluster = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> cluster = new HashSet<PsiTypeVariable>();
for (final PsiTypeParameter parm : aSubst.getSubstitutionMap().keySet()) {
final PsiType type = createParameterizedType(aSubst.substitute(parm), factory, false, context);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
index e9a53aa68702..95535071b50e 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/PsiTypeVariableFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 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.
@@ -21,23 +21,21 @@ import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiUtil;
import org.jetbrains.annotations.NotNull;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
+import java.util.*;
/**
* @author db
*/
public class PsiTypeVariableFactory {
private int myCurrent = 0;
- private final LinkedList<HashSet<PsiTypeVariable>> myClusters = new LinkedList<HashSet<PsiTypeVariable>>();
- private final HashMap<Integer, HashSet<PsiTypeVariable>> myVarCluster = new HashMap<Integer, HashSet<PsiTypeVariable>>();
+ private final List<Set<PsiTypeVariable>> myClusters = new LinkedList<Set<PsiTypeVariable>>();
+ private final Map<Integer, Set<PsiTypeVariable>> myVarCluster = new HashMap<Integer, Set<PsiTypeVariable>>();
public final int getNumber() {
return myCurrent;
}
- public final void registerCluster(final HashSet<PsiTypeVariable> cluster) {
+ public final void registerCluster(final Set<PsiTypeVariable> cluster) {
myClusters.add(cluster);
for (final PsiTypeVariable aCluster : cluster) {
@@ -45,11 +43,11 @@ public class PsiTypeVariableFactory {
}
}
- public final LinkedList<HashSet<PsiTypeVariable>> getClusters() {
+ public final List<Set<PsiTypeVariable>> getClusters() {
return myClusters;
}
- public final HashSet<PsiTypeVariable> getClusterOf(final int var) {
+ public final Set<PsiTypeVariable> getClusterOf(final int var) {
return myVarCluster.get(new Integer(var));
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
index 271c686b7fa9..a23d6d033c74 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/ReductionSystem.java
@@ -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.
@@ -31,19 +31,19 @@ import java.util.*;
* @author db
*/
public class ReductionSystem {
- final HashSet<Constraint> myConstraints = new HashSet<Constraint>();
- final HashSet<PsiElement> myElements;
- final HashMap<PsiTypeCastExpression, PsiType> myCastToOperandType;
- final HashMap<PsiElement, PsiType> myTypes;
+ final Set<Constraint> myConstraints = new HashSet<Constraint>();
+ final Set<PsiElement> myElements;
+ final Map<PsiTypeCastExpression, PsiType> myCastToOperandType;
+ final Map<PsiElement, PsiType> myTypes;
final PsiTypeVariableFactory myTypeVariableFactory;
final Project myProject;
final Settings mySettings;
- HashSet<PsiTypeVariable> myBoundVariables;
+ Set<PsiTypeVariable> myBoundVariables;
public ReductionSystem(final Project project,
- final HashSet<PsiElement> elements,
- final HashMap<PsiElement, PsiType> types,
+ final Set<PsiElement> elements,
+ final Map<PsiElement, PsiType> types,
final PsiTypeVariableFactory factory,
final Settings settings) {
myProject = project;
@@ -59,7 +59,7 @@ public class ReductionSystem {
return myProject;
}
- public HashSet<Constraint> getConstraints() {
+ public Set<Constraint> getConstraints() {
return myConstraints;
}
@@ -165,7 +165,7 @@ public class ReductionSystem {
class Node {
int myComponent = -1;
Constraint myConstraint;
- HashSet<Node> myNeighbours = new HashSet<Node>();
+ Set<Node> myNeighbours = new HashSet<Node>();
public Node() {
myConstraint = null;
@@ -189,7 +189,7 @@ public class ReductionSystem {
final Node[] typeVariableNodes = new Node[myTypeVariableFactory.getNumber()];
final Node[] constraintNodes = new Node[myConstraints.size()];
- final HashMap<Constraint, HashSet<PsiTypeVariable>> boundVariables = new HashMap<Constraint, HashSet<PsiTypeVariable>>();
+ final Map<Constraint, Set<PsiTypeVariable>> boundVariables = new HashMap<Constraint, Set<PsiTypeVariable>>();
for (int i = 0; i < typeVariableNodes.length; i++) {
typeVariableNodes[i] = new Node();
@@ -207,7 +207,7 @@ public class ReductionSystem {
int l = 0;
for (final Constraint constraint : myConstraints) {
- final HashSet<PsiTypeVariable> boundVars = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> boundVars = new LinkedHashSet<PsiTypeVariable>();
final Node constraintNode = constraintNodes[l++];
new Object() {
@@ -266,9 +266,9 @@ public class ReductionSystem {
}
}
- final LinkedList<HashSet<PsiTypeVariable>> clusters = myTypeVariableFactory.getClusters();
+ List<Set<PsiTypeVariable>> clusters = myTypeVariableFactory.getClusters();
- for (final HashSet<PsiTypeVariable> cluster : clusters) {
+ for (final Set<PsiTypeVariable> cluster : clusters) {
Node prev = null;
for (final PsiTypeVariable variable : cluster) {
@@ -327,7 +327,7 @@ public class ReductionSystem {
return systems;
}
- private void addConstraint(final Constraint constraint, final HashSet<PsiTypeVariable> vars) {
+ private void addConstraint(final Constraint constraint, final Set<PsiTypeVariable> vars) {
if (myBoundVariables == null) {
myBoundVariables = vars;
}
@@ -342,7 +342,7 @@ public class ReductionSystem {
return myTypeVariableFactory;
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
index 31e67a451e7f..a74fc23261e3 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/Result.java
@@ -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.
@@ -25,9 +25,9 @@ import com.intellij.refactoring.typeCook.deductive.resolver.Binding;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NonNls;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* @author db
@@ -35,10 +35,10 @@ import java.util.Map;
public class Result {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.builder.Result");
- private final HashSet<PsiElement> myVictims;
- private final HashMap<PsiElement, PsiType> myTypes;
+ private final Set<PsiElement> myVictims;
+ private final Map<PsiElement, PsiType> myTypes;
private final Settings mySettings;
- private final HashMap<PsiTypeCastExpression, PsiType> myCastToOperandType;
+ private final Map<PsiTypeCastExpression, PsiType> myCastToOperandType;
private int myCookedNumber = -1;
private int myCastsRemoved = -1;
@@ -92,10 +92,10 @@ public class Result {
return originalType;
}
- public HashSet<PsiElement> getCookedElements() {
+ public Set<PsiElement> getCookedElements() {
myCookedNumber = 0;
- final HashSet<PsiElement> set = new HashSet<PsiElement>();
+ final Set<PsiElement> set = new HashSet<PsiElement>();
for (final PsiElement element : myVictims) {
final PsiType originalType = Util.getType(element);
@@ -137,7 +137,7 @@ public class Result {
return false;
}
- public void apply(final HashSet<PsiElement> victims) {
+ public void apply(final Set<PsiElement> victims) {
for (final PsiElement element : victims) {
if (element instanceof PsiTypeCastExpression && myCastToOperandType.containsKey(element)) {
final PsiTypeCastExpression cast = ((PsiTypeCastExpression)element);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
index 2cd9045ba121..8b0514143ba6 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/builder/SystemBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 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.
@@ -37,6 +37,7 @@ import com.intellij.util.containers.HashMap;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
/**
* Created by IntelliJ IDEA.
@@ -49,11 +50,11 @@ public class SystemBuilder {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.builder.SystemBuilder");
private final PsiManager myManager;
- private final HashMap<PsiElement, Boolean> myMethodCache;
- private final HashMap<PsiParameter, PsiParameter> myParameters;
- private final HashMap<PsiMethod, PsiMethod> myMethods;
- private final HashMap<PsiElement, PsiType> myTypes;
- private final HashSet<PsiAnchor> myVisitedConstructions;
+ private final Map<PsiElement, Boolean> myMethodCache;
+ private final Map<PsiParameter, PsiParameter> myParameters;
+ private final Map<PsiMethod, PsiMethod> myMethods;
+ private final Map<PsiElement, PsiType> myTypes;
+ private final Set<PsiAnchor> myVisitedConstructions;
private final Settings mySettings;
private final PsiTypeVariableFactory myTypeVariableFactory;
private final Project myProject;
@@ -70,11 +71,11 @@ public class SystemBuilder {
myTypeVariableFactory = new PsiTypeVariableFactory();
}
- private HashSet<PsiElement> collect(final PsiElement[] scopes) {
+ private Set<PsiElement> collect(final PsiElement[] scopes) {
return new VictimCollector(scopes, mySettings).getVictims();
}
- private boolean verifyMethod(final PsiElement element, final HashSet<PsiElement> victims, final PsiSearchHelper helper) {
+ private boolean verifyMethod(final PsiElement element, final Set<PsiElement> victims, final PsiSearchHelper helper) {
PsiMethod method;
PsiParameter parameter = null;
int index = 0;
@@ -352,7 +353,7 @@ public class SystemBuilder {
final PsiExpression qualifier =
expr instanceof PsiMethodCallExpression ? ((PsiMethodCallExpression)expr).getMethodExpression().getQualifierExpression() : null;
- final HashSet<PsiTypeParameter> typeParameters = new HashSet<PsiTypeParameter>(Arrays.asList(methodTypeParameters));
+ final Set<PsiTypeParameter> typeParameters = new HashSet<PsiTypeParameter>(Arrays.asList(methodTypeParameters));
PsiSubstitutor qualifierSubstitutor = PsiSubstitutor.EMPTY;
PsiSubstitutor supertypeSubstitutor = PsiSubstitutor.EMPTY;
@@ -397,7 +398,7 @@ public class SystemBuilder {
}
}
- final HashMap<PsiTypeParameter, PsiType> mapping = new HashMap<PsiTypeParameter, PsiType>();
+ final Map<PsiTypeParameter, PsiType> mapping = new HashMap<PsiTypeParameter, PsiType>();
for (int i = 0; i < Math.min(parameters.length, arguments.length); i++) {
final PsiType argumentType = evaluateType(arguments[i], system);
@@ -913,7 +914,7 @@ public class SystemBuilder {
return build(collect(scopes));
}
- public ReductionSystem build(final HashSet<PsiElement> victims) {
+ public ReductionSystem build(final Set<PsiElement> victims) {
final PsiSearchHelper helper = PsiSearchHelper.SERVICE.getInstance(myManager.getProject());
ReductionSystem system = new ReductionSystem(myProject, victims, myTypes, myTypeVariableFactory, mySettings);
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
index 54901124c3c1..88286517e4f1 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/Binding.java
@@ -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.
@@ -18,7 +18,7 @@ package com.intellij.refactoring.typeCook.deductive.resolver;
import com.intellij.psi.PsiType;
import com.intellij.psi.PsiTypeVariable;
-import java.util.HashSet;
+import java.util.Set;
/**
* @author db
@@ -47,7 +47,7 @@ public abstract class Binding {
public abstract void merge(Binding b, boolean removeObject);
- public abstract HashSet<PsiTypeVariable> getBoundVariables();
+ public abstract Set<PsiTypeVariable> getBoundVariables();
public abstract int getWidth();
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
index 49525a67de44..14b9a1715050 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/BindingFactory.java
@@ -33,7 +33,6 @@ import com.intellij.util.IncorrectOperationException;
import gnu.trove.TIntObjectHashMap;
import gnu.trove.TObjectProcedure;
-import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.Set;
@@ -45,7 +44,7 @@ import java.util.Set;
public class BindingFactory {
private static final Logger LOG = Logger.getInstance("#com.intellij.refactoring.typeCook.deductive.resolver.BindingFactory");
- private final HashSet<PsiTypeVariable> myBoundVariables;
+ private final Set<PsiTypeVariable> myBoundVariables;
private final Project myProject;
private final PsiTypeVariableFactory myFactory;
@@ -95,7 +94,7 @@ public class BindingFactory {
myBindings.put(index, type);
if (type instanceof Bottom) {
- final HashSet<PsiTypeVariable> cluster = myFactory.getClusterOf(index);
+ final Set<PsiTypeVariable> cluster = myFactory.getClusterOf(index);
if (cluster != null) {
for (PsiTypeVariable var : cluster) {
@@ -540,7 +539,7 @@ public class BindingFactory {
if (removeObject &&
javaLangObject.equals(type)) {
- final HashSet<PsiTypeVariable> cluster = myFactory.getClusterOf(var.getIndex());
+ final Set<PsiTypeVariable> cluster = myFactory.getClusterOf(var.getIndex());
if (cluster != null) {
for (final PsiTypeVariable war : cluster) {
@@ -560,7 +559,7 @@ public class BindingFactory {
}
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
@@ -663,7 +662,7 @@ public class BindingFactory {
Binding unify(PsiType x, PsiType y);
}
- public Binding balance(final PsiType x, final PsiType y, final Balancer balancer, final HashSet<Constraint> constraints) {
+ public Binding balance(final PsiType x, final PsiType y, final Balancer balancer, final Set<Constraint> constraints) {
final int indicator = (x instanceof PsiTypeVariable ? 1 : 0) + (y instanceof PsiTypeVariable ? 2 : 0);
switch (indicator) {
@@ -878,7 +877,7 @@ public class BindingFactory {
}
}
- public Binding riseWithWildcard(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding riseWithWildcard(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
final Binding binding = balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
if (y instanceof Bottom) {
@@ -941,7 +940,7 @@ public class BindingFactory {
return binding != null ? binding.reduceRecursive() : null;
}
- public Binding rise(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding rise(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
final Binding binding = balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
if (y instanceof Bottom || y instanceof PsiWildcardType) {
@@ -977,7 +976,7 @@ public class BindingFactory {
return binding != null ? binding.reduceRecursive() : null;
}
- public Binding sink(final PsiType x, final PsiType y, final HashSet<Constraint> constraints) {
+ public Binding sink(final PsiType x, final PsiType y, final Set<Constraint> constraints) {
return balance(x, y, new Balancer() {
public Binding varType(final PsiTypeVariable x, final PsiType y) {
return create(x, y);
@@ -1141,7 +1140,7 @@ public class BindingFactory {
return new BindingImpl();
}
- public HashSet<PsiTypeVariable> getBoundVariables() {
+ public Set<PsiTypeVariable> getBoundVariables() {
return myBoundVariables;
}
}
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
index 7279b6d4a0d0..a58e0561c449 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/resolver/ResolverTree.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 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.
@@ -28,6 +28,7 @@ import com.intellij.refactoring.typeCook.deductive.PsiExtendedTypeVisitor;
import com.intellij.refactoring.typeCook.deductive.builder.Constraint;
import com.intellij.refactoring.typeCook.deductive.builder.ReductionSystem;
import com.intellij.refactoring.typeCook.deductive.builder.Subtype;
+import com.intellij.util.containers.EmptyIterator;
import com.intellij.util.graph.DFSTBuilder;
import com.intellij.util.graph.Graph;
import gnu.trove.TIntArrayList;
@@ -51,7 +52,7 @@ public class ResolverTree {
private final Settings mySettings;
private boolean mySolutionFound = false;
- private HashSet<Constraint> myConstraints;
+ private Set<Constraint> myConstraints;
public ResolverTree(final ReductionSystem system) {
myBindingFactory = new BindingFactory(system);
@@ -65,7 +66,7 @@ public class ResolverTree {
reduceCyclicVariables();
}
- private ResolverTree(final ResolverTree parent, final HashSet<Constraint> constraints, final Binding binding) {
+ private ResolverTree(final ResolverTree parent, final Set<Constraint> constraints, final Binding binding) {
myBindingFactory = parent.myBindingFactory;
myCurrentBinding = binding;
mySolutions = parent.mySolutions;
@@ -76,7 +77,7 @@ public class ResolverTree {
}
private static class PsiTypeVarCollector extends PsiExtendedTypeVisitor {
- final HashSet<PsiTypeVariable> mySet = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> mySet = new HashSet<PsiTypeVariable>();
@Override
public Object visitTypeVariable(final PsiTypeVariable var) {
@@ -85,7 +86,7 @@ public class ResolverTree {
return null;
}
- public HashSet<PsiTypeVariable> getSet(final PsiType type) {
+ public Set<PsiTypeVariable> getSet(final PsiType type) {
type.accept(this);
return mySet;
}
@@ -120,14 +121,14 @@ public class ResolverTree {
return result;
}
- private void setDegree(final HashSet<PsiTypeVariable> set, TObjectIntHashMap<PsiTypeVariable> result) {
+ private void setDegree(final Set<PsiTypeVariable> set, TObjectIntHashMap<PsiTypeVariable> result) {
for (final PsiTypeVariable var : set) {
result.increment(var);
}
}
- private HashSet<Constraint> apply(final Binding b) {
- final HashSet<Constraint> result = new HashSet<Constraint>();
+ private Set<Constraint> apply(final Binding b) {
+ final Set<Constraint> result = new HashSet<Constraint>();
for (final Constraint constr : myConstraints) {
result.add(constr.apply(b));
@@ -136,8 +137,8 @@ public class ResolverTree {
return result;
}
- private HashSet<Constraint> apply(final Binding b, final HashSet<Constraint> additional) {
- final HashSet<Constraint> result = new HashSet<Constraint>();
+ private Set<Constraint> apply(final Binding b, final Set<Constraint> additional) {
+ final Set<Constraint> result = new HashSet<Constraint>();
for (final Constraint constr : myConstraints) {
result.add(constr.apply(b));
@@ -156,18 +157,18 @@ public class ResolverTree {
return newBinding == null ? null : new ResolverTree(this, apply(b), newBinding);
}
- private ResolverTree applyRule(final Binding b, final HashSet<Constraint> additional) {
+ private ResolverTree applyRule(final Binding b, final Set<Constraint> additional) {
final Binding newBinding = b != null ? myCurrentBinding.compose(b) : null;
return newBinding == null ? null : new ResolverTree(this, apply(b, additional), newBinding);
}
private void reduceCyclicVariables() {
- final HashSet<PsiTypeVariable> nodes = new HashSet<PsiTypeVariable>();
- final HashSet<Constraint> candidates = new HashSet<Constraint>();
+ final Set<PsiTypeVariable> nodes = new HashSet<PsiTypeVariable>();
+ final Set<Constraint> candidates = new HashSet<Constraint>();
- final HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>> ins = new HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>>();
- final HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>> outs = new HashMap<PsiTypeVariable, HashSet<PsiTypeVariable>>();
+ final Map<PsiTypeVariable, Set<PsiTypeVariable>> ins = new HashMap<PsiTypeVariable, Set<PsiTypeVariable>>();
+ final Map<PsiTypeVariable, Set<PsiTypeVariable>> outs = new HashMap<PsiTypeVariable, Set<PsiTypeVariable>>();
for (final Constraint constraint : myConstraints) {
final PsiType left = constraint.getLeft();
@@ -182,11 +183,11 @@ public class ResolverTree {
nodes.add(leftVar);
nodes.add(rightVar);
- final HashSet<PsiTypeVariable> in = ins.get(leftVar);
- final HashSet<PsiTypeVariable> out = outs.get(rightVar);
+ Set<PsiTypeVariable> in = ins.get(leftVar);
+ Set<PsiTypeVariable> out = outs.get(rightVar);
if (in == null) {
- final HashSet<PsiTypeVariable> newIn = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> newIn = new HashSet<PsiTypeVariable>();
newIn.add(rightVar);
@@ -197,7 +198,7 @@ public class ResolverTree {
}
if (out == null) {
- final HashSet<PsiTypeVariable> newOut = new HashSet<PsiTypeVariable>();
+ final Set<PsiTypeVariable> newOut = new HashSet<PsiTypeVariable>();
newOut.add(leftVar);
@@ -217,10 +218,10 @@ public class ResolverTree {
@Override
public Iterator<PsiTypeVariable> getIn(final PsiTypeVariable n) {
- final HashSet<PsiTypeVariable> in = ins.get(n);
+ final Set<PsiTypeVariable> in = ins.get(n);
if (in == null) {
- return new HashSet<PsiTypeVariable>().iterator();
+ return EmptyIterator.getInstance();
}
return in.iterator();
@@ -228,10 +229,10 @@ public class ResolverTree {
@Override
public Iterator<PsiTypeVariable> getOut(final PsiTypeVariable n) {
- final HashSet<PsiTypeVariable> out = outs.get(n);
+ final Set<PsiTypeVariable> out = outs.get(n);
if (out == null) {
- return new HashSet<PsiTypeVariable>().iterator();
+ return EmptyIterator.getInstance();
}
return out.iterator();
@@ -240,7 +241,7 @@ public class ResolverTree {
});
final TIntArrayList sccs = dfstBuilder.getSCCs();
- final HashMap<PsiTypeVariable, Integer> index = new HashMap<PsiTypeVariable, Integer>();
+ final Map<PsiTypeVariable, Integer> index = new HashMap<PsiTypeVariable, Integer>();
sccs.forEach(new TIntProcedure() {
int myTNumber = 0;
@@ -284,9 +285,9 @@ public class ResolverTree {
private void reduceTypeType(final Constraint constr) {
final PsiType left = constr.getLeft();
final PsiType right = constr.getRight();
- final HashSet<Constraint> addendumRise = new HashSet<Constraint>();
- final HashSet<Constraint> addendumSink = new HashSet<Constraint>();
- final HashSet<Constraint> addendumWcrd = new HashSet<Constraint>();
+ final Set<Constraint> addendumRise = new HashSet<Constraint>();
+ final Set<Constraint> addendumSink = new HashSet<Constraint>();
+ final Set<Constraint> addendumWcrd = new HashSet<Constraint>();
int numSons = 0;
Binding riseBinding = myBindingFactory.rise(left, right, addendumRise);
@@ -356,7 +357,7 @@ public class ResolverTree {
private void fillTypeRange(final PsiType lowerBound,
final PsiType upperBound,
- final HashSet<PsiType> holder) {
+ final Set<PsiType> holder) {
if (lowerBound instanceof PsiClassType && upperBound instanceof PsiClassType) {
final PsiClassType.ClassResolveResult resultLower = ((PsiClassType)lowerBound).resolveGenerics();
final PsiClassType.ClassResolveResult resultUpper = ((PsiClassType)upperBound).resolveGenerics();
@@ -385,7 +386,7 @@ public class ResolverTree {
}
private PsiType[] getTypeRange(final PsiType lowerBound, final PsiType upperBound) {
- final HashSet<PsiType> range = new HashSet<PsiType>();
+ Set<PsiType> range = new HashSet<PsiType>();
range.add(lowerBound);
range.add(upperBound);
@@ -464,8 +465,8 @@ public class ResolverTree {
reduceCyclicVariables();
}
- final HashMap<PsiTypeVariable, Constraint> myTypeVarConstraints = new HashMap<PsiTypeVariable, Constraint>();
- final HashMap<PsiTypeVariable, Constraint> myVarTypeConstraints = new HashMap<PsiTypeVariable, Constraint>();
+ final Map<PsiTypeVariable, Constraint> myTypeVarConstraints = new HashMap<PsiTypeVariable, Constraint>();
+ final Map<PsiTypeVariable, Constraint> myVarTypeConstraints = new HashMap<PsiTypeVariable, Constraint>();
for (final Constraint constr : myConstraints) {
final PsiType left = constr.getLeft();
@@ -530,7 +531,7 @@ public class ResolverTree {
final PsiType right = constr.getRight();
if (!(left instanceof PsiTypeVariable) && right instanceof PsiTypeVariable) {
- final HashSet<PsiTypeVariable> bound = new PsiTypeVarCollector().getSet(left);
+ Set<PsiTypeVariable> bound = new PsiTypeVarCollector().getSet(left);
if (bound.contains(right)) {
myConstraints.remove(constr);
@@ -561,10 +562,10 @@ public class ResolverTree {
//T1 < a < b < ...
{
- final HashSet<PsiTypeVariable> haveLeftBound = new HashSet<PsiTypeVariable>();
+ Set<PsiTypeVariable> haveLeftBound = new HashSet<PsiTypeVariable>();
Constraint target = null;
- final HashSet<PsiTypeVariable> boundVariables = new HashSet<PsiTypeVariable>();
+ Set<PsiTypeVariable> boundVariables = new HashSet<PsiTypeVariable>();
for (final Constraint constr : myConstraints) {
final PsiType leftType = constr.getLeft();
diff --git a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
index 5b2354563ed9..9af367c9fbd1 100644
--- a/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
+++ b/java/java-impl/src/com/intellij/refactoring/typeCook/deductive/util/VictimCollector.java
@@ -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.
@@ -19,13 +19,14 @@ import com.intellij.psi.*;
import com.intellij.refactoring.typeCook.Settings;
import com.intellij.refactoring.typeCook.Util;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.Set;
/**
* @author db
*/
public class VictimCollector extends Visitor {
- final HashSet<PsiElement> myVictims = new HashSet<PsiElement>();
+ final Set<PsiElement> myVictims = new LinkedHashSet<PsiElement>();
final PsiElement[] myElements;
final Settings mySettings;
@@ -106,7 +107,7 @@ public class VictimCollector extends Visitor {
}
}
- public HashSet<PsiElement> getVictims() {
+ public Set<PsiElement> getVictims() {
for (PsiElement element : myElements) {
element.accept(this);
}