mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -215,14 +215,14 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
private void visitConditional(@Nullable PsiElement condition,
|
||||
@Nullable PsiElement thenBranch,
|
||||
@Nullable PsiElement elseBranch) {
|
||||
if (condition != null) {
|
||||
if (condition != null && checkTextRange(condition, true)) {
|
||||
condition.accept(this);
|
||||
}
|
||||
ThreeState conditionRes = evaluateCondition(condition);
|
||||
if (conditionRes != ThreeState.NO && thenBranch != null) {
|
||||
if (conditionRes != ThreeState.NO && thenBranch != null && checkTextRange(thenBranch, true)) {
|
||||
thenBranch.accept(this);
|
||||
}
|
||||
if (conditionRes != ThreeState.YES && elseBranch != null) {
|
||||
if (conditionRes != ThreeState.YES && elseBranch != null && checkTextRange(elseBranch, true)) {
|
||||
elseBranch.accept(this);
|
||||
}
|
||||
}
|
||||
@@ -246,7 +246,7 @@ public class JavaSmartStepIntoHandler extends JvmSmartStepIntoHandler {
|
||||
super.visitExpression(expression);
|
||||
}
|
||||
|
||||
boolean checkTextRange(PsiElement expression, boolean expand) {
|
||||
boolean checkTextRange(@NotNull PsiElement expression, boolean expand) {
|
||||
TextRange range = expression.getTextRange();
|
||||
if (lineRange.intersects(range)) {
|
||||
if (expand) {
|
||||
|
||||
-5
@@ -722,11 +722,6 @@ public class UnusedDeclarationInspectionBase extends GlobalInspectionTool {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(@NotNull GlobalInspectionContext context) {
|
||||
super.initialize(context);
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public List<EntryPoint> getExtensions() {
|
||||
return myExtensions;
|
||||
|
||||
+5
@@ -49,6 +49,11 @@ class ChangeNullableDefaultsFix implements LocalQuickFix {
|
||||
return "Make \"" + (myNotNullName != null ? myNotNullName : myNullableName) + "\" default annotation";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
if (myNotNullName != null) {
|
||||
|
||||
+1
-1
@@ -55,6 +55,6 @@ public class EnableOptimizeImportsOnTheFlyFix implements IntentionAction, LowPri
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -619,7 +619,7 @@ public class UnusedDeclarationPresentation extends DefaultInspectionToolPresenta
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,13 +29,13 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.containers.Predicate;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
@@ -170,7 +170,7 @@ public class SpecialAnnotationsUtil {
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
+21
-17
@@ -750,29 +750,33 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
}
|
||||
|
||||
private static ExpressionOccurrenceManager createOccurrenceManager(PsiExpression expr, PsiElement tempContainer) {
|
||||
boolean skipForStatement = true;
|
||||
final PsiForStatement forStatement = PsiTreeUtil.getParentOfType(expr, PsiForStatement.class);
|
||||
if (forStatement != null) {
|
||||
Set<PsiVariable> vars = new HashSet<>();
|
||||
SyntaxTraverser.psiTraverser().withRoot(expr)
|
||||
.filter(element -> element instanceof PsiReferenceExpression)
|
||||
.forEach(element -> {
|
||||
final PsiElement resolve = ((PsiReferenceExpression)element).resolve();
|
||||
if (resolve instanceof PsiVariable) {
|
||||
vars.add((PsiVariable)resolve);
|
||||
}
|
||||
});
|
||||
skipForStatement = vars.stream().noneMatch(variable -> PsiTreeUtil.isAncestor(forStatement.getInitialization(), variable, true));
|
||||
}
|
||||
Set<PsiVariable> vars = new HashSet<>();
|
||||
SyntaxTraverser.psiTraverser().withRoot(expr)
|
||||
.filter(element -> element instanceof PsiReferenceExpression)
|
||||
.forEach(element -> {
|
||||
final PsiElement resolve = ((PsiReferenceExpression)element).resolve();
|
||||
if (resolve instanceof PsiVariable) {
|
||||
vars.add((PsiVariable)resolve);
|
||||
}
|
||||
});
|
||||
|
||||
PsiElement containerParent = tempContainer;
|
||||
PsiElement lastScope = tempContainer;
|
||||
while (true) {
|
||||
if (containerParent instanceof PsiFile) break;
|
||||
if (containerParent instanceof PsiMethod) break;
|
||||
// allow to find occurrences outside lambda as we allow this for loops, ifs, etc
|
||||
// if (containerParent instanceof PsiLambdaExpression) break;
|
||||
if (!skipForStatement && containerParent instanceof PsiForStatement) break;
|
||||
if (containerParent instanceof PsiLambdaExpression) {
|
||||
PsiParameter[] parameters = ((PsiLambdaExpression)containerParent).getParameterList().getParameters();
|
||||
if (Arrays.stream(parameters).anyMatch(parameter -> vars.contains(parameter))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (containerParent instanceof PsiForStatement) {
|
||||
PsiForStatement forStatement = (PsiForStatement)containerParent;
|
||||
if (vars.stream().anyMatch(variable -> PsiTreeUtil.isAncestor(forStatement.getInitialization(), variable, true))) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
containerParent = containerParent.getParent();
|
||||
if (containerParent instanceof PsiCodeBlock) {
|
||||
lastScope = containerParent;
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
UnaryOperator<String> f1 = s -> {
|
||||
System.out.println("foo");
|
||||
String temp = s.trim();
|
||||
return temp;
|
||||
};
|
||||
UnaryOperator<String> f2 = s -> {
|
||||
System.out.println("foo");
|
||||
return s.trim();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
class Main {
|
||||
public static void main(String[] args) {
|
||||
UnaryOperator<String> f1 = s -> {
|
||||
System.out.println("foo");
|
||||
return <selection>s.trim()</selection>;
|
||||
};
|
||||
UnaryOperator<String> f2 = s -> {
|
||||
System.out.println("foo");
|
||||
return s.trim();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -211,6 +211,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testDistinguishLambdaParams() {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, CommonClassNames.JAVA_LANG_STRING));
|
||||
}
|
||||
|
||||
public void testDuplicateGenericExpressions() {
|
||||
doTest(new MockIntroduceVariableHandler("temp", true, false, false, "Foo2<? extends java.lang.Runnable>"));
|
||||
}
|
||||
|
||||
@@ -64,9 +64,6 @@
|
||||
<item name='java.lang.Enum T valueOf(java.lang.Class<T>, java.lang.String) 1'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
<item name="java.lang.Iterable Iterator<T> iterator()">
|
||||
<annotation name="org.jetbrains.annotations.NotNull" />
|
||||
</item>
|
||||
<item name='java.lang.Iterable java.util.Iterator<T> iterator()'>
|
||||
<annotation name='org.jetbrains.annotations.NotNull'/>
|
||||
</item>
|
||||
|
||||
-85
@@ -1,85 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.intention.impl;
|
||||
|
||||
import com.intellij.codeInsight.intention.HighPriorityAction;
|
||||
import com.intellij.codeInsight.intention.LowPriorityAction;
|
||||
import com.intellij.codeInspection.LocalQuickFix;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public abstract class PriorityLocalQuickFixWrapper implements LocalQuickFix {
|
||||
private final LocalQuickFix fix;
|
||||
|
||||
private PriorityLocalQuickFixWrapper(@NotNull LocalQuickFix fix) {
|
||||
this.fix = fix;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return fix.getName();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getFamilyName() {
|
||||
return fix.getFamilyName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
|
||||
fix.applyFix(project, descriptor);
|
||||
}
|
||||
|
||||
private static class HighPriorityLocalQuickFixWrapper extends PriorityLocalQuickFixWrapper implements HighPriorityAction {
|
||||
protected HighPriorityLocalQuickFixWrapper(@NotNull LocalQuickFix fix) {
|
||||
super(fix);
|
||||
}
|
||||
}
|
||||
|
||||
private static class NormalPriorityLocalQuickFixWrapper extends PriorityLocalQuickFixWrapper {
|
||||
protected NormalPriorityLocalQuickFixWrapper(@NotNull LocalQuickFix fix) {
|
||||
super(fix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class LowPriorityLocalQuickFixWrapper extends PriorityLocalQuickFixWrapper implements LowPriorityAction {
|
||||
protected LowPriorityLocalQuickFixWrapper(@NotNull LocalQuickFix fix) {
|
||||
super(fix);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalQuickFix highPriority(@NotNull LocalQuickFix fix) {
|
||||
return new HighPriorityLocalQuickFixWrapper(fix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalQuickFix normalPriority(@NotNull LocalQuickFix fix) {
|
||||
return new NormalPriorityLocalQuickFixWrapper(fix);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LocalQuickFix lowPriority(@NotNull LocalQuickFix fix) {
|
||||
return new LowPriorityLocalQuickFixWrapper(fix);
|
||||
}
|
||||
}
|
||||
@@ -135,7 +135,7 @@ class AsyncFilterRunner {
|
||||
List<Filter.Result> results = new ArrayList<>();
|
||||
for (LineHighlighter task : tasks) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (!marker.isValid()) return FilterResults.EMPTY;
|
||||
if (!marker.isValid() || marker.getEndOffset() == 0) return FilterResults.EMPTY;
|
||||
ContainerUtil.addIfNotNull(results, task.compute());
|
||||
}
|
||||
return new FilterResults(markerOffset, marker, results);
|
||||
@@ -146,8 +146,8 @@ class AsyncFilterRunner {
|
||||
private static LineHighlighter processLine(Document document, Filter filter, int line) {
|
||||
int lineEnd = document.getLineEndOffset(line);
|
||||
int endOffset = lineEnd + (lineEnd < document.getTextLength() ? 1 /* for \n */ : 0);
|
||||
String text = EditorHyperlinkSupport.getLineText(document, line, true);
|
||||
return () -> checkRange(filter, endOffset, filter.applyFilter(text, endOffset));
|
||||
CharSequence text = EditorHyperlinkSupport.getLineSequence(document, line, true);
|
||||
return () -> checkRange(filter, endOffset, filter.applyFilter(text.toString(), endOffset));
|
||||
}
|
||||
|
||||
private static Filter.Result checkRange(Filter filter, int endOffset, Filter.Result result) {
|
||||
|
||||
@@ -371,11 +371,15 @@ public class EditorHyperlinkSupport {
|
||||
|
||||
@NotNull
|
||||
public static String getLineText(@NotNull Document document, int lineNumber, boolean includeEol) {
|
||||
return getLineSequence(document, lineNumber, includeEol).toString();
|
||||
}
|
||||
|
||||
static CharSequence getLineSequence(@NotNull Document document, int lineNumber, boolean includeEol) {
|
||||
int endOffset = document.getLineEndOffset(lineNumber);
|
||||
if (includeEol && endOffset < document.getTextLength()) {
|
||||
endOffset++;
|
||||
}
|
||||
return document.getImmutableCharSequence().subSequence(document.getLineStartOffset(lineNumber), endOffset).toString();
|
||||
return document.getImmutableCharSequence().subSequence(document.getLineStartOffset(lineNumber), endOffset);
|
||||
}
|
||||
|
||||
private static class HyperlinkInfoTextAttributes extends TextAttributes {
|
||||
|
||||
@@ -54,6 +54,11 @@ public class AntChangeContextFix extends BaseIntentionAction {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean startInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void invoke(@NotNull final Project project, final Editor editor, final PsiFile file) throws IncorrectOperationException {
|
||||
final HectorComponent component = new HectorComponent(file);
|
||||
//final JComponent focusComponent = findComponentToFocus(component);
|
||||
|
||||
Reference in New Issue
Block a user