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 207577
Collapse All | Expand All

(-)a/java.hints/src/org/netbeans/modules/java/hints/bugs/Bundle.properties (-2 / +2 lines)
Lines 119-124 Link Here
119
ERR_UnbalancedCollectionREAD=The collection is never added to
119
ERR_UnbalancedCollectionREAD=The collection is never added to
120
ERR_UnbalancedCollectionWRITE=The collection is only added to, never read
120
ERR_UnbalancedCollectionWRITE=The collection is only added to, never read
121
121
122
DN_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=@CheckReturnValue
122
#DN_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=@CheckReturnValue
123
DESC_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=Verifies that a result of method marked with @CheckReturnValue is really checked.
123
#DESC_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=Verifies that a result of method marked with @CheckReturnValue is really checked.
124
ERR_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=Should check the method return value
124
ERR_org.netbeans.modules.java.hints.bugs.CheckReturnValueHint=Should check the method return value
(-)a/java.hints/src/org/netbeans/modules/java/hints/bugs/CheckReturnValueHint.java (-1 / +1 lines)
Lines 59-65 Link Here
59
 *
59
 *
60
 * @author lahvac
60
 * @author lahvac
61
 */
61
 */
62
@Hint(category="bugs", suppressWarnings="ResultOfMethodCallIgnored")
62
@Hint(displayName="@CheckReturnValue", description="Verifies that a result of method marked with @CheckReturnValue is really checked.", category="bugs", suppressWarnings="ResultOfMethodCallIgnored")
63
public class CheckReturnValueHint {
63
public class CheckReturnValueHint {
64
64
65
    @TriggerPattern("$method($params$);")
65
    @TriggerPattern("$method($params$);")
(-)a/openide.util/nbproject/project.xml (+1 lines)
Lines 81-86 Link Here
81
                <package>org.openide</package>
81
                <package>org.openide</package>
82
                <package>org.openide.util</package>
82
                <package>org.openide.util</package>
83
                <package>org.openide.util.actions</package>
83
                <package>org.openide.util.actions</package>
84
                <package>org.openide.util.annotations</package>
84
                <package>org.openide.util.datatransfer</package>
85
                <package>org.openide.util.datatransfer</package>
85
                <package>org.openide.util.io</package>
86
                <package>org.openide.util.io</package>
86
                <package>org.openide.xml</package>
87
                <package>org.openide.xml</package>
(-)a/openide.util/src/org/netbeans/modules/openide/util/NbBundleProcessor.java (-44 / +49 lines)
Lines 73-89 Link Here
73
import org.openide.util.EditableProperties;
73
import org.openide.util.EditableProperties;
74
import org.openide.util.NbBundle;
74
import org.openide.util.NbBundle;
75
import org.openide.util.Utilities;
75
import org.openide.util.Utilities;
76
import org.openide.util.annotations.AbstractBundleProcessor;
76
import org.openide.util.lookup.ServiceProvider;
77
import org.openide.util.lookup.ServiceProvider;
77
78
78
@ServiceProvider(service = Processor.class)
79
@ServiceProvider(service = Processor.class)
79
@SupportedSourceVersion(SourceVersion.RELEASE_6)
80
@SupportedSourceVersion(SourceVersion.RELEASE_6)
80
public class NbBundleProcessor extends AbstractProcessor {
81
public class NbBundleProcessor extends AbstractBundleProcessor {
81
82
82
    public @Override Set<String> getSupportedAnnotationTypes() {
83
    public @Override Set<String> getSupportedAnnotationTypes() {
83
        return Collections.singleton(NbBundle.Messages.class.getCanonicalName());
84
        return Collections.singleton(NbBundle.Messages.class.getCanonicalName());
84
    }
85
    }
85
86
86
    public @Override boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
87
    protected @Override boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
87
        if (roundEnv.processingOver()) {
88
        if (roundEnv.processingOver()) {
88
            return false;
89
            return false;
89
        }
90
        }
Lines 149-158 Link Here
149
                    String value = keyValue.substring(i + 1);
150
                    String value = keyValue.substring(i + 1);
150
                    pairs.put(key, value);
151
                    pairs.put(key, value);
151
                    compilationUnits.put(key, simplename);
152
                    compilationUnits.put(key, simplename);
153
                    String[] keyComments;
152
                    if (!runningComments.isEmpty()) {
154
                    if (!runningComments.isEmpty()) {
153
                        comments.put(key, runningComments.toArray(new String[runningComments.size()]));
155
                        comments.put(key, keyComments = runningComments.toArray(new String[runningComments.size()]));
154
                        runningComments.clear();
156
                        runningComments.clear();
157
                    } else {
158
                        keyComments = new String[0];
155
                    }
159
                    }
160
                    setBundleKey(pkg, key, new Value(value, keyComments, new Element[] {e}));
156
                }
161
                }
157
                if (!runningComments.isEmpty()) {
162
                if (!runningComments.isEmpty()) {
158
                    processingEnv.getMessager().printMessage(Kind.ERROR, "Comments must precede keys", e);
163
                    processingEnv.getMessager().printMessage(Kind.ERROR, "Comments must precede keys", e);
Lines 160-206 Link Here
160
            }
165
            }
161
            Element[] elements = new HashSet<Element>(identifiers.values()).toArray(new Element[0]);
166
            Element[] elements = new HashSet<Element>(identifiers.values()).toArray(new Element[0]);
162
            try {
167
            try {
163
                EditableProperties p = new EditableProperties(true);
168
//                EditableProperties p = new EditableProperties(true);
164
                // Load any preexisting bundle so we can just add our keys.
169
//                // Load any preexisting bundle so we can just add our keys.
165
                try {
170
//                try {
166
                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, pkg, "Bundle.properties").openInputStream();
171
//                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, pkg, "Bundle.properties").openInputStream();
167
                    try {
172
//                    try {
168
                        p.load(is);
173
//                        p.load(is);
169
                    } finally {
174
//                    } finally {
170
                        is.close();
175
//                        is.close();
171
                    }
176
//                    }
172
                } catch (IOException x) {
177
//                } catch (IOException x) {
173
                    // OK, not there
178
//                    // OK, not there
174
                }
179
//                }
175
                for (String key : p.keySet()) {
180
//                for (String key : p.keySet()) {
176
                    if (pairs.containsKey(key)) {
181
//                    if (pairs.containsKey(key)) {
177
                        processingEnv.getMessager().printMessage(Kind.ERROR, "Key " + key + " is a duplicate of one from Bundle.properties", identifiers.get(toIdentifier(key)));
182
//                        processingEnv.getMessager().printMessage(Kind.ERROR, "Key " + key + " is a duplicate of one from Bundle.properties", identifiers.get(toIdentifier(key)));
178
                    }
183
//                    }
179
                }
184
//                }
180
                // Also check class output for (1) incremental builds, (2) preexisting bundles from Maven projects.
185
//                // Also check class output for (1) incremental builds, (2) preexisting bundles from Maven projects.
181
                try {
186
//                try {
182
                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties").openInputStream();
187
//                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties").openInputStream();
183
                    try {
188
//                    try {
184
                        // do not use p.load(is) as the impl in EditableProperties does not currently handle duplicates properly
189
//                        // do not use p.load(is) as the impl in EditableProperties does not currently handle duplicates properly
185
                        EditableProperties p2 = new EditableProperties(true);
190
//                        EditableProperties p2 = new EditableProperties(true);
186
                        p2.load(is);
191
//                        p2.load(is);
187
                        p.putAll(p2);
192
//                        p.putAll(p2);
188
                    } finally {
193
//                    } finally {
189
                        is.close();
194
//                        is.close();
190
                    }
195
//                    }
191
                } catch (IOException x) {
196
//                } catch (IOException x) {
192
                    // OK, not there
197
//                    // OK, not there
193
                }
198
//                }
194
                p.putAll(pairs);
199
//                p.putAll(pairs);
195
                for (Map.Entry<String,String[]> entry2 : comments.entrySet()) {
200
//                for (Map.Entry<String,String[]> entry2 : comments.entrySet()) {
196
                    p.setComment(entry2.getKey(), entry2.getValue(), false);
201
//                    p.setComment(entry2.getKey(), entry2.getValue(), false);
197
                }
202
//                }
198
                OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", elements).openOutputStream();
203
//                OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", elements).openOutputStream();
199
                try {
204
//                try {
200
                    p.store(os);
205
//                    p.store(os);
201
                } finally {
206
//                } finally {
202
                    os.close();
207
//                    os.close();
203
                }
208
//                }
204
                Map</*identifier*/String,/*method body*/String> methods = new TreeMap<String,String>();
209
                Map</*identifier*/String,/*method body*/String> methods = new TreeMap<String,String>();
205
                for (Map.Entry<String, String> entry2 : pairs.entrySet()) {
210
                for (Map.Entry<String, String> entry2 : pairs.entrySet()) {
206
                    String key = entry2.getKey();
211
                    String key = entry2.getKey();
(-)966826542403 (+179 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.openide.util.annotations;
43
44
import java.io.IOException;
45
import java.io.InputStream;
46
import java.io.OutputStream;
47
import java.io.PrintWriter;
48
import java.io.Writer;
49
import java.util.ArrayList;
50
import java.util.Arrays;
51
import java.util.HashMap;
52
import java.util.List;
53
import java.util.Map;
54
import java.util.Map.Entry;
55
import java.util.Set;
56
import java.util.TreeMap;
57
import java.util.TreeSet;
58
import java.util.regex.Matcher;
59
import java.util.regex.Pattern;
60
import javax.annotation.processing.AbstractProcessor;
61
import javax.annotation.processing.RoundEnvironment;
62
import javax.lang.model.element.Element;
63
import javax.lang.model.element.TypeElement;
64
import javax.tools.Diagnostic.Kind;
65
import javax.tools.StandardLocation;
66
import org.netbeans.modules.openide.util.NbBundleProcessor;
67
import org.openide.util.EditableProperties;
68
69
/**
70
 *
71
 * @author lahvac
72
 */
73
public abstract class AbstractBundleProcessor extends AbstractProcessor {
74
75
    private Map</*package*/String, Map<String, Value>> package2Keys2Values = new HashMap<String, Map<String, Value>>();
76
77
    @Override
78
    public final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
79
        if (!roundEnv.processingOver()) {
80
            return handleProcess(annotations, roundEnv);
81
        }
82
83
        List<Element> totalElements = new ArrayList<Element>();
84
85
        for (Entry<String, Map<String, Value>> e : package2Keys2Values.entrySet()) {
86
            String pkg = e.getKey();
87
            Map<String, Value> key2Value = e.getValue();
88
            
89
            try {
90
                EditableProperties p = new EditableProperties(true);
91
                // Load any preexisting bundle so we can just add our keys.
92
                try {
93
                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, pkg, "Bundle.properties").openInputStream();
94
                    try {
95
                        p.load(is);
96
                    } finally {
97
                        is.close();
98
                    }
99
                } catch (IOException x) {
100
                    // OK, not there
101
                }
102
                for (String key : p.keySet()) {
103
                    if (key2Value.containsKey(key)) {
104
                        Element[] originatingElements = key2Value.get(key).originatingElements;
105
                        if (originatingElements.length == 0) {
106
                            processingEnv.getMessager().printMessage(Kind.ERROR, "Key " + key + " is a duplicate of one from Bundle.properties");
107
                        } else {
108
                            processingEnv.getMessager().printMessage(Kind.ERROR, "Key " + key + " is a duplicate of one from Bundle.properties", originatingElements[0]);
109
                        }
110
                    }
111
                }
112
                // Also check class output for (1) incremental builds, (2) preexisting bundles from Maven projects.
113
                try {
114
                    InputStream is = processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties").openInputStream();
115
                    try {
116
                        // do not use p.load(is) as the impl in EditableProperties does not currently handle duplicates properly
117
                        EditableProperties p2 = new EditableProperties(true);
118
                        p2.load(is);
119
                        p.putAll(p2);
120
                    } finally {
121
                        is.close();
122
                    }
123
                } catch (IOException x) {
124
                    // OK, not there
125
                }
126
127
                for (Entry<String, Value> valEntry : key2Value.entrySet()) {
128
                    p.put(valEntry.getKey(), valEntry.getValue().value);
129
                    p.setComment(valEntry.getKey(), valEntry.getValue().comments, false);
130
                    totalElements.addAll(Arrays.asList(valEntry.getValue().originatingElements));
131
                }
132
                OutputStream os = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, pkg, "Bundle.properties", totalElements.toArray(new Element[0])).openOutputStream();
133
                try {
134
                    p.store(os);
135
                } finally {
136
                    os.close();
137
                }
138
            } catch (IOException x) {
139
                if (totalElements.isEmpty()) {
140
                    processingEnv.getMessager().printMessage(Kind.ERROR, "Could not generate files: " + x);
141
                } else {
142
                    processingEnv.getMessager().printMessage(Kind.ERROR, "Could not generate files: " + x, totalElements.get(0));
143
                }
144
            }
145
        }
146
147
        return true;
148
    }
149
150
    protected abstract boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv);
151
152
    protected final void setBundleKey(String pkg, String key, Value value) {
153
        Map<String, Value> key2Value = package2Keys2Values.get(pkg);
154
155
        if (key2Value == null) {
156
            package2Keys2Values.put(pkg, key2Value = new HashMap<String, Value>());
157
        }
158
159
        if (key2Value.containsKey(key)) {
160
            throw new IllegalStateException("Key already exists: " + key);
161
        }
162
163
        key2Value.put(key, value);
164
    }
165
166
    public static final class Value {
167
        private final String value;
168
        private final String[] comments;
169
        private final Element[] originatingElements;
170
171
        public Value(String value, String[] comments, Element[] originatingElements) {
172
            this.value = value;
173
            this.comments = comments;
174
            this.originatingElements = originatingElements;
175
        }
176
177
    }
178
179
}
(-)a/spi.java.hints/src/org/netbeans/modules/java/hints/providers/code/CodeHintProviderImpl.java (+10 lines)
Lines 381-386 Link Here
381
            return EMPTY_OPTIONS;
381
            return EMPTY_OPTIONS;
382
        }
382
        }
383
383
384
        @Override
385
        public String displayName() {
386
            return "";
387
        }
388
389
        @Override
390
        public String description() {
391
            return "";
392
        }
393
384
    }
394
    }
385
395
386
    private static final class JComponentBasedCustomizerProvider implements CustomizerProvider {
396
    private static final class JComponentBasedCustomizerProvider implements CustomizerProvider {
(-)966826542403 (+89 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2012 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
 * Portions Copyrighted 2012 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.java.hints.spiimpl.processor;
43
44
import java.util.Set;
45
import javax.annotation.processing.Processor;
46
import javax.annotation.processing.RoundEnvironment;
47
import javax.annotation.processing.SupportedAnnotationTypes;
48
import javax.annotation.processing.SupportedSourceVersion;
49
import javax.lang.model.SourceVersion;
50
import javax.lang.model.element.Element;
51
import javax.lang.model.element.PackageElement;
52
import javax.lang.model.element.TypeElement;
53
import org.netbeans.spi.java.hints.Hint;
54
import org.openide.util.annotations.AbstractBundleProcessor;
55
import org.openide.util.lookup.ServiceProvider;
56
57
/**
58
 *
59
 * @author lahvac
60
 */
61
@SupportedSourceVersion(SourceVersion.RELEASE_6)
62
@SupportedAnnotationTypes("org.netbeans.spi.java.hints.Hint")
63
@ServiceProvider(service=Processor.class, position=150)
64
public class BundleProcessor extends AbstractBundleProcessor {
65
66
    @Override
67
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
68
        if (roundEnv.processingOver()) return false;
69
70
        TypeElement hint = processingEnv.getElementUtils().getTypeElement(Hint.class.getName());
71
72
        if (hint == null) return false;
73
74
        for (Element annotated : roundEnv.getElementsAnnotatedWith(hint)) {
75
            String id = JavaHintsAnnotationProcessor.hintId(processingEnv, annotated);
76
            PackageElement pe = processingEnv.getElementUtils().getPackageOf(annotated);
77
            Hint hintObj = annotated.getAnnotation(Hint.class);
78
            if (!hintObj.displayName().isEmpty()) {
79
                setBundleKey(pe.getQualifiedName().toString(), "DN_" + id, new Value(hintObj.displayName(), new String[0], new Element[] {annotated}));
80
            }
81
            if (!hintObj.description().isEmpty()) {
82
                setBundleKey(pe.getQualifiedName().toString(), "DESC_" + id, new Value(hintObj.description(), new String[0], new Element[] {annotated}));
83
            }
84
        }
85
86
        return false;
87
    }
88
89
}
(-)a/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/processor/JavaHintsAnnotationProcessor.java (-14 / +15 lines)
Lines 60-65 Link Here
60
import java.util.logging.Logger;
60
import java.util.logging.Logger;
61
import java.util.regex.Matcher;
61
import java.util.regex.Matcher;
62
import java.util.regex.Pattern;
62
import java.util.regex.Pattern;
63
import javax.annotation.processing.ProcessingEnvironment;
63
import javax.annotation.processing.Processor;
64
import javax.annotation.processing.Processor;
64
import javax.annotation.processing.RoundEnvironment;
65
import javax.annotation.processing.RoundEnvironment;
65
import javax.annotation.processing.SupportedAnnotationTypes;
66
import javax.annotation.processing.SupportedAnnotationTypes;
Lines 242-250 Link Here
242
        return null;
243
        return null;
243
    }
244
    }
244
245
245
    private <T> T getAttributeValue(AnnotationMirror annotation, String attribute, Class<T> clazz) {
246
    private static <T> T getAttributeValue(ProcessingEnvironment processingEnv, AnnotationMirror annotation, String attribute, Class<T> clazz) {
246
        if (clazz.isArray()) {
247
        if (clazz.isArray()) {
247
            Iterable<?> attributes = getAttributeValueInternal(annotation, attribute, Iterable.class);
248
            Iterable<?> attributes = getAttributeValueInternal(processingEnv, annotation, attribute, Iterable.class);
248
            Collection<Object> coll = new ArrayList<Object>();
249
            Collection<Object> coll = new ArrayList<Object>();
249
250
250
            for (Object internal : NbCollections.iterable(NbCollections.checkedIteratorByFilter(attributes.iterator(), clazz.getComponentType(), false))) {
251
            for (Object internal : NbCollections.iterable(NbCollections.checkedIteratorByFilter(attributes.iterator(), clazz.getComponentType(), false))) {
Lines 253-263 Link Here
253
254
254
            return clazz.cast(coll.toArray((Object[]) Array.newInstance(clazz.getComponentType(), 0)));
255
            return clazz.cast(coll.toArray((Object[]) Array.newInstance(clazz.getComponentType(), 0)));
255
        } else {
256
        } else {
256
            return getAttributeValueInternal(annotation, attribute, clazz);
257
            return getAttributeValueInternal(processingEnv, annotation, attribute, clazz);
257
        }
258
        }
258
    }
259
    }
259
260
260
    private <T> T getAttributeValueInternal(AnnotationMirror annotation, String attribute, Class<T> clazz) {
261
    private static <T> T getAttributeValueInternal(ProcessingEnvironment processingEnv, AnnotationMirror annotation, String attribute, Class<T> clazz) {
261
        for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : processingEnv.getElementUtils().getElementValuesWithDefaults(annotation).entrySet()) {
262
        for (Entry<? extends ExecutableElement, ? extends AnnotationValue> e : processingEnv.getElementUtils().getElementValuesWithDefaults(annotation).entrySet()) {
262
            if (e.getKey().getSimpleName().contentEquals(attribute)) {
263
            if (e.getKey().getSimpleName().contentEquals(attribute)) {
263
                Object value = e.getValue().getValue();
264
                Object value = e.getValue().getValue();
Lines 283-293 Link Here
283
        return null;
284
        return null;
284
    }
285
    }
285
    
286
    
286
    private String hintId(Element hint) {
287
    static String hintId(ProcessingEnvironment processingEnv, Element hint) {
287
        AnnotationMirror hintMirror = findAnnotation(hint.getAnnotationMirrors(), "org.netbeans.spi.java.hints.Hint");
288
        AnnotationMirror hintMirror = findAnnotation(hint.getAnnotationMirrors(), "org.netbeans.spi.java.hints.Hint");
288
289
289
        if (hintMirror != null) {
290
        if (hintMirror != null) {
290
            String id = getAttributeValue(hintMirror, "id", String.class);
291
            String id = getAttributeValue(processingEnv, hintMirror, "id", String.class);
291
292
292
            if (id != null && !id.isEmpty()) return id;
293
            if (id != null && !id.isEmpty()) return id;
293
        }
294
        }
Lines 305-311 Link Here
305
    }
306
    }
306
307
307
    private boolean verifyHintAnnotationAcceptable(Element hint) {
308
    private boolean verifyHintAnnotationAcceptable(Element hint) {
308
        String id = hintId(hint);
309
        String id = hintId(processingEnv, hint);
309
310
310
        if (id == null) {
311
        if (id == null) {
311
            return false;
312
            return false;
Lines 320-327 Link Here
320
            FileObject bundle = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, ((PackageElement) hintPackage).getQualifiedName(), "Bundle.properties");
321
            FileObject bundle = processingEnv.getFiler().getResource(StandardLocation.SOURCE_PATH, ((PackageElement) hintPackage).getQualifiedName(), "Bundle.properties");
321
            ResourceBundle rb = new PropertyResourceBundle(bundle.openInputStream());
322
            ResourceBundle rb = new PropertyResourceBundle(bundle.openInputStream());
322
323
323
            checkBundle(rb, "DN_" + id, hint);
324
//            checkBundle(rb, "DN_" + id, hint);
324
            checkBundle(rb, "DESC_" + id, hint);
325
//            checkBundle(rb, "DESC_" + id, hint);
325
        } catch (IOException ex) {
326
        } catch (IOException ex) {
326
            LOG.log(Level.FINE, null, ex);
327
            LOG.log(Level.FINE, null, ex);
327
        } catch (IllegalArgumentException ex) {
328
        } catch (IllegalArgumentException ex) {
Lines 396-406 Link Here
396
        am = findAnnotation(method.getAnnotationMirrors(), "org.netbeans.spi.java.hints.TriggerPatterns");
397
        am = findAnnotation(method.getAnnotationMirrors(), "org.netbeans.spi.java.hints.TriggerPatterns");
397
398
398
        if (am != null) {
399
        if (am != null) {
399
            patternAnnotations.addAll(Arrays.asList(getAttributeValue(am, "value", AnnotationMirror[].class)));
400
            patternAnnotations.addAll(Arrays.asList(getAttributeValue(processingEnv, am, "value", AnnotationMirror[].class)));
400
        }
401
        }
401
402
402
        for (AnnotationMirror patternDescription : patternAnnotations) {
403
        for (AnnotationMirror patternDescription : patternAnnotations) {
403
            String pattern = getAttributeValue(patternDescription, "value", String.class);
404
            String pattern = getAttributeValue(processingEnv, patternDescription, "value", String.class);
404
405
405
            if (pattern == null) continue;
406
            if (pattern == null) continue;
406
407
Lines 411-419 Link Here
411
                variables.add(m.group(0));
412
                variables.add(m.group(0));
412
            }
413
            }
413
414
414
            for (AnnotationMirror constraint : getAttributeValue(patternDescription, "constraints", AnnotationMirror[].class)) {
415
            for (AnnotationMirror constraint : getAttributeValue(processingEnv, patternDescription, "constraints", AnnotationMirror[].class)) {
415
                String variable = getAttributeValue(constraint, "variable", String.class);
416
                String variable = getAttributeValue(processingEnv, constraint, "variable", String.class);
416
                String type = getAttributeValue(constraint, "type", String.class);
417
                String type = getAttributeValue(processingEnv, constraint, "type", String.class);
417
418
418
                if (variable == null || type == null) continue;
419
                if (variable == null || type == null) continue;
419
420
(-)a/spi.java.hints/src/org/netbeans/spi/java/hints/Hint.java (+2 lines)
Lines 63-68 Link Here
63
     * from previous version. Id will be generated automatically is not specified.
63
     * from previous version. Id will be generated automatically is not specified.
64
     */
64
     */
65
    public String id() default "";
65
    public String id() default "";
66
    public String displayName() default "";
67
    public String description() default "";
66
    /**Category where the hint belongs.
68
    /**Category where the hint belongs.
67
     */
69
     */
68
    public String category();
70
    public String category();

Return to bug 207577