mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fixed quickfixes
This commit is contained in:
@@ -26,15 +26,15 @@ public class VariablesProcessor
|
||||
private final String myPrefix;
|
||||
private boolean myStaticScopeFlag = false;
|
||||
private final boolean myStaticSensitiveFlag;
|
||||
private final List myResultList;
|
||||
private final List<PsiVariable> myResultList;
|
||||
|
||||
/** Collecting _all_ variables in scope */
|
||||
public VariablesProcessor(String _prefix, boolean staticSensitiveFlag){
|
||||
this(_prefix, staticSensitiveFlag, new ArrayList());
|
||||
this(_prefix, staticSensitiveFlag, new ArrayList<PsiVariable>());
|
||||
}
|
||||
|
||||
/** Collecting _all_ variables in scope */
|
||||
public VariablesProcessor(String _prefix, boolean staticSensitiveFlag, List lst){
|
||||
public VariablesProcessor(String _prefix, boolean staticSensitiveFlag, List<PsiVariable> lst){
|
||||
myPrefix = _prefix;
|
||||
myStaticSensitiveFlag = staticSensitiveFlag;
|
||||
myResultList = lst;
|
||||
|
||||
@@ -350,27 +350,29 @@ public class CreateFromUsageUtils {
|
||||
for (int i = 0; i < allVars.length; i++) {
|
||||
PsiVariable variable = allVars[i];
|
||||
PsiType varType = variable.getType();
|
||||
if (!(varType instanceof PsiClassType)) continue;
|
||||
PsiClass aClass = ((PsiClassType)varType).resolve();
|
||||
if (aClass == null) continue;
|
||||
boolean matched = infos.length == 0;
|
||||
for (int j = 0; j < infos.length; j++) {
|
||||
if (ExpectedTypeUtil.matches(varType, infos[j])) {
|
||||
matched = true;
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (matched) {
|
||||
for (Iterator<String> iterator = expectedFieldNames.iterator(); iterator.hasNext();) {
|
||||
String name = iterator.next();
|
||||
if (aClass.findFieldByName(name, true) == null) continue nextVar;
|
||||
}
|
||||
if (!expectedFieldNames.isEmpty() && !expectedMethodNames.isEmpty()) {
|
||||
if (!(varType instanceof PsiClassType)) continue nextVar;
|
||||
PsiClass aClass = ((PsiClassType)varType).resolve();
|
||||
if (aClass == null) continue nextVar;
|
||||
for (Iterator<String> iterator = expectedFieldNames.iterator(); iterator.hasNext();) {
|
||||
String name = iterator.next();
|
||||
if (aClass.findFieldByName(name, true) == null) continue nextVar;
|
||||
}
|
||||
|
||||
for (Iterator<String> iterator = expectedMethodNames.iterator(); iterator.hasNext();) {
|
||||
String name = iterator.next();
|
||||
PsiMethod[] methods = aClass.findMethodsByName(name, true);
|
||||
if (methods == null || methods.length == 0) continue nextVar;
|
||||
for (Iterator<String> iterator = expectedMethodNames.iterator(); iterator.hasNext();) {
|
||||
String name = iterator.next();
|
||||
PsiMethod[] methods = aClass.findMethodsByName(name, true);
|
||||
if (methods == null || methods.length == 0) continue nextVar;
|
||||
}
|
||||
}
|
||||
|
||||
result.add(variable);
|
||||
|
||||
@@ -56,34 +56,34 @@ public class RenameWrongRefAction implements IntentionAction {
|
||||
return !(myRefExpr.multiResolve(true).length > 0);
|
||||
}
|
||||
|
||||
class ReferenceNameExpression implements Expression {
|
||||
|
||||
private class ReferenceNameExpression implements Expression {
|
||||
class HammingComparator implements Comparator<LookupItem> {
|
||||
public int compare(LookupItem lookupItem1, LookupItem lookupItem2) {
|
||||
String s1 = lookupItem1.getLookupString(), s2 = lookupItem2.getLookupString();
|
||||
String refName = myRefExpr.getReferenceName();
|
||||
int diff1 = 0;
|
||||
for (int i = 0; i < Math.min(s1.length(), refName.length()); i++) {
|
||||
if (s1.charAt(i) != refName.charAt(i)) diff1++;
|
||||
for (int i = 0; i < Math.min(s1.length(), myOldReferenceName.length()); i++) {
|
||||
if (s1.charAt(i) != myOldReferenceName.charAt(i)) diff1++;
|
||||
}
|
||||
int diff2 = 0;
|
||||
for (int i = 0; i < Math.min(s2.length(), refName.length()); i++) {
|
||||
if (s2.charAt(i) != refName.charAt(i)) diff2++;
|
||||
for (int i = 0; i < Math.min(s2.length(), myOldReferenceName.length()); i++) {
|
||||
if (s2.charAt(i) != myOldReferenceName.charAt(i)) diff2++;
|
||||
}
|
||||
return diff1 - diff2;
|
||||
}
|
||||
}
|
||||
|
||||
ReferenceNameExpression(LookupItem[] items) {
|
||||
ReferenceNameExpression(LookupItem[] items, String oldReferenceName) {
|
||||
myItems = items;
|
||||
myOldReferenceName = oldReferenceName;
|
||||
Arrays.sort(myItems, new HammingComparator ());
|
||||
}
|
||||
|
||||
LookupItem[] myItems;
|
||||
private final String myOldReferenceName;
|
||||
|
||||
public Result calculateResult(ExpressionContext context) {
|
||||
if (myItems == null || myItems.length == 0) {
|
||||
return new TextResult(myRefExpr.getReferenceName());
|
||||
return new TextResult(myOldReferenceName);
|
||||
}
|
||||
return new TextResult(myItems[0].getLookupString());
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class RenameWrongRefAction implements IntentionAction {
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
PsiElement element = PsiTreeUtil.getParentOfType(myRefExpr, scopes);
|
||||
LookupItem[] items = collectItems();
|
||||
ReferenceNameExpression refExpr = new ReferenceNameExpression(items);
|
||||
ReferenceNameExpression refExpr = new ReferenceNameExpression(items, myRefExpr.getReferenceName());
|
||||
|
||||
Document document = editor.getDocument();
|
||||
TemplateBuilder builder = new TemplateBuilder(element);
|
||||
|
||||
Reference in New Issue
Block a user