This is an automated email from the ASF dual-hosted git repository. sdedic pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new c5d161220d Remove dependency of decl. hints on hints UI; UI plugs into hints SPI. (#5671) c5d161220d is described below commit c5d161220d86d4d495b8e8cfb46c4f81ab2b8c88 Author: Svatopluk Dedic <svatopluk.de...@oracle.com> AuthorDate: Tue Apr 11 02:35:58 2023 -0700 Remove dependency of decl. hints on hints UI; UI plugs into hints SPI. (#5671) --- java/java.hints.declarative/nbproject/project.xml | 8 --- .../idebinding/HintsActionProvider.java | 8 ++- .../refactoring/HintsRefactoringUIFactory.java | 59 ++++++++++++++++++++++ java/java.hints/nbproject/project.xml | 9 ---- .../nbcode/nbproject/platform.properties | 1 + java/spi.java.hints/apichanges.xml | 16 ++++++ java/spi.java.hints/nbproject/project.properties | 2 +- .../hints/spiimpl/HintsRefactoringFactory.java | 44 ++++++++++++++++ .../modules/java/hints/spiimpl/Utilities.java | 35 +++++++++++++ 9 files changed, 159 insertions(+), 23 deletions(-) diff --git a/java/java.hints.declarative/nbproject/project.xml b/java/java.hints.declarative/nbproject/project.xml index 98dbff2fdc..9b46676401 100644 --- a/java/java.hints.declarative/nbproject/project.xml +++ b/java/java.hints.declarative/nbproject/project.xml @@ -141,14 +141,6 @@ <implementation-version/> </run-dependency> </dependency> - <dependency> - <code-name-base>org.netbeans.modules.java.hints.ui</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <implementation-version/> - </run-dependency> - </dependency> <dependency> <code-name-base>org.netbeans.modules.java.lexer</code-name-base> <build-prerequisite/> diff --git a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/idebinding/HintsActionProvider.java b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/idebinding/HintsActionProvider.java index 7547e6fe87..2b98fcda3b 100644 --- a/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/idebinding/HintsActionProvider.java +++ b/java/java.hints.declarative/src/org/netbeans/modules/java/hints/declarative/idebinding/HintsActionProvider.java @@ -24,16 +24,15 @@ import javax.swing.text.BadLocationException; import javax.swing.text.Document; import org.netbeans.modules.java.hints.declarative.DeclarativeHintRegistry; import org.netbeans.modules.java.hints.declarative.HintDataObject; -import org.netbeans.modules.java.hints.spiimpl.refactoring.InspectAndRefactorUI; import org.netbeans.modules.java.hints.providers.spi.HintDescription; import org.netbeans.modules.java.hints.providers.spi.HintMetadata; +import org.netbeans.modules.java.hints.spiimpl.Utilities; import org.netbeans.spi.project.ActionProvider; import org.openide.awt.StatusDisplayer; import org.openide.cookies.EditorCookie; import org.openide.filesystems.FileUtil; import org.openide.util.Exceptions; import org.openide.util.Lookup; -import org.openide.util.lookup.Lookups; import org.openide.util.lookup.ServiceProvider; /** @@ -80,9 +79,8 @@ public class HintsActionProvider implements ActionProvider { StatusDisplayer.getDefault().setStatusText("No hints specified in " + FileUtil.getFileDisplayName(hdo.getPrimaryFile())); return; } - - HintMetadata m = hints.entrySet().iterator().next().getKey(); - InspectAndRefactorUI.openRefactoringUI(Lookups.singleton(new InspectAndRefactorUI.HintWrap(m, DeclarativeHintRegistry.join(hints)))); + + Utilities.openRefactoringUIOrWarn(hints, null); } @Override diff --git a/java/java.hints.ui/src/org/netbeans/modules/java/hints/spiimpl/refactoring/HintsRefactoringUIFactory.java b/java/java.hints.ui/src/org/netbeans/modules/java/hints/spiimpl/refactoring/HintsRefactoringUIFactory.java new file mode 100644 index 0000000000..4c9724e5ab --- /dev/null +++ b/java/java.hints.ui/src/org/netbeans/modules/java/hints/spiimpl/refactoring/HintsRefactoringUIFactory.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.java.hints.spiimpl.refactoring; + +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import org.netbeans.modules.java.hints.providers.spi.HintDescription; +import org.netbeans.modules.java.hints.providers.spi.HintMetadata; +import org.netbeans.modules.java.hints.spiimpl.HintsRefactoringFactory; +import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; +import org.openide.util.lookup.Lookups; +import org.openide.util.lookup.ServiceProvider; + +/** + * + * @author sdedic + */ +@ServiceProvider(service = HintsRefactoringFactory.class) +public class HintsRefactoringUIFactory implements HintsRefactoringFactory { + + public static Collection<? extends HintDescription> join(Map<HintMetadata, Collection<? extends HintDescription>> hints) { + List<HintDescription> descs = new LinkedList<>(); + + for (Collection<? extends HintDescription> c : hints.values()) { + descs.addAll(c); + } + + return descs; + } + + @Override + public RefactoringUI createRefactoringUI(Map<HintMetadata, Collection<? extends HintDescription>> hints) { + if (hints.isEmpty()) { + return null; + } + HintMetadata m = hints.keySet().iterator().next(); + InspectAndRefactorUI.HintWrap wrap = new InspectAndRefactorUI.HintWrap(m, join(hints)); + return new InspectAndRefactorUI(null, true, false, Lookups.singleton(wrap)); + } + +} diff --git a/java/java.hints/nbproject/project.xml b/java/java.hints/nbproject/project.xml index 5681d6ef3e..d1fd03a8f7 100644 --- a/java/java.hints/nbproject/project.xml +++ b/java/java.hints/nbproject/project.xml @@ -103,15 +103,6 @@ <specification-version>3.0</specification-version> </run-dependency> </dependency> - <dependency> - <code-name-base>org.netbeans.modules.code.analysis</code-name-base> - <build-prerequisite/> - <compile-dependency/> - <run-dependency> - <release-version>0</release-version> - <specification-version>1.0</specification-version> - </run-dependency> - </dependency> <dependency> <code-name-base>org.netbeans.modules.editor</code-name-base> <build-prerequisite/> diff --git a/java/java.lsp.server/nbcode/nbproject/platform.properties b/java/java.lsp.server/nbcode/nbproject/platform.properties index b289bcf930..3980d1e377 100644 --- a/java/java.lsp.server/nbcode/nbproject/platform.properties +++ b/java/java.lsp.server/nbcode/nbproject/platform.properties @@ -173,6 +173,7 @@ disabled.modules=\ org.netbeans.modules.java.graph,\ org.netbeans.modules.java.hints.declarative.test,\ org.netbeans.modules.java.hints.test,\ + org.netbeans.modules.java.hints.ui,\ org.netbeans.modules.java.j2sedeploy,\ org.netbeans.modules.java.j2seembedded,\ org.netbeans.modules.java.j2semodule,\ diff --git a/java/spi.java.hints/apichanges.xml b/java/spi.java.hints/apichanges.xml index 952bb9e286..ce9997df45 100644 --- a/java/spi.java.hints/apichanges.xml +++ b/java/spi.java.hints/apichanges.xml @@ -25,6 +25,22 @@ <apidef name="JavaHintsSPI">Java Hints SPI</apidef> </apidefs> <changes> + <change id="openRefactoringUI"> + <api name="JavaHintsSPI"/> + <summary>Added utility methods and SPI to open UI for hints</summary> + <version major="1" minor="53"/> + <date day="17" month="3" year="2021"/> + <compatibility addition="yes"/> + <description> + <p> + Internal helper method added to open refactoring UI with selected hints. + <a href="@TOP@/org/netbeans/modules/java/hints/spiimpl/HintsRefactoringFactory.html">Added SPI</a> that + can be implemented by UI module(s) to actually provide the UI implementation. + </p> + </description> + <class package="org.netbeans.modules.java.hints.spiimpl" name="HintsRefactoringFactory"/> + <class package="org.netbeans.modules.java.hints.spiimpl" name="Utilities"/> + </change> <change id="JavaFixUtilities.isPrimary"> <api name="JavaHintsSPI"/> <summary>Added JavaFixUtilities.isPrimary() utility</summary> diff --git a/java/spi.java.hints/nbproject/project.properties b/java/spi.java.hints/nbproject/project.properties index 8c51666f9e..7f4d00e040 100644 --- a/java/spi.java.hints/nbproject/project.properties +++ b/java/spi.java.hints/nbproject/project.properties @@ -17,7 +17,7 @@ is.autoload=true javac.source=1.8 javac.compilerargs=-Xlint -Xlint:-serial -spec.version.base=1.52.0 +spec.version.base=1.53.0 requires.nb.javac=true javadoc.arch=${basedir}/arch.xml javadoc.apichanges=${basedir}/apichanges.xml diff --git a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/HintsRefactoringFactory.java b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/HintsRefactoringFactory.java new file mode 100644 index 0000000000..29111ee34c --- /dev/null +++ b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/HintsRefactoringFactory.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.netbeans.modules.java.hints.spiimpl; + +import java.util.Collection; +import java.util.Map; +import org.netbeans.api.annotations.common.CheckForNull; +import org.netbeans.api.annotations.common.NonNull; +import org.netbeans.modules.java.hints.providers.spi.HintDescription; +import org.netbeans.modules.java.hints.providers.spi.HintMetadata; +import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; +import org.netbeans.modules.refactoring.spi.ui.UI; + +/** + * Creates a {@link RefactoringUI} initialized for the given collection of hints. The returned UI must be suitable for execution + * using {@link UI#openRefactoringUI(org.netbeans.modules.refactoring.spi.ui.RefactoringUI)} and its variants. + * + * @author sdedic + */ +public interface HintsRefactoringFactory { + /** + * Constructs a refactoring UI for the given collection of hints. The implementation may refuse creation if (any of) the requested + * hints are not suitable or unsupported by returning {@code null}. + * @param hintsCollection the hints + * @return initialized UI delegate or {@code null}. + */ + public @CheckForNull RefactoringUI createRefactoringUI(@NonNull Map<HintMetadata, Collection<? extends HintDescription>> hintsCollection); +} diff --git a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java index a88aabb3fa..2776dfb805 100644 --- a/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java +++ b/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/Utilities.java @@ -166,6 +166,15 @@ import org.openide.util.WeakListeners; import org.openide.util.lookup.ServiceProvider; import static com.sun.source.tree.CaseTree.CaseKind.STATEMENT; +import org.netbeans.api.annotations.common.NullAllowed; +import org.netbeans.modules.java.hints.providers.spi.HintMetadata; +import org.netbeans.modules.refactoring.spi.ui.RefactoringUI; +import org.netbeans.modules.refactoring.spi.ui.UI; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.NbBundle; +import org.openide.util.Parameters; +import org.openide.windows.TopComponent; /** * @@ -1518,6 +1527,32 @@ public class Utilities { return false; } + + @NbBundle.Messages({ + "WARNING_NoRefactoringUI=Cannot start refactoring: no UI implementation is available." + }) + public static void openRefactoringUIOrWarn(@NonNull Map<HintMetadata, Collection<? extends HintDescription>> hintsCollection, @NullAllowed TopComponent parent) { + if (openRefactoringUI(hintsCollection, parent)) { + return; + } + NotifyDescriptor d = new NotifyDescriptor.Message(Bundle.WARNING_NoRefactoringUI(), NotifyDescriptor.WARNING_MESSAGE); + DialogDisplayer.getDefault().notifyLater(d); + } + + public static boolean openRefactoringUI(@NonNull Map<HintMetadata, Collection<? extends HintDescription>> hintsCollection, @NullAllowed TopComponent parent) { + Parameters.notNull("hintsCollection", hintsCollection); + if (hintsCollection.isEmpty()) { + return true; + } + for (HintsRefactoringFactory f : Lookup.getDefault().lookupAll(HintsRefactoringFactory.class)) { + RefactoringUI ui = f.createRefactoringUI(hintsCollection); + if (ui != null) { + UI.openRefactoringUI(ui, parent); + return true; + } + } + return false; + } public static boolean isFakeBlock(Tree t) { return t instanceof FakeBlock; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists