mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IteratorDeclaration: ListIterator support
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -105,12 +105,19 @@ public class IteratorDeclaration {
|
||||
PsiMethodCallExpression call = (PsiMethodCallExpression)initializer;
|
||||
if (call.getArgumentList().getExpressions().length != 0) return null;
|
||||
PsiReferenceExpression methodExpression = call.getMethodExpression();
|
||||
if (!"iterator".equals(methodExpression.getReferenceName())) return null;
|
||||
boolean listIterator = "listIterator".equals(methodExpression.getReferenceName());
|
||||
if (!"iterator".equals(methodExpression.getReferenceName()) && !listIterator) return null;
|
||||
PsiMethod method = call.resolveMethod();
|
||||
if (method == null || !InheritanceUtil.isInheritor(method.getContainingClass(), CommonClassNames.JAVA_LANG_ITERABLE)) return null;
|
||||
boolean isCollection = InheritanceUtil.isInheritor(method.getContainingClass(), CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
PsiType type = variable.getType();
|
||||
if (!(type instanceof PsiClassType) || !((PsiClassType)type).rawType().equalsToText(CommonClassNames.JAVA_UTIL_ITERATOR)) return null;
|
||||
if (method == null) return null;
|
||||
boolean isCollection;
|
||||
if (listIterator) {
|
||||
if (!InheritanceUtil.isInheritor(method.getContainingClass(), CommonClassNames.JAVA_UTIL_LIST)) return null;
|
||||
isCollection = true;
|
||||
} else {
|
||||
if (!InheritanceUtil.isInheritor(method.getContainingClass(), CommonClassNames.JAVA_LANG_ITERABLE)) return null;
|
||||
isCollection = InheritanceUtil.isInheritor(method.getContainingClass(), CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
}
|
||||
if (!InheritanceUtil.isInheritor(variable.getType(), CommonClassNames.JAVA_UTIL_ITERATOR)) return null;
|
||||
return new IteratorDeclaration(variable, methodExpression.getQualifierExpression(), isCollection);
|
||||
}
|
||||
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Replace the loop with Collection.removeIf" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
void test(List<String> list) {
|
||||
list.removeIf(String::isEmpty);
|
||||
}
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// "Replace the loop with Collection.removeIf" "true"
|
||||
import java.util.*;
|
||||
|
||||
public class Test {
|
||||
void test(List<String> list) {
|
||||
ListIterator<String> iterator = list.listIterator();
|
||||
while(iterator<caret>.hasNext()) {
|
||||
if(iterator.next().isEmpty()) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user