This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 271069
Collapse All | Expand All

(-)a/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixAction.java (-8 / +7 lines)
Lines 44-55 Link Here
44
package org.netbeans.modules.editor.hints;
44
package org.netbeans.modules.editor.hints;
45
45
46
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionEvent;
47
import java.util.ArrayList;
48
import java.util.Collection;
47
import javax.swing.AbstractAction;
49
import javax.swing.AbstractAction;
48
import javax.swing.Action;
50
import javax.swing.Action;
49
import javax.swing.text.JTextComponent;
51
import javax.swing.text.JTextComponent;
50
import org.netbeans.editor.ImplementationProvider;
52
import org.netbeans.editor.ImplementationProvider;
53
import org.netbeans.spi.editor.hints.FixableAnnotationProvider;
51
import org.openide.awt.StatusDisplayer;
54
import org.openide.awt.StatusDisplayer;
52
import org.openide.text.CloneableEditorSupport;
55
import org.openide.text.CloneableEditorSupport;
56
import org.openide.util.Lookup;
53
import org.openide.util.NbBundle;
57
import org.openide.util.NbBundle;
54
import org.openide.windows.TopComponent;
58
import org.openide.windows.TopComponent;
55
59
Lines 60-74 Link Here
60
public class FixAction extends AbstractAction {
64
public class FixAction extends AbstractAction {
61
    
65
    
62
    public FixAction() {
66
    public FixAction() {
63
        putValue(NAME, NbBundle.getMessage(FixAction.class, "NM_FixAction"));
67
        putValue(NAME, NbBundle.getMessage(FixAction.class, "NM_FixAction"));        
64
        putValue("supported-annotation-types", new String[] {
68
        putValue("supported-annotation-types", FixableAnnotations.getFixableAnnotationTypes().toArray(new String[0]));
65
            "org-netbeans-spi-editor-hints-parser_annotation_err_fixable",
66
            "org-netbeans-spi-editor-hints-parser_annotation_warn_fixable",
67
            "org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable",
68
            "org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"
69
        });
70
    }
69
    }
71
    
70
72
    public void actionPerformed(ActionEvent e) {
71
    public void actionPerformed(ActionEvent e) {
73
        if (!HintsUI.getDefault().invokeDefaultAction(true)) {
72
        if (!HintsUI.getDefault().invokeDefaultAction(true)) {
74
            Object source = e.getSource();
73
            Object source = e.getSource();
(-)a/spi.editor.hints/src/org/netbeans/modules/editor/hints/FixableAnnotations.java (+71 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.modules.editor.hints;
41
42
import java.util.Collection;
43
import java.util.Collections;
44
import java.util.HashSet;
45
import java.util.Set;
46
import org.netbeans.spi.editor.hints.FixableAnnotationProvider;
47
import org.openide.util.Lookup;
48
49
/**
50
 *
51
 * @author masha
52
 */
53
public final class FixableAnnotations {
54
    private static final Set<String> fixableAnnotations = new HashSet<>();
55
    static {
56
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_err_fixable"); // NOI18N
57
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"); // NOI18N
58
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"); // NOI18N
59
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"); // NOI18N
60
        Collection<? extends FixableAnnotationProvider> providers = Lookup.getDefault().lookupAll(FixableAnnotationProvider.class);
61
        for (FixableAnnotationProvider provider : providers) {
62
            fixableAnnotations.add(provider.getFixableAnnotationType());
63
        }
64
        
65
    }    
66
    
67
    public static  Set<String> getFixableAnnotationTypes() {
68
        return Collections.unmodifiableSet(fixableAnnotations);
69
    }
70
    
71
}
(-)a/spi.editor.hints/src/org/netbeans/modules/editor/hints/HintsUI.java (-12 / +3 lines)
Lines 51-57 Link Here
51
import java.awt.Container;
51
import java.awt.Container;
52
import java.awt.Cursor;
52
import java.awt.Cursor;
53
import java.awt.Dimension;
53
import java.awt.Dimension;
54
import java.awt.GraphicsConfiguration;
55
import java.awt.GraphicsDevice;
54
import java.awt.GraphicsDevice;
56
import java.awt.GraphicsEnvironment;
55
import java.awt.GraphicsEnvironment;
57
import java.awt.HeadlessException;
56
import java.awt.HeadlessException;
Lines 124-129 Link Here
124
import org.netbeans.spi.editor.hints.ErrorDescription;
123
import org.netbeans.spi.editor.hints.ErrorDescription;
125
import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
124
import org.netbeans.spi.editor.hints.ErrorDescriptionFactory;
126
import org.netbeans.spi.editor.hints.Fix;
125
import org.netbeans.spi.editor.hints.Fix;
126
import org.netbeans.spi.editor.hints.FixableAnnotationProvider;
127
import org.netbeans.spi.editor.hints.PositionRefresher;
127
import org.netbeans.spi.editor.hints.PositionRefresher;
128
import org.openide.ErrorManager;
128
import org.openide.ErrorManager;
129
import org.openide.awt.StatusDisplayer;
129
import org.openide.awt.StatusDisplayer;
Lines 155-174 Link Here
155
    //-J-Dorg.netbeans.modules.editor.hints.HintsUI.always.show.error=true
155
    //-J-Dorg.netbeans.modules.editor.hints.HintsUI.always.show.error=true
156
    private static final boolean ALWAYS_SHOW_ERROR_MESSAGE = Boolean.getBoolean(HintsUI.class.getName() + ".always.show.error");
156
    private static final boolean ALWAYS_SHOW_ERROR_MESSAGE = Boolean.getBoolean(HintsUI.class.getName() + ".always.show.error");
157
    private static HintsUI INSTANCE;
157
    private static HintsUI INSTANCE;
158
    private static final Set<String> fixableAnnotations;
159
    private static final String POPUP_NAME = "hintsPopup"; // NOI18N
158
    private static final String POPUP_NAME = "hintsPopup"; // NOI18N
160
    private static final String SUB_POPUP_NAME = "subHintsPopup"; // NOI18N
159
    private static final String SUB_POPUP_NAME = "subHintsPopup"; // NOI18N
161
    private static final int POPUP_VERTICAL_OFFSET = 5;
160
    private static final int POPUP_VERTICAL_OFFSET = 5;
162
    private static final RequestProcessor WORKER = new RequestProcessor(HintsUI.class.getName(), 1, false, false);
161
    private static final RequestProcessor WORKER = new RequestProcessor(HintsUI.class.getName(), 1, false, false);
163
162
164
    static {
165
        fixableAnnotations = new HashSet<String>(3);
166
167
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_err_fixable"); // NOI18N
168
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_hint_fixable"); // NOI18N
169
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_verifier_fixable"); // NOI18N
170
        fixableAnnotations.add("org-netbeans-spi-editor-hints-parser_annotation_warn_fixable"); // NOI18N
171
    }
172
163
173
    public static synchronized HintsUI getDefault() {
164
    public static synchronized HintsUI getDefault() {
174
        if (INSTANCE == null)
165
        if (INSTANCE == null)
Lines 681-689 Link Here
681
                        return false;
672
                        return false;
682
                    }
673
                    }
683
                    String type = activeAnnotation.getAnnotationType();
674
                    String type = activeAnnotation.getAnnotationType();
684
                    if (!fixableAnnotations.contains(type) && onlyActive) {
675
                    if (!FixableAnnotations.getFixableAnnotationTypes().contains(type) && onlyActive) {
685
                        return false;
676
                        return false;
686
                    }
677
                    }                    
687
                    if (onlyActive) {
678
                    if (onlyActive) {
688
                        refresh(doc, comp.getCaretPosition());
679
                        refresh(doc, comp.getCaretPosition());
689
                    }
680
                    }
(-)a/spi.editor.hints/src/org/netbeans/spi/editor/hints/FixableAnnotationProvider.java (+50 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.spi.editor.hints;
41
42
/**
43
 * Use it if your annotation type need to have default fix it action enabled on mouse click
44
 * Register using ServiceProvider
45
 * @author mromashova
46
 */
47
public interface FixableAnnotationProvider {
48
    public String getFixableAnnotationType();
49
    
50
}

Return to bug 271069