Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 227345 | Differences between
and this patch

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_6)
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.getEnclosingElement(), 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.getEnclosingElement(), 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 (+108 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 MUST be set;</li>
55
 * <li><b>at class level</b> on class implementing
56
 * {@link ActiveEditorDrop}.</li>
57
 * </ul>
58
 *
59
 * @author Eric Barboni <skygo@netbeans.org>
60
 * @since 1.32
61
 */
62
@Retention(RetentionPolicy.SOURCE)
63
@Target({ElementType.TYPE, ElementType.PACKAGE})
64
public @interface PaletteItemRegistration {
65
66
    /**
67
     * Palette root name.
68
     */
69
    String paletteid();
70
71
    /**
72
     * category for palette item.
73
     */
74
    String category();
75
76
    /**
77
     * itemid for palette item.
78
     */
79
    String itemid();
80
81
    /**
82
     * body of palette item.
83
     */
84
    String body() default "";
85
86
    /**
87
     * Path to a 16x16 image file for palette item.
88
     *
89
     */
90
    String icon16();
91
92
    /**
93
     * Path to a 32x32 image file for palette item.
94
     *
95
     */
96
    String icon32();
97
98
    /**
99
     * Name for palette item.
100
     */
101
    String name();
102
103
    /**
104
     * Tooltip text for palette item.
105
     *
106
     */
107
    String tooltip();
108
}
(-)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.32
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 (+170 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 VALID_PACKAGE_ANNOTATION = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
79
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", "
80
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\" ,body =\"mydummybody\")";
81
    private static final String INVALID_CLASS_ANNOTATION_1 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
82
            + "icon32 = \"org/netbeans/modules/palette/resources/unknown32.gif\", tooltip = \"tooltip\", name = \"name\")";
83
    private static final String INVALID_CLASS_ANNOTATION_2 = "@PaletteItemRegistration(paletteid = \"JavaPalette\", category = \"dummycat\", itemid = \"myitem\","
84
            + "icon16 = \"org/netbeans/modules/palette/resources/unknown16.gif\", tooltip = \"tooltip\", name = \"name\")";
85
86
    public void testNoCompliantClassAnnotated() throws IOException {
87
        clearWorkDir();
88
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
89
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.A",
90
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
91
                + VALID_CLASS_ANNOTATION
92
                + "public class A {\n"
93
                + "    A() {}"
94
                + "}\n");
95
        ByteArrayOutputStream os = new ByteArrayOutputStream();
96
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
97
        assertFalse("Compilation has to fail:\n" + os, r);
98
    }
99
100
    public void testActiveEditorDropAnnotated() throws IOException {
101
        clearWorkDir();
102
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
103
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
104
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
105
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
106
                + VALID_CLASS_ANNOTATION
107
                + "public class B implements ActiveEditorDrop {\n"
108
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
109
                + "}\n");
110
        ByteArrayOutputStream os = new ByteArrayOutputStream();
111
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
112
        assertTrue("Compilation has to be successfull:\n" + os, r);
113
    }
114
115
    public void testActiveEditorDropAnnotatedWithMissingIcon16() throws IOException {
116
        clearWorkDir();
117
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
118
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
119
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
120
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
121
                + INVALID_CLASS_ANNOTATION_1
122
                + "public class B implements ActiveEditorDrop {\n"
123
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
124
                + "}\n");
125
        ByteArrayOutputStream os = new ByteArrayOutputStream();
126
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
127
        assertFalse("Compilation has to fail:\n" + os, r);
128
    }
129
130
    public void testActiveEditorDropAnnotatedWithMissingIcon32() throws IOException {
131
        clearWorkDir();
132
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
133
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "test.B",
134
                "import org.netbeans.spi.palette.PaletteItemRegistration;\n"
135
                + "import org.openide.text.ActiveEditorDrop;\n;import javax.swing.text.JTextComponent;"
136
                + INVALID_CLASS_ANNOTATION_2
137
                + "public class B implements ActiveEditorDrop {\n"
138
                + "     public boolean handleTransfer(JTextComponent targetComponent) {return true; }"
139
                + "}\n");
140
        ByteArrayOutputStream os = new ByteArrayOutputStream();
141
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
142
        assertFalse("Compilation has to fail:\n" + os, r);
143
    }
144
145
    public void testInvalidAnnotatedPackage() throws IOException {
146
        //missing body
147
        clearWorkDir();
148
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
149
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testb.package-info",
150
                VALID_CLASS_ANNOTATION
151
                + "\npackage testa\n;"
152
                + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
153
        ByteArrayOutputStream os = new ByteArrayOutputStream();
154
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
155
        assertFalse("Compilation has to fail:\n" + os, r);
156
    }
157
158
    public void testAnnotatedPackage() throws IOException {
159
        //missing body
160
        clearWorkDir();
161
        assertTrue("Headless run", GraphicsEnvironment.isHeadless());
162
        AnnotationProcessorTestUtils.makeSource(getWorkDir(), "testa.package-info",
163
                VALID_PACKAGE_ANNOTATION
164
                + "\npackage testa\n;"
165
                + "import org.netbeans.spi.palette.PaletteItemRegistration;\n");
166
        ByteArrayOutputStream os = new ByteArrayOutputStream();
167
        boolean r = AnnotationProcessorTestUtils.runJavac(getWorkDir(), null, getWorkDir(), null, os);
168
        assertTrue("Compilation has to be successfull:\n" + os, r);
169
    }
170
}

Return to bug 227345
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo