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

(-)a/spi.palette/apichanges.xml (+16 lines)
Lines 110-115 Link Here
110
  <changes>
110
  <changes>
111
    <change>
111
    <change>
112
        <api name="palette_api"/>
112
        <api name="palette_api"/>
113
        <summary>Introduced <code>PaletteItemRegistration</code> and <code>PaletteItemRegistrations</code></summary>
114
        <version major="1" minor="40"/>
115
        <date day="4" month="12" year="2013"/>
116
        <author login="skygo"/>
117
        <compatibility addition="yes"/>
118
          <description>
119
             <p>
120
                  Introduced a new annotation for registering palette items.
121
              </p>
122
          </description>
123
        <class package="org.netbeans.spi.palette" name="PaletteItemRegistration"/>
124
        <class package="org.netbeans.spi.palette" name="PaletteItemRegistrations"/>        
125
        <issue number="227345"/>
126
    </change>      
127
    <change>
128
        <api name="palette_api"/>
113
        <summary>Deprecating ModuleInstall</summary>
129
        <summary>Deprecating ModuleInstall</summary>
114
        <version major="1" minor="31"/>
130
        <version major="1" minor="31"/>
115
        <date day="1" month="4" year="2012"/>
131
        <date day="1" month="4" year="2012"/>
(-)a/spi.palette/manifest.mf (-1 / +1 lines)
Lines 1-5 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.netbeans.spi.palette/1
2
OpenIDE-Module: org.netbeans.spi.palette/1
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/palette/resources/Bundle.properties
3
OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/palette/resources/Bundle.properties
4
OpenIDE-Module-Specification-Version: 1.39
4
OpenIDE-Module-Specification-Version: 1.40
5
OpenIDE-Module-Layer: org/netbeans/modules/palette/resources/layer.xml
5
OpenIDE-Module-Layer: org/netbeans/modules/palette/resources/layer.xml
(-)a/spi.palette/nbproject/project.xml (+5 lines)
Lines 176-181 Link Here
176
                    <test-dependency>
176
                    <test-dependency>
177
                        <code-name-base>org.openide.modules</code-name-base>
177
                        <code-name-base>org.openide.modules</code-name-base>
178
                    </test-dependency>
178
                    </test-dependency>
179
                    <test-dependency>
180
                        <code-name-base>org.openide.util.lookup</code-name-base>
181
                        <compile-dependency/>
182
                        <test/>
183
                    </test-dependency>
179
                </test-type>
184
                </test-type>
180
            </test-dependencies>
185
            </test-dependencies>
181
            <public-packages>
186
            <public-packages>
(-)a/spi.palette/src/org/netbeans/modules/palette/PaletteItemRegistrationProcessor.java (+165 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.palette;
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.ElementKind;
52
import javax.lang.model.element.TypeElement;
53
import javax.lang.model.type.TypeMirror;
54
import org.netbeans.spi.palette.PaletteItemRegistration;
55
import org.netbeans.spi.palette.PaletteItemRegistrations;
56
import org.openide.filesystems.annotations.LayerBuilder;
57
import org.openide.filesystems.annotations.LayerGeneratingProcessor;
58
import org.openide.filesystems.annotations.LayerGenerationException;
59
import org.openide.text.ActiveEditorDrop;
60
import org.openide.util.lookup.ServiceProvider;
61
62
/**
63
 * Processor for PaletteItemRegistration.
64
 *
65
 * @author Eric Barboni <skygo@netbeans.org>
66
 */
67
@ServiceProvider(service = Processor.class)
68
@SupportedSourceVersion(SourceVersion.RELEASE_7)
69
@SupportedAnnotationTypes({"org.netbeans.spi.palette.PaletteItemRegistration", "org.netbeans.spi.palette.PaletteItemRegistrations"})
70
public final class PaletteItemRegistrationProcessor extends LayerGeneratingProcessor {
71
72
    @Override
73
    protected boolean handleProcess(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) throws LayerGenerationException {
74
75
        if (roundEnv.processingOver()) {
76
            return false;
77
        }
78
79
        for (Element e : roundEnv.getElementsAnnotatedWith(PaletteItemRegistration.class)) {
80
            PaletteItemRegistration pir = e.getAnnotation(PaletteItemRegistration.class);
81
            if (pir == null) {
82
                continue;
83
            }
84
            process(e, pir);
85
        }
86
        for (Element e : roundEnv.getElementsAnnotatedWith(PaletteItemRegistrations.class)) {
87
            PaletteItemRegistrations dfrr = e.getAnnotation(PaletteItemRegistrations.class);
88
            if (dfrr == null) {
89
                continue;
90
            }
91
            for (PaletteItemRegistration t : dfrr.value()) {
92
                process(e, t);
93
            }
94
        }
95
        return true;
96
    }
97
98
    private void process(Element e, PaletteItemRegistration pir) throws LayerGenerationException {
99
        LayerBuilder builder = layer(e);
100
        TypeMirror activeEditorDrop = type(ActiveEditorDrop.class);
101
102
        LayerBuilder.File f = builder.file(pir.paletteid() + "/" + pir.category() + "/" + pir.itemid() + ".xml");
103
        StringBuilder paletteFile = new StringBuilder();
104
105
        paletteFile.append("<!DOCTYPE editor_palette_item PUBLIC '-//NetBeans//Editor Palette Item 1.1//EN' 'http://www.netbeans.org/dtds/editor-palette-item-1_1.dtd'>\n");
106
        paletteFile.append("<editor_palette_item version=\"1.1\">\n");
107
108
        if (pir.body().isEmpty()) {
109
            // body empty we need a activeEditorDrop
110
            if (e.getKind() == ElementKind.CLASS && isAssignable(e.asType(), activeEditorDrop)) {
111
                String className = processingEnv.getElementUtils().getBinaryName((TypeElement) e).toString();
112
                paletteFile.append(" <class name=\"").append(className).append("\"/>\n");
113
            } else {
114
                throw new LayerGenerationException("Class annotated with @PaletteItemRegistration has to implements ActiveEditorDrop", e);
115
            }
116
        } else {
117
            // body not empty put info 
118
            paletteFile.append("<body>  <![CDATA[");
119
            paletteFile.append(pir.body());
120
            paletteFile.append("]]> </body>\n");
121
        }
122
123
// icon shoud be in classpath
124
        if (!pir.icon16().isEmpty()) {
125
            builder.validateResource(pir.icon16(), e, pir, "icon16", true);
126
            paletteFile.append("<icon16 urlvalue=\"").append(pir.icon16()).append("\" />\n");
127
        } else {
128
            throw new LayerGenerationException("Icon 16 must be set ", e);
129
        }
130
        if (!pir.icon32().isEmpty()) {
131
            builder.validateResource(pir.icon32(), e, pir, "icon32", true);
132
            paletteFile.append("<icon32 urlvalue=\"").append(pir.icon32()).append("\" />\n");
133
        } else {
134
            throw new LayerGenerationException("Icon 32 must be set ", e);
135
        }
136
137
        paletteFile.append("<inline-description>");
138
        paletteFile.append("<display-name>");
139
        paletteFile.append(pir.name());
140
        paletteFile.append("</display-name>");
141
        paletteFile.append("<tooltip> <![CDATA[ ");
142
        paletteFile.append(pir.tooltip());
143
        paletteFile.append("]]></tooltip>");
144
        paletteFile.append("</inline-description>");
145
146
        paletteFile.append("</editor_palette_item>");
147
148
        f.contents(paletteFile.toString());
149
        f.write();
150
    }
151
152
    // XXX come from other processor in openide
153
    private boolean isAssignable(TypeMirror first, TypeMirror snd) {
154
        if (snd == null) {
155
            return false;
156
        } else {
157
            return processingEnv.getTypeUtils().isAssignable(first, snd);
158
        }
159
    }
160
    // XXX come from other processor in openide
161
    private TypeMirror type(Class<?> type) {
162
        final TypeElement e = processingEnv.getElementUtils().getTypeElement(type.getCanonicalName());
163
        return e == null ? null : e.asType();
164
    }
165
}
(-)a/spi.palette/src/org/netbeans/spi/palette/PaletteItemRegistration.java (+136 lines)
Line 0 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.spi.palette;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * Register a palette item.
51
 *
52
 * This annotation may be used at two level:
53
 * <ul>
54
 * <li><b>at package level</b> body <b>MUST</b> be set;<br><br> 
55
 * Usage example in a package-info.java file, inspired by Netbeans Code Snippet Module Tutorial.<br>
56
 * {@code @PaletteItemRegistration(paletteid = "HTMLPalette", category = "HTML", itemid = "BR",
57
    icon32 = "org/netbeans/modules/newsnippets1/BR32.png",
58
    icon16 = "org/netbeans/modules/newsnippets1/BR16.png",
59
    body = "<br>",
60
    name = "New Line",
61
    tooltip = "<br>")}</li>
62
 * <li><b>at class level</b> on class implementing {@link ActiveEditorDrop}.<br><br>
63
 * {@code @PaletteItemRegistration(
64
    paletteid = "HTMLPalette",
65
    category = "HTML",
66
    itemid = "BR",
67
    icon32 = "org/netbeans/modules/newsnippets1/BR32.png",
68
    icon16 = "org/netbeans/modules/newsnippets1/BR16.png",
69
    body = "&lt;br&gt;",
70
    name = "New Line",
71
    tooltip = "&lt;br&gt;")} <br>
72
  * {@code public class MyPaletteItem implements org.openide.text.ActiveEditorDrop ...}
73
 * </li>
74
 * </ul>
75
 * 
76
 * @author Eric Barboni <skygo@netbeans.org>
77
 * @since 1.40
78
 */
79
@Retention(RetentionPolicy.SOURCE)
80
@Target({ElementType.TYPE, ElementType.PACKAGE})
81
public @interface PaletteItemRegistration {
82
83
    /**
84
     * Palette root name. 
85
     * 
86
     * This is part of palette location in the netbeans layer:<br>
87
     * <b>paletteid</b>/category/itemid
88
     */
89
    String paletteid();
90
91
    /**
92
     * Category for palette item.
93
     * 
94
     * This is part of palette location in the netbeans layer:<br>
95
     * paletteid/<b>category</b>/itemid
96
     */
97
    String category();
98
99
    /**
100
     * Id for palette item.
101
     * 
102
     * This is part of palette location in the netbeans layer:<br>
103
     * paletteid/category/<b>itemid</b>
104
     */
105
     String itemid();
106
107
    /**
108
     * body of palette item.
109
     */
110
    String body() default "";
111
112
    /**
113
     * Path to a 16x16 image file for palette item.
114
     * <br>
115
     * Image must be available in classpath.
116
     */
117
    String icon16();
118
119
    /**
120
     * Path to a 32x32 image file for palette item.
121
     * <br>
122
     * Image must be available in the classpath
123
     */
124
    String icon32();
125
126
    /**
127
     * Display name for palette item.
128
     */
129
    String name();
130
131
    /**
132
     * Tooltip text for palette item.
133
     *
134
     */
135
    String tooltip();
136
}
(-)a/spi.palette/src/org/netbeans/spi/palette/PaletteItemRegistrations.java (+65 lines)
Line 0 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.spi.palette;
43
44
import java.lang.annotation.ElementType;
45
import java.lang.annotation.Retention;
46
import java.lang.annotation.RetentionPolicy;
47
import java.lang.annotation.Target;
48
49
/**
50
 * May be uses to allow multiple
51
 * {@link PaletteItemRegistration PaletteItemRegistration} at one place.
52
 *
53
 * @author Eric Barboni <skygo@netbeans.org>
54
 *
55
 * @since 1.40
56
 */
57
@Retention(RetentionPolicy.SOURCE)
58
@Target({ElementType.PACKAGE})
59
public @interface PaletteItemRegistrations {
60
61
    /**
62
     * array of Paletteitemregistration. 
63
     */
64
    PaletteItemRegistration[] value();
65
}
(-)a/spi.palette/test/unit/src/org/netbeans/modules/palette/PaletteItemRegistrationProcessorTest.java (+203 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2013 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 2013 Sun Microsystems, Inc.
41
 */
42
package org.netbeans.modules.palette;
43
44
import java.awt.GraphicsEnvironment;
45
import java.io.ByteArrayOutputStream;
46
import java.io.IOException;
47
import static junit.framework.Assert.assertFalse;
48
import static junit.framework.Assert.assertTrue;
49
import org.netbeans.junit.NbTestCase;
50
import org.openide.util.test.AnnotationProcessorTestUtils;
51
52
/**
53
 *
54
 * @author Didier
55
 */
56
public class PaletteItemRegistrationProcessorTest extends NbTestCase {
57
58
    static {
59
        System.setProperty("java.awt.headless", "true");
60
    }
61
62
    public PaletteItemRegistrationProcessorTest(String n) {
63
        super(n);
64
    }
65
66
    @Override
67
    protected boolean runInEQ() {
68
        return true;
69
    }
70
71
    @Override
72
    protected void setUp() throws Exception {
73
        super.setUp();
74
    }
75
    private static final String VALID_CLASS_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
76
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", "
77
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\")";
78
    private static final String INVALIDRESOURCE_CLASS_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
79
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16wrong.gif\", "
80
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32wrong.gif\", tooltip = \"tooltip\", name = \"name\")";
81
    private static final String VALID_PACKAGE_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
82
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", "
83
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\" ,body =\"mydummybody\")";    
84
    private static final String INVALIDRESOURCE_PACKAGE_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
85
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16wrong.gif\", "
86
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32wrong.gif\", tooltip = \"tooltip\", name = \"name\" ,body =\"mydummybody\")";   
87
    private static final String INVALID_CLASS_ANNOTATION_1 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
88
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\")";
89
    private static final String INVALID_CLASS_ANNOTATION_2 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
90
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", tooltip = \"tooltip\", name = \"name\")";
91
92
    public void testNoCompliantClassAnnotated() throws IOException {
93
        clearWorkDir();
94
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
95
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A",
96
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
97
                + VALID_CLASS_ANNOTATION
98
                + "public class A {\n"
99
                + "    A() {}"
100
                + "}\n");
101
        ByteArrayOutputStream os = new ByteArrayOutputStream();
102
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
103
        assertFalse("Compilation has to fail:\n" + os, r);
104
    }
105
106
    public void testActiveEditorDropAnnotated() throws IOException {
107
        clearWorkDir();
108
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
109
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
110
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
111
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
112
                + VALID_CLASS_ANNOTATION
113
                + "public class B implements ActiveEditorDrop {\n"
114
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
115
                + "}\n");
116
        ByteArrayOutputStream os = new ByteArrayOutputStream();
117
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
118
        assertTrue("Compilation has to be successfull:\n" + os, r);
119
    }
120
121
    public void testActiveEditorDropAnnotatedWithInvalidResources() throws IOException {
122
        clearWorkDir();
123
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
124
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
125
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
126
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
127
                + INVALIDRESOURCE_CLASS_ANNOTATION
128
                + "public class B implements ActiveEditorDrop {\n"
129
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
130
                + "}\n");
131
        ByteArrayOutputStream os = new ByteArrayOutputStream();
132
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
133
        assertFalse("Compilation has to fail:\n" + os, r);
134
    }
135
    
136
    public void testActiveEditorDropAnnotatedWithMissingIcon16() throws IOException {
137
        clearWorkDir();
138
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
139
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
140
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
141
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
142
                + INVALID_CLASS_ANNOTATION_1
143
                + "public class B implements ActiveEditorDrop {\n"
144
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
145
                + "}\n");
146
        ByteArrayOutputStream os = new ByteArrayOutputStream();
147
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
148
        assertFalse("Compilation has to fail:\n" + os, r);
149
    }
150
151
    public void testActiveEditorDropAnnotatedWithMissingIcon32() throws IOException {
152
        clearWorkDir();
153
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
154
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
155
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
156
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
157
                + INVALID_CLASS_ANNOTATION_2
158
                + "public class B implements ActiveEditorDrop {\n"
159
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
160
                + "}\n");
161
        ByteArrayOutputStream os = new ByteArrayOutputStream();
162
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
163
        assertFalse("Compilation has to fail:\n" + os, r);
164
    }
165
166
    public void testInvalidAnnotatedPackage() throws IOException {
167
        //missing body
168
        clearWorkDir();
169
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
170
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testb.package-info",
171
                VALID_CLASS_ANNOTATION
172
                + "\npackage testa\n;"
173
                + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
174
        ByteArrayOutputStream os = new ByteArrayOutputStream();
175
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
176
        assertFalse("Compilation has to fail:\n" + os, r);
177
    }
178
179
    public void testAnnotatedPackage() throws IOException {
180
        //missing body
181
        clearWorkDir();
182
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
183
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testa.package-info",
184
                VALID_PACKAGE_ANNOTATION
185
                + "\npackage testa\n;"
186
                + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
187
        ByteArrayOutputStream os = new ByteArrayOutputStream();
188
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
189
        assertTrue("Compilation has to be successfull:\n" + os, r);
190
    }
191
    public void testAnnotatedPackageWithInvalidResource() throws IOException {
192
        //missing body
193
        clearWorkDir();
194
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
195
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testa.package-info",
196
                INVALIDRESOURCE_PACKAGE_ANNOTATION
197
                + "\npackage testa\n;"
198
                + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
199
        ByteArrayOutputStream os = new ByteArrayOutputStream();
200
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
201
        assertFalse("Compilation has to fail:\n" + os, r);
202
    }
203
}

Return to bug 227345