mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
highlight usages tests -> community
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
class Usage extends<caret> Base{
|
||||
void foo() {
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
void foo(){}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class Usage <caret>implements Base{
|
||||
void foo() {
|
||||
}
|
||||
}
|
||||
interface Base {
|
||||
void foo();
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
class Usage <caret>implements Base, Other{
|
||||
public void foo() {
|
||||
}
|
||||
public void other() {}
|
||||
}
|
||||
interface Base {
|
||||
void foo();
|
||||
}
|
||||
interface Other {
|
||||
void other();
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class Usage <caret>extends Base{
|
||||
void foo3() {
|
||||
}
|
||||
}
|
||||
class Base {
|
||||
void foo() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Calculator {
|
||||
public void printError(String detail, int line, String file) <caret>throws Exception {
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Calculator {
|
||||
public void printError(Object detail, int line, String file) <caret>throws Exception {
|
||||
throw (Exception)detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class Calculator {
|
||||
public void printError(Exception detail, int line, String file) <caret>throws Exception {
|
||||
throw detail;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
class Usage {
|
||||
void foo() {
|
||||
foo();
|
||||
<caret>foo();
|
||||
}
|
||||
}
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
package com.intellij.codeInsight.highlighting;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.sillyAssignment.SillyAssignmentInspection;
|
||||
import com.intellij.openapi.editor.markup.RangeHighlighter;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author cdr
|
||||
*/
|
||||
public class HighlightUsagesHandlerTest extends LightCodeInsightTestCase {
|
||||
private static void ctrlShiftF7() {
|
||||
HighlightUsagesHandler.invoke(getProject(), getEditor(), getFile());
|
||||
}
|
||||
|
||||
public void testSimpleThrows() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("throws", "Exception");
|
||||
checkUnselect();
|
||||
}
|
||||
public void testThrowsExpression() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("throws", "(Exception)detail");
|
||||
checkUnselect();
|
||||
}
|
||||
public void testThrowsReference() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("throws", "detail");
|
||||
checkUnselect();
|
||||
}
|
||||
|
||||
private static void checkUnselect() {
|
||||
ctrlShiftF7();
|
||||
assertRangeText();
|
||||
}
|
||||
|
||||
public void testUnselectUsage() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("foo", "foo", "foo");
|
||||
checkUnselect();
|
||||
}
|
||||
|
||||
public void testHighlightOverridden() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("extends", "foo");
|
||||
checkUnselect();
|
||||
}
|
||||
public void testHighlightOverriddenImplements() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("implements", "foo");
|
||||
checkUnselect();
|
||||
}
|
||||
public void testHighlightOverriddenNothing() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText();
|
||||
checkUnselect();
|
||||
}
|
||||
public void testHighlightOverriddenMultiple() throws Exception {
|
||||
configureFile();
|
||||
ctrlShiftF7();
|
||||
assertRangeText("implements", "foo", "other");
|
||||
checkUnselect();
|
||||
}
|
||||
|
||||
public void testIDEADEV28822() throws Exception {
|
||||
configureFromFileText("Foo.java",
|
||||
"""public class Foo {public String foo(String s) {
|
||||
while (s.length() > 0) {
|
||||
if (s.length() < 0) {
|
||||
s = "";
|
||||
continue;
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
re<caret>turn s;
|
||||
}
|
||||
}""");
|
||||
ctrlShiftF7();
|
||||
assertRangeText("return s;");
|
||||
}
|
||||
|
||||
public void testReturnsInTryFinally() throws Exception {
|
||||
// See IDEADEV-14028
|
||||
configureFromFileText("Foo.java",
|
||||
"""public class Foo {
|
||||
int foo(boolean b) {
|
||||
try {
|
||||
if (b) return 1;
|
||||
}
|
||||
finally {
|
||||
if (b) return 2;
|
||||
}
|
||||
r<caret>eturn 3;
|
||||
}
|
||||
}""");
|
||||
|
||||
ctrlShiftF7();
|
||||
assertRangeText("return 1;", "return 2;", "return 3;");
|
||||
}
|
||||
|
||||
public void testReturnsInLambda() throws Exception {
|
||||
// See IDEADEV-14028
|
||||
configureFromFileText("Foo.java",
|
||||
"""public class Foo {
|
||||
{
|
||||
Runnable r = () -> {
|
||||
if (true) return;
|
||||
retur<caret>n;
|
||||
}
|
||||
}
|
||||
}""");
|
||||
|
||||
ctrlShiftF7();
|
||||
assertRangeText("return;", "return;");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
return [new SillyAssignmentInspection()]
|
||||
}
|
||||
|
||||
public void testSuppressedWarningsHighlights() throws Exception {
|
||||
configureFromFileText("Foo.java", """public class Foo {
|
||||
@SuppressWarnings({"Sil<caret>lyAssignment"})
|
||||
void foo() {
|
||||
int i = 0;
|
||||
i = i;
|
||||
}
|
||||
}""");
|
||||
ctrlShiftF7();
|
||||
assertRangeText("i = i");
|
||||
}
|
||||
|
||||
private static void assertRangeText(@NonNls String... texts) {
|
||||
RangeHighlighter[] highlighters = getEditor().getMarkupModel().getAllHighlighters();
|
||||
assertSameElements(highlighters.collect { myFile.text.substring(it.startOffset, it.endOffset) }, texts)
|
||||
}
|
||||
|
||||
private void configureFile() throws Exception {
|
||||
configureByFile("/codeInsight/highlightUsagesHandler/" + getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user