IJPL-7 make methods of Navigatable default

They should not be required to be implemented, only `Navigatable.navigationRequest` is.

GitOrigin-RevId: b038cb465de3b9f1d6c37f8578ecd69f8667a10b
This commit is contained in:
Daniil Ovchinnikov
2023-04-17 15:53:28 +02:00
committed by intellij-monorepo-bot
parent c5b0fccfc9
commit df1f55a499
23 changed files with 38 additions and 366 deletions

View File

@@ -1,27 +1,11 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.navigation;
import com.intellij.pom.Navigatable;
import com.intellij.util.IncorrectOperationException;
public final class EmptyNavigatable implements Navigatable {
public static final Navigatable INSTANCE = new EmptyNavigatable();
private EmptyNavigatable() {}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public void navigate(boolean requestFocus) {
throw new IncorrectOperationException("Must not call #navigate() if #canNavigate() returns 'false'");
}
}

View File

@@ -3,6 +3,7 @@ package com.intellij.pom;
import com.intellij.platform.backend.navigation.NavigationRequest;
import com.intellij.platform.backend.navigation.NavigationRequests;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread;
import com.intellij.util.concurrency.annotations.RequiresReadLock;
import org.jetbrains.annotations.ApiStatus.Experimental;
@@ -38,7 +39,12 @@ public interface Navigatable {
*
* @param requestFocus {@code true} if focus requesting is necessary
*/
void navigate(boolean requestFocus);
default void navigate(boolean requestFocus) {
throw new IncorrectOperationException(
"Must not call `navigate(boolean)` if `canNavigate()` returns `false`, " +
"or `navigate(boolean)` should be overridden if `canNavigate()` can return `true`."
);
}
/**
* Indicates whether this instance supports navigation of any kind.
@@ -50,7 +56,9 @@ public interface Navigatable {
*
* @return {@code false} if navigation is not possible for any reason.
*/
boolean canNavigate();
default boolean canNavigate() {
return false;
}
/**
* Indicates whether this instance supports navigation to source (that means some kind of editor).
@@ -62,5 +70,7 @@ public interface Navigatable {
*
* @return {@code false} if navigation to source is not possible for any reason.
*/
boolean canNavigateToSource();
default boolean canNavigateToSource() {
return false;
}
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.util.treeView;
import com.intellij.ide.projectView.PresentationData;
@@ -255,20 +255,6 @@ public abstract class AbstractTreeNode<T> extends PresentableNodeDescriptor<Abst
return myName;
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Nullable
protected final Object getParentValue() {
AbstractTreeNode<?> parent = getParent();

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.find.actions
@@ -56,10 +56,7 @@ class SearchTarget2UsageTarget(
// ----- Navigatable & NavigationItem -----
// TODO Symbol navigation
override fun canNavigate(): Boolean = false
override fun canNavigateToSource(): Boolean = false
override fun getName(): String? = null
override fun navigate(requestFocus: Boolean) = Unit
// ----- actions -----

View File

@@ -515,21 +515,6 @@ public final class FindInProjectUtil {
return this;
}
@Override
public void navigate(boolean requestFocus) {
throw new UnsupportedOperationException();
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public void showSettings() {
Content selectedContent = UsageViewContentManager.getInstance(myProject).getSelectedContent(true);

View File

@@ -1,8 +1,8 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.bookmark.providers
import com.intellij.ide.bookmark.Bookmark
import java.util.Objects
import java.util.*
internal class InvalidBookmark(override val provider: LineBookmarkProvider, val url: String, val line: Int) : Bookmark {
@@ -11,10 +11,6 @@ internal class InvalidBookmark(override val provider: LineBookmarkProvider, val
override fun createNode() = UrlNode(provider.project, this)
override fun canNavigate() = false
override fun canNavigateToSource() = false
override fun navigate(requestFocus: Boolean) = Unit
override fun hashCode() = Objects.hash(provider, url, line)
override fun equals(other: Any?) = other === this || other is InvalidBookmark
&& other.provider == provider

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.rename.impl
import com.intellij.model.Pointer
@@ -52,9 +52,6 @@ internal class RenameTarget2UsageTarget(
// ----- Navigatable & NavigationItem -----
override fun getName(): String? = null
override fun canNavigate(): Boolean = false
override fun canNavigateToSource(): Boolean = false
override fun navigate(requestFocus: Boolean): Unit = Unit
// ----- actions -----

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.refactoring.ui;
@@ -21,7 +21,10 @@ import com.intellij.util.ArrayUtilRt;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.ui.HTMLEditorKitBuilder;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.*;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.HyperlinkEvent;
@@ -270,18 +273,6 @@ public class ConflictsDialog extends DialogWrapper implements ConflictsDialogBas
};
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public void navigate(boolean requestFocus) {}
@Override
public FileEditorLocation getLocation() {
return null;

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 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.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.pom;
/**
@@ -24,18 +10,4 @@ public final class NonNavigatable implements Navigatable {
private NonNavigatable() {
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}

View File

@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.structureView;
import com.intellij.ide.projectView.PresentationData;
@@ -105,20 +91,6 @@ public class TestTreeModel implements StructureViewModel{
public String getValue() {
return myValue;
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}
@Override

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.usages.impl;
import com.intellij.openapi.Disposable;
@@ -152,17 +152,6 @@ public class UsageNodeTreeBuilderTest extends LightPlatformTestCase {
return o instanceof LogUsageGroup && myPower == ((LogUsageGroup)o).myPower;
}
public int hashCode() { return myPower; }
@Override
public void navigate(boolean requestFocus) { }
@Override
public boolean canNavigate() { return false; }
@Override
public boolean canNavigateToSource() {
return false;
}
}
private static class OddEvenGroupingRule extends SingleParentUsageGroupingRule {
@@ -172,16 +161,6 @@ public class UsageNodeTreeBuilderTest extends LightPlatformTestCase {
@NotNull
public String getPresentableGroupText() { return "Even"; }
@Override
public void navigate(boolean focus) throws UnsupportedOperationException { }
@Override
public boolean canNavigate() { return false; }
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public int compareTo(@NotNull UsageGroup o) { return o == ODD ? -1 : 0; }
public String toString() { return getPresentableGroupText(); }
@@ -193,16 +172,6 @@ public class UsageNodeTreeBuilderTest extends LightPlatformTestCase {
@NotNull
public String getPresentableGroupText() { return "Odd"; }
@Override
public void navigate(boolean focus) throws UnsupportedOperationException { }
@Override
public boolean canNavigate() { return false; }
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public int compareTo(@NotNull UsageGroup o) { return o == EVEN ? 1 : 0; }
@Override
@@ -280,20 +249,6 @@ public class UsageNodeTreeBuilderTest extends LightPlatformTestCase {
return String.valueOf(myId);
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public boolean isReadOnly() {
return false;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.structuralsearch.plugin.ui;
import com.intellij.navigation.ItemPresentation;
@@ -61,21 +61,6 @@ class StructuralSearchUsageTarget implements ConfigurableUsageTarget, ItemPresen
return this;
}
@Override
public void navigate(boolean requestFocus) {
throw new UnsupportedOperationException();
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public void showSettings() {
UIUtil.invokeAction(myConfiguration, mySearchContext);

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.structureView.impl;
@@ -118,9 +118,6 @@ public class StructureViewComposite implements StructureView {
@Override public TreeElement @NotNull [] getChildren() { return EMPTY_ARRAY;}
@Nullable @Override public String getPresentableText() { return null;}
@Nullable @Override public Icon getIcon(boolean unused) { return null;}
@Override public void navigate(boolean requestFocus) {}
@Override public boolean canNavigate() { return false;}
@Override public boolean canNavigateToSource() { return false;}
}
return new M();
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.usages.impl.rules;
import com.intellij.usages.UsageGroup;
@@ -11,20 +11,6 @@ public abstract class UsageGroupBase implements UsageGroup {
myOrder = order;
}
@Override
public void navigate(boolean focus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public int compareTo(@NotNull UsageGroup o) {
if (!(o instanceof UsageGroupBase)) {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.usages.impl.rules;
import com.intellij.icons.AllIcons;
@@ -97,16 +97,6 @@ class UsageScopeGroupingRule extends SingleParentUsageGroupingRule implements Du
myCode = code;
}
@Override
public void navigate(boolean focus) { }
@Override
public boolean canNavigate() { return false; }
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public int compareTo(@NotNull UsageGroup usageGroup) {
return getPresentableGroupText().compareTo(usageGroup.getPresentableGroupText());

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.usages.impl.rules;
import com.intellij.psi.PsiComment;
@@ -88,16 +88,6 @@ public class UsageTypeGroupingRule extends SingleParentUsageGroupingRule impleme
return myUsageType.toString();
}
@Override
public void navigate(boolean focus) { }
@Override
public boolean canNavigate() { return false; }
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public int compareTo(@NotNull UsageGroup usageGroup) {
return getPresentableGroupText().compareTo(usageGroup.getPresentableGroupText());

View File

@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.usages.impl;
import com.intellij.openapi.fileEditor.FileEditorLocation;
@@ -51,19 +37,4 @@ public class UsageAdapter implements Usage {
public void highlightInEditor() {
}
@Override
public void navigate(final boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}

View File

@@ -1,18 +1,4 @@
/*
* Copyright 2000-2012 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.
*/
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.xdebugger.impl.breakpoints.ui;
@@ -65,20 +51,6 @@ public class BreakpointNoneItem extends BreakpointItem {
return XDebuggerBundle.message("xbreakpoint.master.breakpoint.none");
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
public String speedSearchText() {
return null;

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package org.jetbrains.idea.devkit.inspections
import com.intellij.codeInsight.hint.HintManager
@@ -670,20 +670,13 @@ private class DummyUsageTarget(@Nls val text: String) : UsageTarget {
}
}
override fun canNavigate(): Boolean = false
override fun getName(): String = text
override fun findUsages() {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
override fun canNavigateToSource() = false
override fun isReadOnly(): Boolean = false
override fun navigate(requestFocus: Boolean) {
}
override fun isValid(): Boolean = true
}

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.lang.properties.editor;
@@ -147,19 +147,4 @@ public final class ResourceBundleFileStructureViewElement implements StructureVi
}
};
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}

View File

@@ -430,20 +430,6 @@ public class XPathEvalAction extends XPathAction {
public ItemPresentation getPresentation() {
return myItemPresentation;
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
}
private static class MyUsageSearcher implements UsageSearcher {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.xml.impl;
import com.intellij.ide.presentation.Presentation;
@@ -125,20 +125,6 @@ public abstract class AbstractDomChildDescriptionImpl implements AbstractDomChil
return true;
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
@Nullable
public ElementPresentationTemplate getPresentationTemplate() {

View File

@@ -1,4 +1,4 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.xml.impl.dom;
import com.intellij.codeInsight.daemon.impl.analysis.XmlHighlightingAwareElementDescriptor;
@@ -94,20 +94,6 @@ public class DomElementXmlDescriptor extends AbstractDomChildrenDescriptor imple
return true;
}
@Override
public void navigate(boolean requestFocus) {
}
@Override
public boolean canNavigate() {
return false;
}
@Override
public boolean canNavigateToSource() {
return false;
}
@Override
@NotNull
public XmlName getXmlName() {