diff --git a/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixAction.java b/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixAction.java --- a/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixAction.java +++ b/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixAction.java @@ -44,12 +44,16 @@ package org.netbeans.modules.editor.hints; import java.awt.event.ActionEvent; +import java.util.ArrayList; +import java.util.Collection; import javax.swing.AbstractAction; import javax.swing.Action; import javax.swing.text.JTextComponent; import org.netbeans.editor.ImplementationProvider; +import org.netbeans.spi.editor.hints.FixableAnnotationProvider; import org.openide.awt.StatusDisplayer; import org.openide.text.CloneableEditorSupport; +import org.openide.util.Lookup; import org.openide.util.NbBundle; import org.openide.windows.TopComponent; @@ -60,15 +64,10 @@ public class FixAction extends AbstractAction { public FixAction() { - putValue(NAME, NbBundle.getMessage(FixAction.class, "NM_FixAction")); - putValue("supported-annotation-types", new String[] { - "org-netbeans-spi-editor-hints-parser_annotation_err_fixable", - "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable", - "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable", - "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable" - }); + putValue(NAME, NbBundle.getMessage(FixAction.class, "NM_FixAction")); + putValue("supported-annotation-types", FixableAnnotations.getFixableAnnotationTypes().toArray(new String[0])); } - + public void actionPerformed(ActionEvent e) { if (!HintsUI.getDefault().invokeDefaultAction(true)) { Object source = e.getSource(); diff --git a/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixableAnnotations.java b/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixableAnnotations.java new file mode 100644 --- /dev/null +++ b/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixableAnnotations.java @@ -0,0 +1,71 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + */ +package org.netbeans.modules.editor.hints; + +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.netbeans.spi.editor.hints.FixableAnnotationProvider; +import org.openide.util.Lookup; + +/** + * + * @author masha + */ +public final class FixableAnnotations { + private static final Set fixableAnnotations = new HashSet<>(); + static { + fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_err_fixable"); // NOI18N + fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"); // NOI18N + fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"); // NOI18N + fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"); // NOI18N + Collection providers = Lookup.getDefault().lookupAll(FixableAnnotationProvider.class); + for (FixableAnnotationProvider provider : providers) { + fixableAnnotations.add(provider.getFixableAnnotationType()); + } + + } + + public static Set getFixableAnnotationTypes() { + return Collections.unmodifiableSet(fixableAnnotations); + } + +} diff --git a/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java b/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java --- a/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java +++ b/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java @@ -51,7 +51,6 @@ import java.awt.Container; import java.awt.Cursor; import java.awt.Dimension; -import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.HeadlessException; @@ -124,6 +123,7 @@ import org.netbeans.spi.editor.hints.ErrorDescription; import org.netbeans.spi.editor.hints.ErrorDescriptionFactory; import org.netbeans.spi.editor.hints.Fix; +import org.netbeans.spi.editor.hints.FixableAnnotationProvider; import org.netbeans.spi.editor.hints.PositionRefresher; import org.openide.ErrorManager; import org.openide.awt.StatusDisplayer; @@ -155,20 +155,11 @@ //-J-Dorg.netbeans.modules.editor.hints.HintsUI.always.show.error=true private static final boolean ALWAYS_SHOW_ERROR_MESSAGE = Boolean.getBoolean(HintsUI.class.getName() + ".always.show.error"); private static HintsUI INSTANCE; - private static final Set fixableAnnotations; private static final String POPUP_NAME = "hintsPopup"; // NOI18N private static final String SUB_POPUP_NAME = "subHintsPopup"; // NOI18N private static final int POPUP_VERTICAL_OFFSET = 5; private static final RequestProcessor WORKER = new RequestProcessor(HintsUI.class.getName(), 1, false, false); - static { - fixableAnnotations = new HashSet(3); - - fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_err_fixable"); // NOI18N - fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"); // NOI18N - fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"); // NOI18N - fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"); // NOI18N - } public static synchronized HintsUI getDefault() { if (INSTANCE == null) @@ -681,9 +672,9 @@ return false; } String type = activeAnnotation.getAnnotationType(); - if (!fixableAnnotations.contains(type) && onlyActive) { + if (!FixableAnnotations.getFixableAnnotationTypes().contains(type) && onlyActive) { return false; - } + } if (onlyActive) { refresh(doc, comp.getCaretPosition()); } diff --git a/spi.editor.hints/src/org/netbeans/spi/editor/hints/FixableAnnotationProvider.java b/spi.editor.hints/src/org/netbeans/spi/editor/hints/FixableAnnotationProvider.java new file mode 100644 --- /dev/null +++ b/spi.editor.hints/src/org/netbeans/spi/editor/hints/FixableAnnotationProvider.java @@ -0,0 +1,50 @@ +/* + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. + * + * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved. + * + * Oracle and Java are registered trademarks of Oracle and/or its affiliates. + * Other names may be trademarks of their respective owners. + * + * The contents of this file are subject to the terms of either the GNU + * General Public License Version 2 only ("GPL") or the Common + * Development and Distribution License("CDDL") (collectively, the + * "License"). You may not use this file except in compliance with the + * License. You can obtain a copy of the License at + * http://www.netbeans.org/cddl-gplv2.html + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the + * specific language governing permissions and limitations under the + * License. When distributing the software, include this License Header + * Notice in each file and include the License file at + * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the GPL Version 2 section of the License file that + * accompanied this code. If applicable, add the following below the + * License Header, with the fields enclosed by brackets [] replaced by + * your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * If you wish your version of this file to be governed by only the CDDL + * or only the GPL Version 2, indicate your decision by adding + * "[Contributor] elects to include this software in this distribution + * under the [CDDL or GPL Version 2] license." If you do not indicate a + * single choice of license, a recipient has the option to distribute + * your version of this file under either the CDDL, the GPL Version 2 or + * to extend the choice of license to its licensees as provided above. + * However, if you add GPL Version 2 code and therefore, elected the GPL + * Version 2 license, then the option applies only if the new code is + * made subject to such option by the copyright holder. + * + * Contributor(s): + */ +package org.netbeans.spi.editor.hints; + +/** + * Use it if your annotation type need to have default fix it action enabled on mouse click + * Register using ServiceProvider + * @author mromashova + */ +public interface FixableAnnotationProvider { + public String getFixableAnnotationType(); + +}