mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Pseudo functional style inspection: 1. options list listeners fixed 2. validation by method return type fixed
This commit is contained in:
+39
-5
@@ -22,6 +22,7 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.impl.PsiDiamondTypeUtil;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -103,14 +104,47 @@ class PseudoLambdaReplaceTemplate {
|
||||
});
|
||||
final PsiType returnType = method.getReturnType();
|
||||
|
||||
if (returnType instanceof PsiClassType) {
|
||||
final PsiClass resolvedReturnTypeClass = ((PsiClassType)returnType).resolve();
|
||||
if (!InheritanceUtil.isInheritor(resolvedReturnTypeClass, CommonClassNames.JAVA_LANG_ITERABLE)) {
|
||||
if (StreamApiConstants.FAKE_FIND_MATCHED.equals(myStreamApiMethodName)) {
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
return null;
|
||||
}
|
||||
} else if (!(returnType instanceof PsiArrayType)) {
|
||||
return null;
|
||||
} else {
|
||||
final PsiClass stream =
|
||||
JavaPsiFacade.getInstance(method.getProject()).findClass(StreamApiConstants.JAVA_UTIL_STREAM_STREAM, method.getResolveScope());
|
||||
if (stream == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiMethod[] methods = stream.findMethodsByName(myStreamApiMethodName, false);
|
||||
LOG.assertTrue(methods.length != 0);
|
||||
PsiMethod representative = methods[0];
|
||||
final PsiType expectedReturnType = representative.getReturnType();
|
||||
if (expectedReturnType instanceof PsiClassType) {
|
||||
final PsiClass resolvedClass = ((PsiClassType)expectedReturnType).resolve();
|
||||
if (resolvedClass == null) {
|
||||
return null;
|
||||
} else {
|
||||
if (StreamApiConstants.JAVA_UTIL_STREAM_STREAM.equals(resolvedClass.getQualifiedName())) {
|
||||
if (!(returnType instanceof PsiArrayType)) {
|
||||
if (!(returnType instanceof PsiClassType)) {
|
||||
return null;
|
||||
}
|
||||
final PsiClass methodReturnType = ((PsiClassType)returnType).resolve();
|
||||
if (methodReturnType == null ||
|
||||
(!InheritanceUtil.isInheritor(methodReturnType, CommonClassNames.JAVA_LANG_ITERABLE) &&
|
||||
!InheritanceUtil.isInheritor(methodReturnType, CommonClassNames.JAVA_LANG_ITERABLE))) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (PsiType.BOOLEAN.equals(expectedReturnType)) {
|
||||
if (!PsiType.BOOLEAN.equals(returnType)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return validate(parameterTypes, returnType, null, method);
|
||||
}
|
||||
|
||||
|
||||
+10
-40
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.EditableModel;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -119,9 +120,7 @@ public class StaticPseudoFunctionalStyleMethodOptions {
|
||||
}
|
||||
|
||||
public JComponent createPanel() {
|
||||
final JBList list = new JBList();
|
||||
list.setModel(new SettingsListModel());
|
||||
|
||||
final JBList list = new JBList(myElements);
|
||||
list.setCellRenderer(new ColoredListCellRenderer<PipelineElement>() {
|
||||
@Override
|
||||
protected void customizeCellRenderer(JList list, PipelineElement element, int index, boolean selected, boolean hasFocus) {
|
||||
@@ -152,26 +151,19 @@ public class StaticPseudoFunctionalStyleMethodOptions {
|
||||
return;
|
||||
}
|
||||
myElements.add(newElement);
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
list.revalidate();
|
||||
list.updateUI();
|
||||
}
|
||||
});
|
||||
((DefaultListModel)list.getModel()).addElement(newElement);
|
||||
}
|
||||
}
|
||||
}).setRemoveAction(new AnActionButtonRunnable() {
|
||||
@Override
|
||||
public void run(AnActionButton button) {
|
||||
myElements.remove(list.getSelectedIndex());
|
||||
UIUtil.invokeLaterIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
list.revalidate();
|
||||
list.updateUI();
|
||||
}
|
||||
});
|
||||
final int[] indices = list.getSelectedIndices();
|
||||
final List<PipelineElement> toRemove = new ArrayList<PipelineElement>(indices.length);
|
||||
for (int idx : indices) {
|
||||
toRemove.add(myElements.get(idx));
|
||||
}
|
||||
myElements.removeAll(toRemove);
|
||||
ListUtil.removeSelectedItems(list);
|
||||
}
|
||||
}).createPanel();
|
||||
}
|
||||
@@ -223,26 +215,4 @@ public class StaticPseudoFunctionalStyleMethodOptions {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private class SettingsListModel implements ListModel {
|
||||
@Override
|
||||
public int getSize() {
|
||||
return myElements.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PipelineElement getElementAt(int index) {
|
||||
return myElements.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListDataListener(ListDataListener l) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListDataListener(ListDataListener l) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user